Advertisement Jump to content
Sign in to follow this  
Hintze

glTexSubImage2D, subtexture not rendering correct.

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

Hi guys!

I have a little problem with my program, when i try to set a sub texture to my color map on my terrain it works just as i want it to except it draws the sub texture all wrong. So I am not quite sure how to proceed at the moment so any help is greatly appreciated :)

void UpdateTexture::CreateSubTexture(glm::vec2 position, unsigned char * imageData)
{
    glBindTexture(GL_TEXTURE_2D, 3);
    glTexSubImage2D(GL_TEXTURE_2D, 0, position.x, position.y, 128,
                    128 , GL_RGBA,
                    GL_UNSIGNED_BYTE, imageData);
}

the sub texture is an all purple square at 128x128 for testing purposes, but as you can see in the picture that is not what i am getting at all.

 

thanks for your time!

//Hintze

 

Share this post


Link to post
Share on other sites
Advertisement

Either the existing texture is a different format (than GL_RGBA) or your data you are passing in is formatted wrong.

Share this post


Link to post
Share on other sites
glTexImage2D(GL_TEXTURE_2D, 0,GL_RGB, width, height, 0, GL_BGR, GL_UNSIGNED_BYTE, data);

that is how i load in my color map, so i tried using GL_RGB but with the same result.

 

not quite sure how my data could be formatted wrong, all i do is instead of binding it to a texture in my textureLoader i save it instead as

unsigned char * imageData;
if(strcmp (imagepath,"test.bmp"))
    {
        imageData = data;  
    }

edit:might have found an error on my part...

which is what I use later in my other function.

thanks for your answer, and just ask if you need more info.

//Hintze

Edited by Hintze

Share this post


Link to post
Share on other sites

It seems it all had to do with my new bmp i tried to load in,

I  tried it again with a texture I know work and it´s all fine, except the color is wrong and the color of the color map is seen in sharp angles.

 

Share this post


Link to post
Share on other sites

Looks like the color channels are switched. The code in your first post tells OpenGL that the color is in RGBA format, but the bitmap is probably stored in BGRA format.

Share this post


Link to post
Share on other sites

Looks like the color channels are switched. The code in your first post tells OpenGL that the color is in RGBA format, but the bitmap is probably stored in BGRA format.

thank you! :D

when i loaded it in GL_BGR everything works just fine :)

the only problem is the one i had before with the underlaying color of the colormap still showing in sharp angles, see the grass picture.

Share this post


Link to post
Share on other sites

 

Looks like the color channels are switched. The code in your first post tells OpenGL that the color is in RGBA format, but the bitmap is probably stored in BGRA format.

thank you! biggrin.png

when i loaded it in GL_BGR everything works just fine smile.png

the only problem is the one i had before with the underlaying color of the colormap still showing in sharp angles, see the grass picture.

 

never mind what i said

I don't seem to have the problem when using other textures so that is not an issue:)

thanks everyone for your help!

:D

//Hintze

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!