bfdf97fbb9cbc89352d863cf981d652629c80480
2 * Test program for glpng
3 * by Ben Wyatt ben@wyatt100.freeserve.co.uk
4 * Featuring a shameless plug for my stunt course program
5 * Available from the same site as glpng
6 * http://www.wyatt100.freeserve.co.uk/download.htm
15 /***** GLUT callback functions *****/
17 void KeyPress(unsigned char key
, int x
, int y
) {
19 case 27: /*ESC*/ glutDestroyWindow(glutGetWindow()); exit(0); break;
24 angle
= (angle
+1)%360;
29 const float w
= 2, h
= 2;
31 glClear(GL_COLOR_BUFFER_BIT
);
34 glTranslatef(0, 0, -10);
35 glRotatef(angle
, 0, 1, 0);
39 glTexCoord2f(1, 1); glVertex3f( w
, -h
, 0);
40 glTexCoord2f(1, 0); glVertex3f( w
, h
, 0);
41 glTexCoord2f(0, 0); glVertex3f(-w
, h
, 0);
42 glTexCoord2f(0, 1); glVertex3f(-w
, -h
, 0);
45 glTexCoord2f(1, 1); glVertex3f(-w
, -h
, 0);
46 glTexCoord2f(1, 0); glVertex3f(-w
, h
, 0);
47 glTexCoord2f(0, 0); glVertex3f( w
, h
, 0);
48 glTexCoord2f(0, 1); glVertex3f( w
, -h
, 0);
54 void Reshape(int w
, int h
) {
55 glViewport(0, 0, w
, h
);
57 glMatrixMode(GL_PROJECTION
);
59 gluPerspective(30, (float) w
/h
, 1, 100);
61 glMatrixMode(GL_MODELVIEW
);
65 /***** Main function *****/
71 glutInitDisplayMode(GLUT_DOUBLE
| GLUT_RGB
);
72 glutInitWindowSize(300, 300);
73 glutCreateWindow("glpng test");
75 #if 0 // Using pngLoad and setting texture parameters manually.
76 glGenTextures(1, &texture
);
77 glBindTexture(GL_TEXTURE_2D
, texture
);
79 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
80 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
81 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_S
, GL_CLAMP
);
82 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_T
, GL_CLAMP
);
84 if (!pngLoad("Stunt.png", PNG_NOMIPMAP
, PNG_SOLID
, &info
)) {
85 puts("Can't load file");
88 #else // Using pngLoadAndBind to set texture parameters automatically.
89 texture
= pngBind("Stunt.png", PNG_NOMIPMAP
, PNG_ALPHA
, &info
, GL_CLAMP
, GL_NEAREST
, GL_NEAREST
);
92 puts("Can't load file");
97 printf("Size=%i,%i Depth=%i Alpha=%i\n", info
.Width
, info
.Height
, info
.Depth
, info
.Alpha
);
99 glEnable(GL_TEXTURE_2D
);
100 glBindTexture(GL_TEXTURE_2D
, texture
);
101 glEnable(GL_CULL_FACE
);
104 glutKeyboardFunc(KeyPress
);
105 glutIdleFunc(Update
);
106 glutDisplayFunc(Display
);
107 glutReshapeFunc(Reshape
);