Jump to content

  • Log In with Google      Sign In   
  • Create Account

Dynamic texture allocation problem


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 returnONE   Members   -  Reputation: 100

Like
0Likes
Like

Posted 29 January 2012 - 08:34 AM

Hi guys,

I'm having a hard time implementing a dynamic texture loader with OpenGL (and SDL).
So far I've created a dynamic list, where the nodes keep pointer to the textures and I can add or delete any members of it, any time, where each scene of the game (splash, menu, in-game, etc) have its list and control its textures to be used, and it works perfectly.

Unfortunatelly I've stucked in a point.
The function glGenTextures() asks for a predetermined number of textures in the very begining of the application.
I've researched about it, and got that glGenTextures() simply determine IDs to the textures, but do not alloc it.

My question here is, how can I load my textures dynamically, since OpenGL seems to limit it in a way that I have to predetermine the number of textures?

Current texture load source:

SetMyImageList(LoadImage("Data/Images/Splash.png"), "Splash");
GetMyImageList()->NewNode(LoadImage("Data/Images/Splash2.png"), "Splash2");

- image is defined in my class
- pimage is a pointer to image. the list require the image data as a pointer.

GLuint* Scene::LoadImage(char* fileName)
{
    GLuint* pimage;
    pimage = ℑ
    SDL_Surface*  surface = IMG_Load(fileName);
    if (!surface) {
	    fprintf(stderr, "Unable to load image: %s\n", SDL_GetError());
	    SDL_Quit();
    }
    //GLuint* teste = GetImageAddess();
    glGenTextures(1, &image);
    glBindTexture(GL_TEXTURE_2D, image);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); // scale linearly when image bigger than texture
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); // scale linearly when image smalled than texture
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, surface->w, surface->h, 0, GL_RGB, GL_UNSIGNED_BYTE, surface->pixels);
    wTex = surface->w;
    hTex = surface->h;
    return pimage;
}


Sponsor:

#2 Rene Z   Members   -  Reputation: 514

Like
1Likes
Like

Posted 29 January 2012 - 09:04 AM

You can call glGenTextures as many times as you want. When adding a texture, call glGenTextures(1, &handle); where handle is a single GLuint.

#3 returnONE   Members   -  Reputation: 100

Like
0Likes
Like

Posted 20 February 2012 - 11:09 AM

Sorry for the delay!
Yes, glGenTextures gives me an ID to each texture that I ask for being loaded. I can simply consider the number it gives me.
Everything went better then expected. Posted Image




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS