loading textures with SDL
to post C++ code, you surround it with the [source lang="cpp"] and [/source](no tags to make it bold)
http://www.roboguy.net(WIP) - lisperati - SICP - Haskell - Python - OCaml - Lambda the Ultimate - Good Math, Bad Math - Wiki (not Wikipedia) - Pure - Term-Rewriting Functional Language
traiger,
first:
in the first section:
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...
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.
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?
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
Popular Topics
Advertisement