glTexSubImage2D color problem
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, ℑ);
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 ;)
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).
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, ℑ);
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]
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, ℑ);
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]
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.
That might send the address of the pointer to the array instead, which would explain the wrong color.. but I'm not sure.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement