Jump to content
  • Advertisement
Sign in to follow this  

Texture Questions

This topic is 4739 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

Can glGenTextures, and glDeleteTextures not be used with anything but an array? Each instance of my texmap class has a GLuint m_TexObject to be used for the texture, but I can't get it to compile. Am I stuck storing them all in an array, I guess through some kind of material manager class? Is there any reason I would want to keep my textures in memory in my class? Or does GL keep them in RAM and on the card too? I don't think I've ever seen this explained in anything I read. what happens if I load 8mb worth of textures and the user has a 4mb card? Is glGetTexImage what I use to feed the texture into dlDrawPixels?

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by Vampyre_Dark

Can glGenTextures, and glDeleteTextures not be used with anything but an array? Each instance of my texmap class has a GLuint m_TexObject to be used for the texture, but I can't get it to compile. Am I stuck storing them all in an array, I guess through some kind of material manager class?
Those functions take a pointer to a GLuint, so to use a single variable you pass the address of it (ie: glGenTextures(1, &texName);).
Quote:
Original post by Vampyre_Dark

Is there any reason I would want to keep my textures in memory in my class? Or does GL keep them in RAM and on the card too? I don't think I've ever seen this explained in anything I read. what happens if I load 8mb worth of textures and the user has a 4mb card?
All you need to keep track of is the texture name, which is just an unsigned int. It acts as an ID for opengl to know which texture you're talking about. Your video card's opengl driver decides where to put the memory for the texture, which will most likely be in video ram but it will handle all the paging back and forth between system ram it needs to do if you don't have enough VRAM left. This way you don't have to worry about where OpenGL puts the texture and it will still work (it will be slow if it's in system memory though).
Quote:
Original post by Vampyre_Dark

Is glGetTexImage what I use to feed the texture into dlDrawPixels?
The pixels parameter in glDrawPixels is just an array of data representing the pixels you wish to draw in whichever format you send to glDrawPixels. You can use glGetTexImage to get the pixel data from a texture object. You should not use glDrawPixels for drawing textures though because the texture data is already (most likely) in VRAM and pulling the data from the card to system ram, then sending it back to the card with glDrawPixels is pretty pointless. If you already have a texture object created the best way to draw it on screen is to map it to a fullscreen quad. If you need help with that, there are MANY tutorials around.

Share this post


Link to post
Share on other sites
I'm using glDrawPixels to draw menu sprites in ortho mode. I figured it would be faster using a texture directly from vram. [sad]

Share this post


Link to post
Share on other sites
Quote:
Original post by Vampyre_Dark
I'm using glDrawPixels to draw menu sprites in ortho mode. I figured it would be faster using a texture directly from vram. [sad]
It is faster to use a texture, but you don't use textures with glDrawPixels. glDrawPixels takes an array of pixels in system memory and sends it to the frame-buffer, so to use glDrawPixels with a texture that's in vram you first need to get the data from vram (glGetTexImage, very slow) and then send it back to vram (glDrawPixels, also pretty slow). The way you use textures is to map it onto a quad. Again, there are many tutorials on the net that show how to use OpenGL texturing. For drawing menus you would just go into ortho mode and draw a quad in the correct spot with the correct menu texture bound.

EDIT: Here's a texture mapping tutorial at NeHe's site.

Share this post


Link to post
Share on other sites
I understand how to use texturing. :) I wasn't asking how to use it.

Nothing I've read has mentioned glDrawPixels as being slow, and I was keeping copies of my textures in memory anyways, so I was using it a bit. I didn't need the functionality of a quad for those GUI bits, as they are transfered to the screen in exact size. Also, it's easier to place those bits in terms of actual pixels, and not having to go through the trial and error of 'projecting' them and compiling to see where they show up.

I guess I will redesign my texturing stuff, to only keep one temp buffer to store a loaded texture to feed to opengl.

Share this post


Link to post
Share on other sites
Quote:
Original post by Vampyre_Dark
I understand how to use texturing. :) I wasn't asking how to use it.
Ah okay, sorry I misunderstood.
Quote:
Nothing I've read has mentioned glDrawPixels as being slow, and I was keeping copies of my textures in memory anyways, so I was using it a bit. I didn't need the functionality of a quad for those GUI bits, as they are transfered to the screen in exact size. Also, it's easier to place those bits in terms of actual pixels, and not having to go through the trial and error of 'projecting' them and compiling to see where they show up.

I guess I will redesign my texturing stuff, to only keep one temp buffer to store a loaded texture to feed to opengl.
glDrawPixels isn't really slow, it's just relatively slow compared to texturing a quad since you need to send all the pixels over whenever you want to draw it, instead of just sending it over once like you do for texturing.

As for placing in screen coordinates, that is easy to do with an orthographic projection. Just use glOrtho with (0,0) as the bottom-left and (screenWidth, screenHeight) as the top-right (or swap the bottom and top parameters to make the top-left the origin), then say you render a quad like this...
glBegin(GL_QUADS);
glVertex2f(20.0f, 20.0f);
glVertex2f(100.0f, 20.0f);
glVertex2f(100.0f, 50.0f);
glVertex2f(20.0f, 50.0f);
glEnd();
//Or reverse the winding order if you use top-left origin
Then the bottom-left vertex will be projected to pixel (20,20) and the top-right will be projected to (100,50).

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!