Jump to content
  • Advertisement
Sign in to follow this  

OpenGL How many ways to load/dispaly a texture? (EGL 1.1)

This topic is 3297 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am creating an opengl es 1.1 application that has issues with textures becoming distorted randomly. The code below is a simplified version of the larger application that has the issue. The issue does not exist under an emulator so I believe the code is correct but was wondering if there were other ways to load and display textures other than using glTex(Sub)Image and then glDrawArrays/glDrawElements? I am not sure the chip provider is going to provide a solution so I am trying to find alternatives. The actual problem occurs because of a call to glDrawArrays, the first time the texture is displayed it will look fine and then the second time it looks like it has random data on it. The platform I am using does not have support for glDrawTexsOES.
typedef struct {
    unsigned char Red;
    unsigned char Green;
    unsigned char Blue;
    unsigned char Alpha;
}RGBAQuad, *pRGBAQuad;

bool Begin()
    GLfloat width = nWidth;
    GLfloat height = nHeight;

    glMatrixMode (GL_PROJECTION);
    glLoadIdentity ();
    glOrthof (0, width, height, 0, 0, 1);
    glMatrixMode (GL_MODELVIEW);

    glClearColor(1.0f, 0.0f, 0.0f, 0.0f);


    if (textures.size() == 0 || textpos == textures.end())
        thisFrameTextureID = 0;
        glGenTextures(1, &thisFrameTextureID);
        glBindTexture(GL_TEXTURE_2D, thisFrameTextureID);   
        RGBAQuad* rgbadata = new RGBAQuad[TEST_TXTR_SIZE * TEST_TXTR_SIZE];
        unsigned char val = rand() % 255;

        unsigned long idx = 0;
        for (int w = 0; w < TEST_TXTR_SIZE; w++)
            for (int h = 0; h < TEST_TXTR_SIZE; h++)
                idx = h + (w * TEST_TXTR_SIZE);

                rgbadata[idx].Red = val;
                rgbadata[idx].Green = val;
                rgbadata[idx].Blue = val;
                rgbadata[idx].Alpha = val;

        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, TEST_TXTR_SIZE, TEST_TXTR_SIZE, 0, GL_RGBA, GL_UNSIGNED_BYTE, (unsigned char*)rgbadata);
        glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);        //was i


        delete rgbadata;
        textpos = textures.begin();
        if (textures.size() > 5)
            int moveback = 5;
            textpos = textures.end();
            while (textpos != textures.begin() && moveback )               
                textpos--, moveback--;

    return 1;

bool End()
    if (*textpos)
        GLuint txtr = *textpos;

        GLfloat pfVertices[] = {(float)0, (float)0, //0.0f,
                                (float)0, (float)nHeight, //0.0f,
                                (float)nWidth, (float)0, //0.0f,
                                (float)nWidth, (float)nHeight//, //0.0f

        GLfloat pfTexCoords[] = { 0.0f, 0.0f,
                                0.0f, 1.0f,
                                1.0f, 0.0f,
                                1.0f, 1.0f };

        //make sure Texture is enabled


        glBindTexture(GL_TEXTURE_2D, txtr);

        glVertexPointer(2, GL_FLOAT, 0, pfVertices);
        glTexCoordPointer(2, GL_FLOAT, 0, pfTexCoords);

        glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);


        printf("displayed %d texture\n", txtr);

    if (EGL_TRUE != eglSwapBuffers( eglDisplay, eglSurface ))
        return false;

    return true;

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!