Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7828679
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T10:26:15+00:00 2026-06-02T10:26:15+00:00

I am working on an OpenGL 2D game with sprite graphics. I was recently

  • 0

I am working on an OpenGL 2D game with sprite graphics. I was recently advised that I should use OpenGL ES calls as it is a subset of OpenGL and would allow me to port it more easily to mobile platforms. The majority of the code is just calls to a draw_image function, which is defined so:

void draw_img(float x, float y, float w, float h, GLuint tex,float r=1,float g=1, float b=1) {
    glColor3f(r,g,b);
    glEnable(GL_TEXTURE_2D);
    glBindTexture(GL_TEXTURE_2D, tex);
    glBegin(GL_QUADS);
        glTexCoord2f(0.0f, 0.0f);
        glVertex2f( x, y);
        glTexCoord2f(1.0f, 0.0f);
        glVertex2f(w+x, y);
        glTexCoord2f(1.0f, 1.0f);
        glVertex2f( w+x, h+y);
        glTexCoord2f(0.0f, 1.0f);
        glVertex2f( x, h+y);
    glEnd();
}

What do I need to change to make this OpenGL ES compatible? Also, the reason I am using fixed-function rather than shaders is that I am developing on a machine which doesn’t support GLSL.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T10:26:25+00:00Added an answer on June 2, 2026 at 10:26 am

    In OpenGL ES 1.1 use the glVertexPointer(), glColorPointer(), glTexCoordPointer() and glDrawArrays() functions to draw a quad. In contrast to your OpenGL implementation, you will have to describe the structures (vectors, colors, texture coordinates) that your quad consists of instead of just using the built-in glTexCoord2f, glVertex2f and glColor3f methods.

    Here is some example code that should do what you want. (I have used the argument names you used in your function definition, so it should be simple to port your code from the example.)

    First, you need to define a structure for one vertex of your quad. This will hold the quad vertex positions, colors and texture coordinates.

    // Define a simple 2D vector
    typedef struct Vec2 {
        float x,y;
    } Vec2;
    
    // Define a simple 4-byte color
    typedef struct Color4B {
        GLbyte r,g,b,a;
    };
    
    // Define a suitable quad vertex with a color and tex coords.
    typedef struct QuadVertex {
        Vec2 vect;              // 8 bytes
        Color4B color;          // 4 bytes
        Vec2 texCoords;         // 8 bytes
    } QuadVertex;
    

    Then, you should define a structure describing the whole quad consisting of four vertices:

    // Define a quad structure
    typedef struct Quad {
        QuadVertex tl;
        QuadVertex bl;
        QuadVertex tr;
        QuadVertex br;
    } Quad; 
    

    Now, instantiate your quad and assign quad vertex information (positions, colors, texture coordinates):

    Quad quad;
    quad.bl.vect = (Vec2){x,y};
    quad.br.vect = (Vec2){w+x,y};
    quad.tr.vect = (Vec2){w+x,h+y};
    quad.tl.vect = (Vec2){x,h+y};
    quad.tl.color = quad.tr.color = quad.bl.color = quad.br.color
                  = (Color4B){r,g,b,255};
    quad.tl.texCoords = (Vec2){0,0};
    quad.tr.texCoords = (Vec2){1,0};
    quad.br.texCoords = (Vec2){1,1};
    quad.bl.texCoords = (Vec2){0,1};
    

    Now tell OpenGL how to draw the quad. The calls to gl...Pointer provide OpenGL with the right offsets and sizes to your vertex structure’s values, so it can later use that information for drawing the quad.

    // "Explain" the quad structure to OpenGL ES
    
    #define kQuadSize sizeof(quad.bl)    
    long offset = (long)&quad;
    
    // vertex
    int diff = offsetof(QuadVertex, vect);
    glVertexPointer(2, GL_FLOAT, kQuadSize, (void*)(offset + diff));
    
    // color
    diff = offsetof(QuadVertex, color);
    glColorPointer(4, GL_UNSIGNED_BYTE, kQuadSize, (void*)(offset + diff));
    
    // texCoods
    diff = offsetof(QuadVertex, texCoords);
    glTexCoordPointer(2, GL_FLOAT, kQuadSize, (void*)(offset + diff));
    

    Finally, assign the texture and draw the quad. glDrawArrays tells OpenGL to use the previously defined offsets together with the values contained in your Quad object to draw the shape defined by 4 vertices.

    glBindTexture(GL_TEXTURE_2D, tex);
    
    // Draw the quad
    glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
    
    glBindTexture(GL_TEXTURE_2D, 0);
    

    Please also note that it is perfectly OK to use OpenGL ES 1 if you don’t need shaders. The main difference between ES1 and ES2 is that, in ES2, there is no fixed pipeline, so you would need to implement a matrix stack plus shaders for the basic rendering on your own. If you are fine with the functionality offered by the fixed pipeline, just use OpenGL ES 1.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently working on a game/engine that uses OpenGL for rendering, and recently have
This is my first game I'm working on in C++ using OpenGL for graphics
I'm currently working on an OpenGL game, and recently began refactoring it to support
I'm working on a game using OpenGL and C++. I would really like hardware
I'm working on a 3d game using OpenGL and would like to take it
I'm working on an android game with OpenGL, and I have a game update
I am working on a 2D iPhone game using OpenGL ES and I keep
I'm programming this game in OpenGL, mostly working inside an single EAGLView (I'm not
I am working on a cross platform OpenGL project and it seems that all
Ahoy, I'm working on an OpenGL ES based game for Android using the NDK.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.