Jump to content
  • Advertisement
Sign in to follow this  
nrgyzer

glTexSubImage2D color problem

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

Hello everyone, I'm trying to replace a single pixel by using glTexSubImage2D. I currently using the following code: ushort[] image[130*130*3]; ushort pixelData[255,0,0]; GLuint texture; glGenTextures(1, &texture); glBindTexture(GL_TEXTURE_2D, texture); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexImage2D(GL_TEXTURE_2D, 0, 3, 130, 130, 0, GL_RGB, GL_UNSIGNED_BYTE, &image); glTexSubImage2D(GL_TEXTURE_2D, 0, 65, 65, 2, 2, GL_RGB, GL_UNSIGNED_BYTE, &pixelData); The color of the pixel at position (x,y) = (65,65) should be red (r,g,b) = (255,0,0), but as you can see on http://ipics.biz/img/image3dVD.png - it's not red... it's an other color. I hope anyone can help me -> thanks in advance ;)

Share this post


Link to post
Share on other sites
Advertisement
As you're using GL_UNSIGNED_BYTE, you should use a byte array, not ushort (which I guess is two bytes per element). Secondly, if pixelData is an array, remove the &, and just pass pixelData. Thirdly, you specify 2, 2 for the width/height, which is 4 pixels, so if that is your intention, you need a larger array. And lastly that code won't compile in any language I've ever seen, but I guess it's meant to be pseudo-code. If you still have problems, post the actual compiled code (and what language it's in).

Share this post


Link to post
Share on other sites
1. ushort to byte -> yes, works
2. if I remove the & from pixelData, I get the following error: "... of type byte[0u] to void*"
3. when I use 1,1 instead of 2,2 - nothing happens... (edit: it just works, but... wrong color)
4. the code can be compiled with D
5. When I use 2,2... the color is not exactly what I want

Complete code:

private ubyte image[130*130*3];

private GLuint texture;

this() {

glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture);

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);

glTexImage2D(GL_TEXTURE_2D, 0, 3, 130, 130, 0, GL_RGB, GL_UNSIGNED_BYTE, &image);

ubyte data[255,0,0];

glTexSubImage2D(GL_TEXTURE_2D, 0, 65, 65, 1, 1, GL_RGB, GL_UNSIGNED_BYTE, &data);

}

[Edited by - nrgyzer on March 14, 2010 4:49:33 PM]

Share this post


Link to post
Share on other sites
Don't know D, but that should work.. if the correct address is passed to glTexSubImage2d. Can you cast to void* instead of using the & ?
That might send the address of the pointer to the array instead, which would explain the wrong color.. but I'm not sure.

Share this post


Link to post
Share on other sites
The solution is to use &pixelData[0] instead of &pixelData. The following glTexSubImage2D ist working for me:

glTexSubImage2D(GL_TEXTURE_2D, 0, 65, 65, 1, 1, GL_RGB, GL_UNSIGNED_BYTE, &pixelData[0]);

Thanks, Erik :)

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.

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!