2 * Test cylindrical texcoord wrapping
12 static int WinWidth
= 600, WinHeight
= 400;
13 static GLfloat Xrot
= 0, Yrot
= 0;
14 static GLboolean CylWrap
= GL_TRUE
;
15 static GLboolean Lines
= GL_FALSE
;
20 PrintString(const char *s
)
23 glutBitmapCharacter(GLUT_BITMAP_8_BY_13
, (int) *s
);
30 DrawSample(GLboolean wrap
)
34 glEnable(GL_TEXTURE_2D
);
39 for (t
= 0; t
<= 1.0; t
+= 0.125) {
40 float y
= -1.0 + 2.0 * t
;
41 glBegin(GL_LINE_STRIP
);
42 for (p
= 0.0; p
<= 1.001; p
+= 0.05) {
43 float x
= -2.0 + p
* 4.0;
47 glTexCoord2f(s
, t
); glVertex2f(x
, y
);
54 glBegin(GL_QUAD_STRIP
);
55 for (p
= 0.0; p
<= 1.001; p
+= 0.1) {
56 float x
= -2.0 + p
* 4.0;
60 glTexCoord2f(s
, 0); glVertex2f(x
, -1);
61 glTexCoord2f(s
, 1); glVertex2f(x
, +1);
66 glDisable(GL_TEXTURE_2D
);
71 for (p
= 0.0; p
<= 1.001; p
+= 0.1) {
72 float x
= -2.0 + p
* 4.0;
80 for (p
= 0.0; p
<= 1.001; p
+= 0.1) {
82 float x
= -2.0 + p
* 4.0;
88 sprintf(str
, "%3.1f", s
);
89 glRasterPos2f(x
, -1.2);
90 glBitmap(0, 0, 0, 0, -11, 0, NULL
);
93 glBitmap(0, 0, 0, 0, -55, 0, NULL
);
103 glClear(GL_COLOR_BUFFER_BIT
);
106 glRotatef(Xrot
, 1, 0, 0);
107 glRotatef(Yrot
, 0, 1, 0);
110 glTranslatef(0, +1.2, 0);
111 DrawSample(GL_FALSE
);
114 /* set Mesa back-door state for testing cylindrical wrap mode */
116 glTexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_PRIORITY
, 0.125);
119 glTranslatef(0, -1.2, 0);
123 glTexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_PRIORITY
, 1.0);
132 Reshape(int width
, int height
)
136 glViewport(0, 0, width
, height
);
137 glMatrixMode(GL_PROJECTION
);
139 glFrustum(-1.0, 1.0, -1.0, 1.0, 3.0, 25.0);
140 glMatrixMode(GL_MODELVIEW
);
142 glTranslatef(0.0, 0.0, -10.0);
147 Key(unsigned char key
, int x
, int y
)
156 printf("Cylindrical wrap on.\n");
158 printf("Cylindrical wrap off.\n");
165 glutDestroyWindow(Win
);
174 SpecialKey(int key
, int x
, int y
)
176 const GLfloat step
= 3.0;
198 MakeSineWaveTexture(void)
200 GLubyte tex
[128][512][4];
203 for (j
= 0; j
< 128; j
++) {
204 for (i
= 0; i
< 512; i
++) {
205 float x
= i
/ 511.0 * 2.0 * M_PI
+ M_PI
* 0.5;
206 float y0
= sin(x
) * 0.5 + 0.5;
208 float y1
= sin(x
+ M_PI
) * 0.5 + 0.5;
223 glTexImage2D(GL_TEXTURE_2D
, 0, GL_RGBA
, 512, 128, 0,
224 GL_RGBA
, GL_UNSIGNED_BYTE
, tex
);
225 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_LINEAR
);
226 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_LINEAR
);
227 glTexEnvi(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, GL_REPLACE
);
234 glBindTexture(GL_TEXTURE_2D
, 5);
235 MakeSineWaveTexture();
237 glClearColor(0.5, 0.5, 0.5, 0.0);
240 printf("Press 'c' to toggle cylindrical wrap mode.\n");
241 printf("Press 'l' to toggle line / quad drawing.\n");
246 main(int argc
, char *argv
[])
248 glutInit(&argc
, argv
);
249 glutInitWindowSize(WinWidth
, WinHeight
);
250 glutInitDisplayMode(GLUT_RGB
| GLUT_DOUBLE
);
251 Win
= glutCreateWindow(argv
[0]);
252 glutReshapeFunc(Reshape
);
253 glutSpecialFunc(SpecialKey
);
254 glutKeyboardFunc(Key
);
255 glutDisplayFunc(Draw
);