Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ecafff17 authored by Android (Google) Code Review's avatar Android (Google) Code Review
Browse files

Merge change I1c875584

* changes:
  Print OpenGL version and extension information.
parents 872db948 909486a7
Loading
Loading
Loading
Loading
+152 −144
Original line number Original line Diff line number Diff line
// Simple OpenGL ES 1.x application showing how to initialize and draw something.
// 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/gl.h>
#include <GLES/glext.h>
#include <GLES/glext.h>


@@ -8,6 +9,7 @@
#include <ui/EGLUtils.h>
#include <ui/EGLUtils.h>


#include <stdio.h>
#include <stdio.h>

#include <stdlib.h>
#include <stdlib.h>
#include <math.h>
#include <math.h>


@@ -28,6 +30,11 @@ void render();
void create_texture(void);
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,
static void gluLookAt(float eyeX, float eyeY, float eyeZ,
        float centerX, float centerY, float centerZ, float upX, float upY,
        float centerX, float centerY, float centerZ, float upX, float upY,
        float upZ)
        float upZ)
@@ -87,7 +94,6 @@ static void gluLookAt(float eyeX, float eyeY, float eyeZ,
    glTranslatef(-eyeX, -eyeY, -eyeZ);
    glTranslatef(-eyeX, -eyeY, -eyeZ);
}
}



void printEGLConfiguration(EGLDisplay dpy, EGLConfig config) {
void printEGLConfiguration(EGLDisplay dpy, EGLConfig config) {


#define X(VAL) {VAL, #VAL}
#define X(VAL) {VAL, #VAL}
@@ -188,27 +194,19 @@ int main(int argc, char **argv)
{
{
    int q;
    int q;
    int start, end;
    int start, end;

    printf("Initializing EGL...\n");
    printf("Initializing EGL...\n");

    if(!init_gl_surface())
    if(!init_gl_surface())
    {
    {
        printf("GL initialisation failed - exiting\n");
        printf("GL initialisation failed - exiting\n");
        return 0;
        return 0;
    }
    }

    init_scene();
    init_scene();

    create_texture();
    create_texture();

    printf("Running...\n");
    printf("Running...\n");

    while(true) {
    while(true) {
        render();
        render();
    }
    }

    free_gl_surface();
    free_gl_surface();

    return 0;
    return 0;
}
}


@@ -238,6 +236,7 @@ int init_gl_surface(void)
        printf("printEGLConfigurations failed.\n");
        printf("printEGLConfigurations failed.\n");
        return 0;
        return 0;
    }
    }

    EGLNativeWindowType window = android_createDisplaySurface();
    EGLNativeWindowType window = android_createDisplaySurface();
    EGLUtils::selectConfigForNativeWindow(eglDisplay, attrib, window, &myConfig);
    EGLUtils::selectConfigForNativeWindow(eglDisplay, attrib, window, &myConfig);


@@ -260,6 +259,21 @@ int init_gl_surface(void)
        return 0;
        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;
    return 1;
}
}


@@ -280,21 +294,17 @@ void init_scene(void)
{
{
    glDisable(GL_DITHER);
    glDisable(GL_DITHER);
    glEnable(GL_CULL_FACE);
    glEnable(GL_CULL_FACE);

    float ratio = 320.0f / 480.0f;
    float ratio = 320.0f / 480.0f;
    glViewport(0, 0, 320, 480);
    glViewport(0, 0, 320, 480);

    glMatrixMode(GL_PROJECTION);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glLoadIdentity();
    glFrustumf(-ratio, ratio, -1, 1, 1, 10);
    glFrustumf(-ratio, ratio, -1, 1, 1, 10);

    glMatrixMode(GL_MODELVIEW);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    glLoadIdentity();
    gluLookAt(
    gluLookAt(
            0, 0, 3,  // eye
            0, 0, 3,  // eye
            0, 0, 0,  // center
            0, 0, 0,  // center
            0, 1, 0); // up
            0, 1, 0); // up

    glEnable(GL_TEXTURE_2D);
    glEnable(GL_TEXTURE_2D);
    glEnableClientState(GL_VERTEX_ARRAY);
    glEnableClientState(GL_VERTEX_ARRAY);
    glEnableClientState(GL_TEXTURE_COORD_ARRAY);
    glEnableClientState(GL_TEXTURE_COORD_ARRAY);
@@ -315,6 +325,7 @@ void create_texture(void)
            on, off, on, off, on, off, on, off,
            on, off, on, off, on, off, on, off,
            off, on, off, on, off, on, off, on,
            off, on, off, on, off, on, off, on,
    };
    };

    glGenTextures(1, &texture);
    glGenTextures(1, &texture);
    glBindTexture(GL_TEXTURE_2D, texture);
    glBindTexture(GL_TEXTURE_2D, texture);
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
@@ -346,12 +357,9 @@ void render()


    glVertexPointer(3, GL_FLOAT, 0, vertices);
    glVertexPointer(3, GL_FLOAT, 0, vertices);
    glTexCoordPointer(2, GL_FIXED, 0, texCoords);
    glTexCoordPointer(2, GL_FIXED, 0, texCoords);

    glClearColor(1.0, 1.0, 1.0, 1.0);
    glClearColor(1.0, 1.0, 1.0, 1.0);

    int nelem = sizeof(indices)/sizeof(indices[0]);
    int nelem = sizeof(indices)/sizeof(indices[0]);
    glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
    glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
    glDrawElements(GL_TRIANGLES, nelem, GL_UNSIGNED_SHORT, indices);
    glDrawElements(GL_TRIANGLES, nelem, GL_UNSIGNED_SHORT, indices);
    eglSwapBuffers(eglDisplay, eglSurface);
    eglSwapBuffers(eglDisplay, eglSurface);
}
}