Advertisement

loading textures with SDL

Started by November 11, 2004 11:45 AM
11 comments, last by traiger 20 years ago
to post C++ code, you surround it with the [source lang="cpp"] and [/source](no tags to make it bold)
traiger,

first:

in the first section:
Quote: glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height,0, GL_RGBA, GL_UNSIGNED_BYTE,image->pixels);


I would suggest changing the first GL_RGB to GL_RGBA since you are wanting to preserve the format from the image to the internal openGL texture structure.

Second, in your drawing section, I dont see that you've enabled blending anywhere. Is it globally enabled? I dont usually do that cause you have to be real careful which order you draw things in. I generally enclose the draw code for any transparent images I have with:

glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);

<draw code goes here>

glDisable(GL_BLEND);

Also, I notice that you are assigning colors to the vertices. No problem here but the color you assign will combine with the texture image to "shade" it with that color. I "generally" do not use color on the vertices if I am going to assign a texture to it.

Anyways, just a couple of things I noticed. Mebbe they'll help...
Hard work USUALLY pays off in the future, but laziness ALWAYS pays off right now.
Advertisement
Bullfrog

Yup that GL_RGB is usually GL_RGBA, although that makes the png texture invisible.

Because this is only a sprite engine it makes sorting a lot easier so blending is global.


I'll look into the vetex colouring issue, thanks for your help.

There must be some one who use png's for textures out there how do you do it?

This topic is closed to new replies.

Advertisement