Jump to content

  • Log In with Google      Sign In   
  • Create Account


glTexSubImage2D, subtexture not rendering correct.


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
7 replies to this topic

#1 Hintze   Members   -  Reputation: 119

Like
0Likes
Like

Posted 13 February 2014 - 12:49 PM

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

 

Attached Thumbnails

  • Skärmavbild 2014-02-13 kl. 19.41.13.png


Sponsor:

#2 radioteeth   Prime Members   -  Reputation: 1005

Like
0Likes
Like

Posted 13 February 2014 - 01:26 PM

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



#3 Hintze   Members   -  Reputation: 119

Like
0Likes
Like

Posted 13 February 2014 - 01:40 PM

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, 13 February 2014 - 01:43 PM.


#4 empirical2   Members   -  Reputation: 558

Like
0Likes
Like

Posted 13 February 2014 - 01:48 PM

Is test.bmp a 32bpp bitmap or less? If less is it being upscaled to 32bpp?



#5 Hintze   Members   -  Reputation: 119

Like
0Likes
Like

Posted 13 February 2014 - 02:02 PM

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.

 

Attached Thumbnails

  • Skärmavbild 2014-02-13 kl. 20.59.10.png

Attached Files



#6 Brother Bob   Moderators   -  Reputation: 8053

Like
0Likes
Like

Posted 13 February 2014 - 02:06 PM

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.



#7 Hintze   Members   -  Reputation: 119

Like
0Likes
Like

Posted 13 February 2014 - 02:16 PM

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.



#8 Hintze   Members   -  Reputation: 119

Like
0Likes
Like

Posted 13 February 2014 - 03:13 PM

 

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






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS