Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Ruudje

Creating textures

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

In the tutorials, a texture is stored in a GLuint. This is a pointer? Why I am asking is because Im planning something like this: I wanna create a texture-loader which has a GLuint as a local variable, and return that variable at the end. Should I return GLuint, or &GLuint, and how exactly do I release the texture, simply by using delete GLuint-variable? Additional q: which texture formats are most popular, and worth adding support for? Ive got bmp, jpg and tga on my list

Share this post


Link to post
Share on other sites
Advertisement
quote:
Original post by Ruudje
In the tutorials, a texture is stored in a GLuint. This is a pointer?



Yes, in a round about way. If you display it, you''ll see that the value returned will have an inreasing value, starting with 1. If it''s 0, the texture wasn''t created properly. So it''s more of an index in a memory address lookup table.

Share this post


Link to post
Share on other sites
first, let say your texture-loader function is defined as follow:
GLuint LoadTex(char *filename);
note that the parameters may be different, it's not important.

your function should look like this:
GLuint LoadTex(char *filename)
{
GLuint texId;
unsigned char *texData; // the texture pixels

// load your file here
// and store the pixels in texData
// don't forget to allocate memory for texData
// texData = (unsigned char *)malloc(texSize)
// where texSize is the size (in bytes) of the image data
// if you have width and height you need to calculate the size
// texSize = width * height * bits_per_pixel

glEnable(GL_TEXTURE_2D); // enable 2D texturing
glGenTextures(1, &texId); // generate the texture Id
glBindTexture(GL_TEXTURE_2D, texId); // this is a 2D texture

// do texture modifications here
// hint: glTexParameteri() or gluBuild2DMipmaps()

// load the texture image
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, texWidth, texHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, texData);

return texId;
}

[EDIT]
for releasing the texture, AFAIK OpenGL takes care of doing it for you.
[/EDIT]

Matt
---------
"Without C, we would only have Basi, Pasal and obol."

[edited by - lemurion on September 24, 2003 1:24:28 PM]

Share this post


Link to post
Share on other sites
Ive tried to implement the tga-loader from the tutorials today, but failed The only real difference from the tutor that I had was that I stored the Texture-structure in a class and not globally, but this is what happened:

First of all, it went fine untill AFTER loading the texture using the LoadTGA function. But then you have to create the actual texture using the opengl code. That wouldnt work. the texID (the GLuint) was still 0 afterwards, and the really strange thing was when I looked at the list of members of my class, the structure was displayed as: var int file_3ds::Texture. It shouldve been like this though: var Texture file_3ds::texture, since I named my instance texture. I couldnt get this fixed, so ended up removing all the tga code from my files.

I still cant explain why... spent 5 hours working on this

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!