2 * Copyright (C) 2008 Tunsgten Graphics,Inc. All Rights Reserved.
6 * Test GL_OES_draw_texture
11 #define GL_GLEXT_PROTOTYPES
18 #include <GLES/glext.h>
23 static GLfloat view_posx
= 10.0, view_posy
= 20.0;
24 static GLfloat width
= 200, height
= 200;
25 static GLboolean animate
= GL_FALSE
;
32 glClear(GL_COLOR_BUFFER_BIT
);
34 glDrawTexfOES(view_posx
, view_posy
, 0.0, width
, height
);
38 /* new window size or exposure */
40 reshape(int width
, int height
)
42 GLfloat ar
= (GLfloat
) width
/ (GLfloat
) height
;
44 glViewport(0, 0, (GLint
) width
, (GLint
) height
);
46 glMatrixMode(GL_PROJECTION
);
49 #ifdef GL_VERSION_ES_CM_1_0
50 glFrustumf(-ar
, ar
, -1, 1, 5.0, 60.0);
52 glFrustum(-ar
, ar
, -1, 1, 5.0, 60.0);
55 glMatrixMode(GL_MODELVIEW
);
57 glTranslatef(0.0, 0.0, -15.0);
62 dist(GLuint i
, GLuint j
, float x
, float y
)
64 return sqrt((i
-x
) * (i
-x
) + (j
-y
) * (j
-y
));
68 make_smile_texture(void)
71 GLenum Filter
= GL_LINEAR
;
72 GLubyte image
[SZ
][SZ
][4];
76 for (i
= 0; i
< SZ
; i
++) {
77 for (j
= 0; j
< SZ
; j
++) {
78 GLfloat d_mouth
= dist(i
, j
, SZ
/2, SZ
/2);
79 GLfloat d_rt_eye
= dist(i
, j
, SZ
*3/4, SZ
*3/4);
80 GLfloat d_lt_eye
= dist(i
, j
, SZ
*3/4, SZ
*1/4);
81 if (d_rt_eye
< SZ
/ 8 || d_lt_eye
< SZ
/ 8) {
87 else if (i
< SZ
/2 && d_mouth
< SZ
/3) {
102 glActiveTexture(GL_TEXTURE0
); /* unit 0 */
103 glBindTexture(GL_TEXTURE_2D
, 42);
104 glTexImage2D(GL_TEXTURE_2D
, 0, GL_RGBA
, SZ
, SZ
, 0,
105 GL_RGBA
, GL_UNSIGNED_BYTE
, image
);
106 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, Filter
);
107 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, Filter
);
108 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_S
, GL_REPEAT
);
109 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_T
, GL_REPEAT
);
115 glTexParameteriv(GL_TEXTURE_2D
, GL_TEXTURE_CROP_RECT_OES
, cropRect
);
124 const char *ext
= (char *) glGetString(GL_EXTENSIONS
);
126 if (!strstr(ext
, "GL_OES_draw_texture")) {
127 fprintf(stderr
, "Sorry, this program requires GL_OES_draw_texture");
131 glClearColor(0.4, 0.4, 0.4, 0.0);
133 make_smile_texture();
134 glEnable(GL_TEXTURE_2D
);
144 eglutPostRedisplay();
149 key(unsigned char key
)
168 eglutDestroyWindow(win
);
183 case EGLUT_KEY_RIGHT
:
198 main(int argc
, char *argv
[])
200 eglutInitWindowSize(400, 300);
201 eglutInitAPIMask(EGLUT_OPENGL_ES1_BIT
);
202 eglutInit(argc
, argv
);
204 win
= eglutCreateWindow("drawtex");
207 eglutReshapeFunc(reshape
);
208 eglutDisplayFunc(draw
);
209 eglutKeyboardFunc(key
);
210 eglutSpecialFunc(special_key
);