diff options
author | Jack Palevich <jackpal@google.com> | 2009-12-24 11:09:56 +0800 |
---|---|---|
committer | Jack Palevich <jackpal@google.com> | 2009-12-24 11:09:56 +0800 |
commit | 1c875584c5d90a3935f4c53376dfb2ba098795b5 (patch) | |
tree | 80275004c9717a1afe5d671be0a7569b2527c8d2 | |
parent | ecc1f6eca2a89b5a1d0e0e067e3f270424121546 (diff) | |
download | frameworks_base-1c875584c5d90a3935f4c53376dfb2ba098795b5.zip frameworks_base-1c875584c5d90a3935f4c53376dfb2ba098795b5.tar.gz frameworks_base-1c875584c5d90a3935f4c53376dfb2ba098795b5.tar.bz2 |
Print OpenGL version and extension information.
Something happened to the line endings, adding
a blank line after most lines of text. I
repaired the damage, but in the process some
blank lines have been added / removed.
-rw-r--r-- | opengl/tests/gl_basic/gl_basic.cpp | 296 |
1 files changed, 152 insertions, 144 deletions
diff --git a/opengl/tests/gl_basic/gl_basic.cpp b/opengl/tests/gl_basic/gl_basic.cpp index 7dc2378..feb964a 100644 --- a/opengl/tests/gl_basic/gl_basic.cpp +++ b/opengl/tests/gl_basic/gl_basic.cpp @@ -1,32 +1,39 @@ // Simple OpenGL ES 1.x application showing how to initialize and draw something. -#include <EGL/egl.h>
+#include <EGL/egl.h> + #include <GLES/gl.h> #include <GLES/glext.h> #include <ui/FramebufferNativeWindow.h> #include <ui/EGLUtils.h> -#include <stdio.h>
+#include <stdio.h> + #include <stdlib.h> #include <math.h> using namespace android; -
-EGLDisplay eglDisplay;
-EGLSurface eglSurface;
-EGLContext eglContext;
-GLuint texture;
-
+ +EGLDisplay eglDisplay; +EGLSurface eglSurface; +EGLContext eglContext; +GLuint texture; + #define FIXED_ONE 0x10000 -#define ITERATIONS 50
-
-int init_gl_surface(void);
-void free_gl_surface(void);
-void init_scene(void);
-void render();
+#define ITERATIONS 50 + +int init_gl_surface(void); +void free_gl_surface(void); +void init_scene(void); +void render(); void create_texture(void); -int readTimer(void);
+int readTimer(void); + +static void printGLString(const char *name, GLenum s) { + const char *v = (const char *) glGetString(s); + fprintf(stderr, "GL %s = %s\n", name, v); +} static void gluLookAt(float eyeX, float eyeY, float eyeZ, float centerX, float centerY, float centerZ, float upX, float upY, @@ -87,7 +94,6 @@ static void gluLookAt(float eyeX, float eyeY, float eyeZ, glTranslatef(-eyeX, -eyeY, -eyeZ); } - void printEGLConfiguration(EGLDisplay dpy, EGLConfig config) { #define X(VAL) {VAL, #VAL} @@ -183,125 +189,129 @@ int printEGLConfigurations(EGLDisplay dpy) { free(configs); return true; } -
-int main(int argc, char **argv)
-{
- int q; - int start, end;
+int main(int argc, char **argv) +{ + int q; + int start, end; printf("Initializing EGL...\n"); -
- if(!init_gl_surface())
- {
- printf("GL initialisation failed - exiting\n");
- return 0;
- }
-
- init_scene();
-
- create_texture();
-
+ if(!init_gl_surface()) + { + printf("GL initialisation failed - exiting\n"); + return 0; + } + init_scene(); + create_texture(); printf("Running...\n"); - while(true) { render(); - }
-
- free_gl_surface();
-
- return 0;
-}
-
-int init_gl_surface(void)
-{
- EGLint numConfigs = 1;
- EGLConfig myConfig = {0};
- EGLint attrib[] =
- {
- EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
- EGL_NONE
- };
-
- if ( (eglDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY)) == EGL_NO_DISPLAY )
- {
- printf("eglGetDisplay failed\n");
- return 0;
} -
- if ( eglInitialize(eglDisplay, NULL, NULL) != EGL_TRUE )
- {
- printf("eglInitialize failed\n");
- return 0;
+ free_gl_surface(); + return 0; +} + +int init_gl_surface(void) +{ + EGLint numConfigs = 1; + EGLConfig myConfig = {0}; + EGLint attrib[] = + { + EGL_SURFACE_TYPE, EGL_WINDOW_BIT, + EGL_NONE + }; + + if ( (eglDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY)) == EGL_NO_DISPLAY ) + { + printf("eglGetDisplay failed\n"); + return 0; + } + + if ( eglInitialize(eglDisplay, NULL, NULL) != EGL_TRUE ) + { + printf("eglInitialize failed\n"); + return 0; } if (! printEGLConfigurations(eglDisplay)) { printf("printEGLConfigurations failed.\n"); return 0; - }
- EGLNativeWindowType window = android_createDisplaySurface();
- EGLUtils::selectConfigForNativeWindow(eglDisplay, attrib, window, &myConfig);
-
+ } + + EGLNativeWindowType window = android_createDisplaySurface(); + EGLUtils::selectConfigForNativeWindow(eglDisplay, attrib, window, &myConfig); + if ( (eglSurface = eglCreateWindowSurface(eglDisplay, myConfig, - window, 0)) == EGL_NO_SURFACE )
- {
- printf("eglCreateWindowSurface failed\n");
- return 0;
- }
-
- if ( (eglContext = eglCreateContext(eglDisplay, myConfig, 0, 0)) == EGL_NO_CONTEXT )
- {
- printf("eglCreateContext failed\n");
- return 0;
- }
-
- if ( eglMakeCurrent(eglDisplay, eglSurface, eglSurface, eglContext) != EGL_TRUE )
- {
- printf("eglMakeCurrent failed\n");
- return 0;
- }
-
- return 1;
-}
-
-void free_gl_surface(void)
-{
- if (eglDisplay != EGL_NO_DISPLAY)
- {
- eglMakeCurrent( EGL_NO_DISPLAY, EGL_NO_SURFACE,
- EGL_NO_SURFACE, EGL_NO_CONTEXT );
- eglDestroyContext( eglDisplay, eglContext );
- eglDestroySurface( eglDisplay, eglSurface );
- eglTerminate( eglDisplay );
- eglDisplay = EGL_NO_DISPLAY;
- }
-}
-
-void init_scene(void)
-{
+ window, 0)) == EGL_NO_SURFACE ) + { + printf("eglCreateWindowSurface failed\n"); + return 0; + } + + if ( (eglContext = eglCreateContext(eglDisplay, myConfig, 0, 0)) == EGL_NO_CONTEXT ) + { + printf("eglCreateContext failed\n"); + return 0; + } + + if ( eglMakeCurrent(eglDisplay, eglSurface, eglSurface, eglContext) != EGL_TRUE ) + { + printf("eglMakeCurrent failed\n"); + return 0; + } + + int w, h; + + eglQuerySurface(eglDisplay, eglSurface, EGL_WIDTH, &w); + checkEglError("eglQuerySurface"); + eglQuerySurface(eglDisplay, eglSurface, EGL_HEIGHT, &h); + checkEglError("eglQuerySurface"); + GLint dim = w < h ? w : h; + + fprintf(stderr, "Window dimensions: %d x %d\n", w, h); + + printGLString("Version", GL_VERSION); + printGLString("Vendor", GL_VENDOR); + printGLString("Renderer", GL_RENDERER); + printGLString("Extensions", GL_EXTENSIONS); + + return 1; +} + +void free_gl_surface(void) +{ + if (eglDisplay != EGL_NO_DISPLAY) + { + eglMakeCurrent( EGL_NO_DISPLAY, EGL_NO_SURFACE, + EGL_NO_SURFACE, EGL_NO_CONTEXT ); + eglDestroyContext( eglDisplay, eglContext ); + eglDestroySurface( eglDisplay, eglSurface ); + eglTerminate( eglDisplay ); + eglDisplay = EGL_NO_DISPLAY; + } +} + +void init_scene(void) +{ glDisable(GL_DITHER); glEnable(GL_CULL_FACE); - float ratio = 320.0f / 480.0f; glViewport(0, 0, 320, 480); - glMatrixMode(GL_PROJECTION); glLoadIdentity(); glFrustumf(-ratio, ratio, -1, 1, 1, 10); - - glMatrixMode(GL_MODELVIEW);
+ glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt( 0, 0, 3, // eye 0, 0, 0, // center 0, 1, 0); // up -
- glEnable(GL_TEXTURE_2D);
- glEnableClientState(GL_VERTEX_ARRAY);
+ glEnable(GL_TEXTURE_2D); + glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY); -}
-
-void create_texture(void)
-{
+} + +void create_texture(void) +{ const unsigned int on = 0xff0000ff; const unsigned int off = 0xffffffff; const unsigned int pixels[] = @@ -314,44 +324,42 @@ void create_texture(void) off, on, off, on, off, on, off, on, on, off, on, off, on, off, on, off, off, on, off, on, off, on, off, on, - };
- glGenTextures(1, &texture);
- glBindTexture(GL_TEXTURE_2D, texture);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
- glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
- glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
- glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
-}
-
-void render()
-{
+ }; + + glGenTextures(1, &texture); + glBindTexture(GL_TEXTURE_2D, texture); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels); + glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); +} + +void render() +{ int i, j; - int quads = 1;
-
- const GLfloat vertices[] = {
- -1, -1, 0,
- 1, -1, 0,
- 1, 1, 0,
- -1, 1, 0
- };
-
- const GLfixed texCoords[] = {
- 0, 0,
- FIXED_ONE, 0,
- FIXED_ONE, FIXED_ONE,
- 0, FIXED_ONE
- };
-
+ int quads = 1; + + const GLfloat vertices[] = { + -1, -1, 0, + 1, -1, 0, + 1, 1, 0, + -1, 1, 0 + }; + + const GLfixed texCoords[] = { + 0, 0, + FIXED_ONE, 0, + FIXED_ONE, FIXED_ONE, + 0, FIXED_ONE + }; + const GLushort indices[] = { 0, 1, 2, 0, 2, 3 }; -
- glVertexPointer(3, GL_FLOAT, 0, vertices);
- glTexCoordPointer(2, GL_FIXED, 0, texCoords); + glVertexPointer(3, GL_FLOAT, 0, vertices); + glTexCoordPointer(2, GL_FIXED, 0, texCoords); glClearColor(1.0, 1.0, 1.0, 1.0); - int nelem = sizeof(indices)/sizeof(indices[0]); glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT); glDrawElements(GL_TRIANGLES, nelem, GL_UNSIGNED_SHORT, indices); - eglSwapBuffers(eglDisplay, eglSurface);
-}
- + eglSwapBuffers(eglDisplay, eglSurface); +} |