1/* test texturing + stippling */ 2 3#include <stdio.h> 4#include <string.h> 5#include <stdlib.h> 6#include <GL/glew.h> 7#include "glut_wrap.h" 8 9 10static GLubyte fly[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 110x03, 0x80, 0x01, 0xC0, 0x06, 0xC0, 0x03, 0x60, 0x04, 0x60, 0x06, 0x20, 120x04, 0x30, 0x0C, 0x20, 0x04, 0x18, 0x18, 0x20, 0x04, 0x0C, 0x30, 0x20, 130x04, 0x06, 0x60, 0x20, 0x44, 0x03, 0xC0, 0x22, 0x44, 0x01, 0x80, 0x22, 140x44, 0x01, 0x80, 0x22, 0x44, 0x01, 0x80, 0x22, 0x44, 0x01, 0x80, 0x22, 150x44, 0x01, 0x80, 0x22, 0x44, 0x01, 0x80, 0x22, 0x66, 0x01, 0x80, 0x66, 160x33, 0x01, 0x80, 0xCC, 0x19, 0x81, 0x81, 0x98, 0x0C, 0xC1, 0x83, 0x30, 170x07, 0xe1, 0x87, 0xe0, 0x03, 0x3f, 0xfc, 0xc0, 0x03, 0x31, 0x8c, 0xc0, 180x03, 0x33, 0xcc, 0xc0, 0x06, 0x64, 0x26, 0x60, 0x0c, 0xcc, 0x33, 0x30, 190x18, 0xcc, 0x33, 0x18, 0x10, 0xc4, 0x23, 0x08, 0x10, 0x63, 0xC6, 0x08, 200x10, 0x30, 0x0c, 0x08, 0x10, 0x18, 0x18, 0x08, 0x10, 0x00, 0x00, 0x08}; 21 22 23static void 24Init(void) 25{ 26 fprintf(stderr, "GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER)); 27 fprintf(stderr, "GL_VERSION = %s\n", (char *) glGetString(GL_VERSION)); 28 fprintf(stderr, "GL_VENDOR = %s\n", (char *) glGetString(GL_VENDOR)); 29 fflush(stderr); 30 31 glClearColor(0.0, 0.0, 1.0, 1.0); 32 33#define SIZE 32 34 { 35 GLubyte tex2d[SIZE][SIZE][3]; 36 GLint s, t; 37 38 for (s = 0; s < SIZE; s++) { 39 for (t = 0; t < SIZE; t++) { 40 tex2d[t][s][0] = s*255/(SIZE-1); 41 tex2d[t][s][1] = t*255/(SIZE-1); 42 tex2d[t][s][2] = 0; 43 } 44 } 45 46 glEnable(GL_TEXTURE_2D); 47 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); 48 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_R, GL_REPEAT); 49 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 50 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 51 glPixelStorei(GL_UNPACK_ALIGNMENT, 1); 52 glTexImage2D(GL_TEXTURE_2D, 0, 3, SIZE, SIZE, 0, 53 GL_RGB, GL_UNSIGNED_BYTE, tex2d); 54 } 55 56 glEnable (GL_POLYGON_STIPPLE); 57 glPolygonStipple (fly); 58} 59 60 61static void 62Reshape(int width, int height) 63{ 64 glViewport(0, 0, (GLint)width, (GLint)height); 65 66 glMatrixMode(GL_PROJECTION); 67 glLoadIdentity(); 68 glMatrixMode(GL_MODELVIEW); 69} 70 71 72static void 73Key(unsigned char key, int x, int y) 74{ 75 if (key == 27) 76 exit(1); 77 78 glutPostRedisplay(); 79} 80 81 82static void 83Draw(void) 84{ 85 glClear(GL_COLOR_BUFFER_BIT); 86 87 glBegin(GL_TRIANGLES); 88 glTexCoord2f(1,-1); 89 glVertex3f(0.9, -0.9, -0.0); 90 glTexCoord2f(1,1); 91 glVertex3f(0.9, 0.9, -0.0); 92 glTexCoord2f(-1,0); 93 glVertex3f(-0.9, 0.0, -0.0); 94 glEnd(); 95 96 glutSwapBuffers(); 97} 98 99 100int 101main(int argc, char **argv) 102{ 103 glutInit(&argc, argv); 104 glutInitWindowPosition(0, 0); 105 glutInitWindowSize(250, 250); 106 glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE); 107 108 if (glutCreateWindow(*argv) == GL_FALSE) { 109 exit(1); 110 } 111 112 Init(); 113 114 glutReshapeFunc(Reshape); 115 glutKeyboardFunc(Key); 116 glutDisplayFunc(Draw); 117 glutMainLoop(); 118 119 return 0; 120} 121