17ec3b29aSmrg/* test texturing + stippling */ 27ec3b29aSmrg 37ec3b29aSmrg#include <stdio.h> 47ec3b29aSmrg#include <string.h> 57ec3b29aSmrg#include <stdlib.h> 67ec3b29aSmrg#include <GL/glew.h> 77ec3b29aSmrg#include "glut_wrap.h" 87ec3b29aSmrg 97ec3b29aSmrg 107ec3b29aSmrgstatic GLubyte fly[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 117ec3b29aSmrg0x03, 0x80, 0x01, 0xC0, 0x06, 0xC0, 0x03, 0x60, 0x04, 0x60, 0x06, 0x20, 127ec3b29aSmrg0x04, 0x30, 0x0C, 0x20, 0x04, 0x18, 0x18, 0x20, 0x04, 0x0C, 0x30, 0x20, 137ec3b29aSmrg0x04, 0x06, 0x60, 0x20, 0x44, 0x03, 0xC0, 0x22, 0x44, 0x01, 0x80, 0x22, 147ec3b29aSmrg0x44, 0x01, 0x80, 0x22, 0x44, 0x01, 0x80, 0x22, 0x44, 0x01, 0x80, 0x22, 157ec3b29aSmrg0x44, 0x01, 0x80, 0x22, 0x44, 0x01, 0x80, 0x22, 0x66, 0x01, 0x80, 0x66, 167ec3b29aSmrg0x33, 0x01, 0x80, 0xCC, 0x19, 0x81, 0x81, 0x98, 0x0C, 0xC1, 0x83, 0x30, 177ec3b29aSmrg0x07, 0xe1, 0x87, 0xe0, 0x03, 0x3f, 0xfc, 0xc0, 0x03, 0x31, 0x8c, 0xc0, 187ec3b29aSmrg0x03, 0x33, 0xcc, 0xc0, 0x06, 0x64, 0x26, 0x60, 0x0c, 0xcc, 0x33, 0x30, 197ec3b29aSmrg0x18, 0xcc, 0x33, 0x18, 0x10, 0xc4, 0x23, 0x08, 0x10, 0x63, 0xC6, 0x08, 207ec3b29aSmrg0x10, 0x30, 0x0c, 0x08, 0x10, 0x18, 0x18, 0x08, 0x10, 0x00, 0x00, 0x08}; 217ec3b29aSmrg 227ec3b29aSmrg 237ec3b29aSmrgstatic void 247ec3b29aSmrgInit(void) 257ec3b29aSmrg{ 267ec3b29aSmrg fprintf(stderr, "GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER)); 277ec3b29aSmrg fprintf(stderr, "GL_VERSION = %s\n", (char *) glGetString(GL_VERSION)); 287ec3b29aSmrg fprintf(stderr, "GL_VENDOR = %s\n", (char *) glGetString(GL_VENDOR)); 297ec3b29aSmrg fflush(stderr); 307ec3b29aSmrg 317ec3b29aSmrg glClearColor(0.0, 0.0, 1.0, 1.0); 327ec3b29aSmrg 337ec3b29aSmrg#define SIZE 32 347ec3b29aSmrg { 357ec3b29aSmrg GLubyte tex2d[SIZE][SIZE][3]; 367ec3b29aSmrg GLint s, t; 377ec3b29aSmrg 387ec3b29aSmrg for (s = 0; s < SIZE; s++) { 397ec3b29aSmrg for (t = 0; t < SIZE; t++) { 407ec3b29aSmrg tex2d[t][s][0] = s*255/(SIZE-1); 417ec3b29aSmrg tex2d[t][s][1] = t*255/(SIZE-1); 427ec3b29aSmrg tex2d[t][s][2] = 0; 437ec3b29aSmrg } 447ec3b29aSmrg } 457ec3b29aSmrg 467ec3b29aSmrg glEnable(GL_TEXTURE_2D); 477ec3b29aSmrg glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); 487ec3b29aSmrg glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_R, GL_REPEAT); 497ec3b29aSmrg glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 507ec3b29aSmrg glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 517ec3b29aSmrg glPixelStorei(GL_UNPACK_ALIGNMENT, 1); 527ec3b29aSmrg glTexImage2D(GL_TEXTURE_2D, 0, 3, SIZE, SIZE, 0, 537ec3b29aSmrg GL_RGB, GL_UNSIGNED_BYTE, tex2d); 547ec3b29aSmrg } 557ec3b29aSmrg 567ec3b29aSmrg glEnable (GL_POLYGON_STIPPLE); 577ec3b29aSmrg glPolygonStipple (fly); 587ec3b29aSmrg} 597ec3b29aSmrg 607ec3b29aSmrg 617ec3b29aSmrgstatic void 627ec3b29aSmrgReshape(int width, int height) 637ec3b29aSmrg{ 647ec3b29aSmrg glViewport(0, 0, (GLint)width, (GLint)height); 657ec3b29aSmrg 667ec3b29aSmrg glMatrixMode(GL_PROJECTION); 677ec3b29aSmrg glLoadIdentity(); 687ec3b29aSmrg glMatrixMode(GL_MODELVIEW); 697ec3b29aSmrg} 707ec3b29aSmrg 717ec3b29aSmrg 727ec3b29aSmrgstatic void 737ec3b29aSmrgKey(unsigned char key, int x, int y) 747ec3b29aSmrg{ 757ec3b29aSmrg if (key == 27) 767ec3b29aSmrg exit(1); 777ec3b29aSmrg 787ec3b29aSmrg glutPostRedisplay(); 797ec3b29aSmrg} 807ec3b29aSmrg 817ec3b29aSmrg 827ec3b29aSmrgstatic void 837ec3b29aSmrgDraw(void) 847ec3b29aSmrg{ 857ec3b29aSmrg glClear(GL_COLOR_BUFFER_BIT); 867ec3b29aSmrg 877ec3b29aSmrg glBegin(GL_TRIANGLES); 887ec3b29aSmrg glTexCoord2f(1,-1); 897ec3b29aSmrg glVertex3f(0.9, -0.9, -0.0); 907ec3b29aSmrg glTexCoord2f(1,1); 917ec3b29aSmrg glVertex3f(0.9, 0.9, -0.0); 927ec3b29aSmrg glTexCoord2f(-1,0); 937ec3b29aSmrg glVertex3f(-0.9, 0.0, -0.0); 947ec3b29aSmrg glEnd(); 957ec3b29aSmrg 967ec3b29aSmrg glutSwapBuffers(); 977ec3b29aSmrg} 987ec3b29aSmrg 997ec3b29aSmrg 1007ec3b29aSmrgint 1017ec3b29aSmrgmain(int argc, char **argv) 1027ec3b29aSmrg{ 1037ec3b29aSmrg glutInit(&argc, argv); 1047ec3b29aSmrg glutInitWindowPosition(0, 0); 1057ec3b29aSmrg glutInitWindowSize(250, 250); 1067ec3b29aSmrg glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE); 1077ec3b29aSmrg 1087ec3b29aSmrg if (glutCreateWindow(*argv) == GL_FALSE) { 1097ec3b29aSmrg exit(1); 1107ec3b29aSmrg } 1117ec3b29aSmrg 1127ec3b29aSmrg Init(); 1137ec3b29aSmrg 1147ec3b29aSmrg glutReshapeFunc(Reshape); 1157ec3b29aSmrg glutKeyboardFunc(Key); 1167ec3b29aSmrg glutDisplayFunc(Draw); 1177ec3b29aSmrg glutMainLoop(); 1187ec3b29aSmrg 1197ec3b29aSmrg return 0; 1207ec3b29aSmrg} 121