Sign in to follow this  
nrgyzer

glTexSubImage2D color problem

Recommended Posts

nrgyzer    105
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
Erik Rufelt    5901
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
nrgyzer    105
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
Erik Rufelt    5901
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
nrgyzer    105
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this