PDA

View Full Version : Texture representation causes problems



GLABA2017
09-05-2017, 04:16 AM
Hi,
i cant find he misstake i did. Pls Help me.

My Problems are:
-Image is printet nearly white (95% with some blue/red/green pixels) but he images is nearly colored more hen 90%
-Texture edges arn't parse on Images edges like:

Correct edges parse:
0---------1
|_| _ |_|_|
|_| _ |_|_|
3---------2

and it is shown as:
0---------1
| /_ /_ /_|
|/ _ /_ / _|
-------23--

Image is png and has w:505 and h:378

My Code:
Image load:


cv::Mat *GroundImage;

if(GroundImage)
delete GroundImage;
cv::Mat load=cv::Mat(cv::imread("download.png"));
cv::flip(load,load,0);
cvtColor(load, load, CV_BGR2RGB);

GroundImage=new cv::Mat(load);


Set Image in Opengl window (it is inside a winform)


void SetGround(cv::Mat *Image){
GroundImage=Image;

if(tex)
delete tex;
tex=new GLuint ();
glEnable(GL_TEXTURE_2D);
// Create Texture
glGenTextures(1, tex);
glBindTexture(GL_TEXTURE_2D, *tex); // 2d texture (x and y size)

glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTE R,GL_LINEAR); // scale linearly when image bigger than texture
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTE R,GL_LINEAR); // scale linearly when image smalled than texture
// 2d texture, level of detail 0 (normal), 3 components (red, green, blue), x size from image, y size from image,
// border 0 (normal), rgb color data, unsigned byte data, and finally the data itself.
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, GroundImage->cols, GroundImage->rows, 0, GL_BGR_EXT, GL_UNSIGNED_BYTE, GroundImage->data);
glBindTexture(GL_TEXTURE_2D, *tex); // choose the texture to use.
}



and draw


void drawGround()
{
if(GroundImage){
glColor3f(1,1,1); // set global color to white, otherwise this color will be (somehow) added to the texture

glBegin(GL_QUADS);

float x = 10.0;
float y = 10.0;

glTexCoord2f(0.0f, 0.0f); glVertex3f(-x, -y, 0.0f);
glTexCoord2f(0.0f, 1.0f);glVertex3f( x, -y, 0.0f);
glTexCoord2f(1.0f, 1.0f);glVertex3f( x, y, 0.0f);
glTexCoord2f(1.0f, 0.0f);glVertex3f(-x, y, 0.0f);

glEnd();
}
}

GClements
09-05-2017, 05:58 AM
Image is png and has w:505

If the image data is RGB (3 bytes per pixel) and the image width isn't a multiple of 4, then you'll need to use:


glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

prior to the glTexImage2D() call.

The default alignment is 4 bytes.

GLABA2017
09-05-2017, 07:09 AM
Thanks, very nice.