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 6244221
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T12:17:15+00:00 2026-05-24T12:17:15+00:00

there’s a problem which I don’t know how to solve. I know how to

  • 0

there’s a problem which I don’t know how to solve.
I know how to get multiple textures in my 3D openGL and MVC++ 2010 game but the way is extremely slow. The more textures I load the more the game gets slower. It has been 2 weeks since I got stuck with this. I searched many sites but none of them helped me.

I don’t want glaux because it keeps giving me errors and is said to have memory leaks.
This is the way I load .RAW textures:

GLuint texture; //ID to bind with

    GLuint LoadTexture(const char *filename, int imW, int imH){
    unsigned char*data;
    FILE*file;

    file=fopen(filename,"rb");
    if(file==NULL)return 0;
    data=(unsigned char*)malloc(imW*imH*3);
    fread(data,imW*imH*3,1,file);
    fclose(file);

    glGenTextures(1,&texture);
    glBindTexture(GL_TEXTURE_2D,texture);
    glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_MODULATE);
    glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_LINEAR);
    glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
    glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT);
    glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_REPEAT);
    glTexParameterf(GL_TEXTURE_2D,0x8191,1); //0x8191 means GL_GENERATE_MIPMAP
    glTexImage2D(GL_TEXTURE_2D,0,3,imW,imH,0,GL_RGB,GL_UNSIGNED_BYTE,data);
    free(data);
    return texture;
    }

I have opengl 2 but I use “glTexParameterf(GL_TEXTURE_2D,0x8191,1);” to build mipmaps because “gluBuild2DMipmaps” is slower than that.

void model_room(float x, float y, float x2, float y2, float z, float z2){
LoadTexture("tex_floor.raw",512,512);
model_floor(x,y,x2,y2,z,7,7);
glDeleteTextures(1,&texture);

LoadTexture("tex_ceiling.raw",512,512);
model_floor(x,y,x2,y2,z2,4,4);
glDeleteTextures(1,&texture);

LoadTexture("tex_wall.raw",512,512);
model_wall(x,y,x,y2,z,z2,1,1);
glDeleteTextures(1,&texture);

LoadTexture("tex_tiles.raw",512,512);
model_wall(x,y2,x2,y2,z,z2,1,1);
glDeleteTextures(1,&texture);

LoadTexture("tex_diamondtiles.raw",512,512);
model_wall(x2,y2,x2,y,z,z2,1,1);
glDeleteTextures(1,&texture);

LoadTexture("tex_castlepoint.raw",512,512);
model_wall(x2,y,x,y,z,z2,5,3);
glDeleteTextures(1,&texture);
}

Over here the code loads the textures and then deletes them every frame. It might not be a good idea but for now it’s okay. For “model_wall” and “model_floor”, this is the code:

    void model_floor(float x, float y, float x2, float y2, float z, float tc1, float tc2){
glBegin(GL_QUADS);
    glTexCoord2f(0,     0);     glVertex3f(x,  y,  z);
    glTexCoord2f(tc1,   0);     glVertex3f(x,  y2, z);
    glTexCoord2f(tc1,   tc2);   glVertex3f(x2, y2, z);
    glTexCoord2f(0,     tc2);   glVertex3f(x2, y,  z);
glEnd();
    }

    void model_wall(float x, float y, float x2, float y2, float z1, float z2, float tch, float tcv){
glBegin(GL_QUADS);
    glTexCoord2f(0,     0);     glVertex3f(x,   y,  z2);
    glTexCoord2f(tch,   0);     glVertex3f(x2,  y2, z2);
    glTexCoord2f(tch,   tcv);   glVertex3f(x2,  y2, z1);
    glTexCoord2f(0,     tcv);   glVertex3f(x,   y,  z1);
glEnd();
    }

I just want a good way to load textures without slowing down the game and it’s not important to only load raw files but anything that is recommended. I’m not a Win Base programmer so I may want some explanation on those type of codes. Any help would be appreciated. Thanks in advance!

  • 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-05-24T12:17:17+00:00Added an answer on May 24, 2026 at 12:17 pm

    It might not be a good idea to load and destroy all textures every frame? Definitely not a good idea and surely the cause of your performance drop! That’s what texture objects are for (the IDs you get from glGenTextures). These are handles to the textures in video memory. So you load all your textures at start, then just bind the neccessary texture (using glBindTexture) before drawing (before the model_wall calls). And then at the end of your program you destroy them using glDeleteTextures.

    By your mentioning of glaux, I assume you are using quite old learning ressources, maybe you should look for a better tutorial/book if you got this practice from there.

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

Sidebar

Related Questions

There is no problem to get the src or alt separately,but how can get
There is a product which runs multiple reports to indicate the quality of different
There is a strange bug which I can't solve. The bug is reproducable by
There are a few ways to get class-like behavior in javascript, the most common
There are numerous Agile software development methods. Which ones have you used in practice
There's http://www.amazon.com/gp/product/0321278542/ but it looks a bit dated. Specificaly, it talks about bits that
There is a container, for example lets say which has a volume of V.
There is a vim function Send_to_Screen(text) which sends some text to a console screen
There are 2 servers, they need to know the status(live oe dead) each other.
There's a lot of reading on self referencing problems, but I can't seem to

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.