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

  • Home
  • SEARCH
  • 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 8881659
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:23:27+00:00 2026-06-14T20:23:27+00:00

I’m programming a 2D-Game in OpenGL and I have to output a level which

  • 0

I’m programming a 2D-Game in OpenGL and I have to output a level which consists of 20×15 fields.

So I’m currently outputting a texture for each field which is quite slow (300 textures/frame).

But due to the reason that the level never changes, I wondered if it’s possible to combine the textures to a big, single texture before the game-loop starts.

Then I would have to output only one texture with 4 Texture Coordinates (0/0)(0/1)(1/1)(1/0) and 4 glVertex2f() which specifies the position in the Window.

This is my current Code for each of the 300 fields:

glColor3f(1,1,1);
glBindTexture(GL_TEXTURE_2D,textur);
glBegin(GL_QUADS);
    glTexCoord2f(textArea.a.x,textArea.b.y);glVertex2f(display.a.x,display.a.y);
    glTexCoord2f(textArea.a.x,textArea.a.y);glVertex2f(display.a.x,display.b.y);
    glTexCoord2f(textArea.b.x,textArea.a.y);glVertex2f(display.b.x,display.b.y);
    glTexCoord2f(textArea.b.x,textArea.b.y);glVertex2f(display.b.x,display.a.y);
glEnd();

Note that I have the images for all possible field-types in one .tga-File. So I’m choosing the right one with glTexCoord2f().

The image-File with all Tiles is loaded into

GLuint textur;

So I bind the same texture for every field.

My target is to decrease CPU-time. Display-Lists didn’t work because there is so many data to load in the Graphics Card, that, in the end, display-Lists were even slower.

I also wasn’t able to use VBOs because I don’t use extensions like GLUT.

So my idea was to generate a single texture which should be quite easy and effective.

I hope you can give me feedback how I can combine textures and if this method would be the easiest one to increase performance

EDIT: that are the OpenGl-Functions I use in my program:

When I start the program, I initialize the window:

glfwInit();                     
if( !glfwOpenWindow(windowSize.x,windowSize.y, 0, 0, 0, 0, 0, 0, GLFW_WINDOW ) ) 
{   glfwTerminate();           
    return;
}

And that’s all what the game-loop does with OpenG:

int main()
{
    //INIT HERE (see code above)

    glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
    glEnable(GL_BLEND);                                
    glAlphaFunc(GL_GREATER,0.1f);
    glEnable(GL_ALPHA_TEST);

    long loopStart;//measure loopcycle-time
    do{
        height = height > 0 ? height : 1;
        glViewport( 0, 0, width, height );              //set Origin
        glClearColor( 0.0f, 0.0f, 0.0f, 0.0f );      //background-color
        glClear(GL_COLOR_BUFFER_BIT);
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();                      
        glOrtho(0,windowSize.x,0,windowSize.y,0,128);   //2D-Mode
        glMatrixMode(GL_MODELVIEW);
        loopStart=clock();

        //(...) OUTPUT HERE (code see above)

        glfwSwapBuffers();                              //erzeugte Grafikdaten ausgeben

        printf("%4dms -> ",clock()-loopStart);
    }while(...);

    glDisable(GL_ALPHA_TEST);
    glDisable(GL_TEXTURE_2D);
    glfwTerminate();
}
  • 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-14T20:23:27+00:00Added an answer on June 14, 2026 at 8:23 pm

    I identified a huge time-killer now. The textures I was using were too large, and the resolution was very unefficient.

    The main-texture which included the level sprites had a resolution of 2200×2200 Pixels. So the GPU increased the size to 4096×4096 and calculated it with a huge amount of data.

    The image contains 10×10 different Level-Tiles which are outputed on the screen with a resolution of 50×50 pixels each.
    So I saved the Tiles-File with a lower resolution (1020 x 1020 Pixels -> each tile=102x102px) and now I have a loop-cycle time of <=15ms.
    This isn’t perfect, but in comparison with my previous 30-60ms it was a huge progress.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have an autohotkey script which looks up a word in a bilingual dictionary
I have an array which has BIG numbers and small numbers in it. I
I have a text area in my form which accepts all possible characters from
Let's say I'm outputting a post title and in our database, it's Hello Y&#8217;all
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small

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.