Skip to main content
gamedev.net
🔒 Locked

Texturing mapping with artifacts

Started by serious_learner07 5 replies 800+ views
Original Post
serious_learner07
serious_learner07
I need to texture the whole window (win_w,win_h). But My textured Quad have some artifacts with some portion of the texture having pattern of previously block of the texture. The following is the my texture mapping code.

glPushMatrix();
glLoadIdentity();       
  // Reset The View
glTranslatef(0.0f,0.0f,0.0f);
 // Bind the texture to the polygons
glBindTexture( GL_TEXTURE_RECTANGLE_NV, texture[currenttexture]);
glTexParameteri(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
glTexParameteri(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
glTexParameteri(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_BORDER);
glTexParameteri(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glBegin(GL_QUADS);
glTexCoord2f(0.0, 0.0);glVertex2f(0.0, 0.0);
glTexCoord2f(win_w, 0.0);glVertex2f(win_w, 0.0);
glTexCoord2f(win_w, win_h);glVertex2f(win_w, win_h);
glTexCoord2f(0.0, win_h);glVertex2f(0.0, win_h);
glEnd();
Any suggestions. Thanks in advance.
bitshifter
bitshifter
Texture coordinate expect to be clamped to [0.0~1.0] range.
Texture coordinates should start at the top left corner, same for the vertices.
Also, normal winding is done in a counter-clockwise order.

So..
t1/v1 = top left
t2/v2 = bottom left
t3/v3 = bottom right
t4/v4 = top right

And ditch these:
glTexParameteri(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);glTexParameteri(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);glTexParameteri(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_BORDER);


And calling glTranslatef(0.0,0.0,0.0); does nothing there, you have the identity matrix already.
serious_learner07
serious_learner07
This is my output.







[Edited by - serious_learner07 on August 25, 2008 2:57:58 AM]
Hodgman
Hodgman
For future reference, this forum uses HTML tags not BB tags, so to post a link/image it should look like this:


Quote:
Original post by bitshifter
Texture coordinate expect to be clamped to [0.0~1.0] range.
This is generally true, but AFAIK when using GL_TEXTURE_RECTANGLE_NV, texture coordinates are non-normalized texel indices.

With new cards though, I'm pretty sure you don't need to use GL_TEXTURE_RECTANGLE_NV any more -- you should just be able to use GL_TEXTURE_2D and normalized (0.0-1.0) texture coordinates as usual.

[EDIT] perhaps the problem isn't with your drawing code that you posted - it might be a problem with the code that actually creates the texture.
serious_learner07
serious_learner07
Quote:
Original post by Hodgman
For future reference, this forum uses HTML tags not BB tags, so to post a link/image it should look like this:



Thanks Hodgman. I have changed. Following is my initialization code for the Texture. .

glEnable( GL_TEXTURE_RECTANGLE_NV );// Generate one texture IDglGenTextures( 1, &texture );// Write the 32-bit RGBA texture buffer to video memoryglTexImage2D( GL_TEXTURE_RECTANGLE_NV, 0, GL_RGB, TextureImage->sizeX, TextureImage->sizeY,0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage->data );// Bind the texture using GL_TEXTURE_RECTANGLE_NVglBindTexture( GL_TEXTURE_RECTANGLE_NV, texture);// Enable bilinear filtering on this textureglTexParameteri( GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_MIN_FILTER, GL_LINEAR );glTexParameteri( GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_MAG_FILTER, GL_LINEAR );


My ultimate aim is Full Window texture.

[Edited by - serious_learner07 on August 25, 2008 3:54:06 AM]
ma_hty
ma_hty
Quote:
Original post by serious_learner07
glBegin(GL_QUADS);glTexCoord2f(0.0, 0.0);glVertex2f(0.0, 0.0);glTexCoord2f(win_w, 0.0);glVertex2f(win_w, 0.0);glTexCoord2f(win_w, win_h);glVertex2f(win_w, win_h);glTexCoord2f(0.0, win_h);glVertex2f(0.0, win_h);glEnd();
...


I think it should be the following instead...
glBegin(GL_QUADS);glTexCoord2f(0.0, 0.0);glVertex2f(0.0, 0.0);glTexCoord2f(TextureImage->sizeX, 0.0);glVertex2f(win_w, 0.0);glTexCoord2f(TextureImage->sizeX, TextureImage->sizeY);glVertex2f(win_w, win_h);glTexCoord2f(0.0, TextureImage->sizeY);glVertex2f(0.0, win_h);glEnd();
V-man
V-man
Quote:
Original post by serious_learner07
glEnable( GL_TEXTURE_RECTANGLE_NV );// Generate one texture IDglGenTextures( 1, &texture );// Write the 32-bit RGBA texture buffer to video memoryglTexImage2D( GL_TEXTURE_RECTANGLE_NV, 0, GL_RGB, TextureImage->sizeX, TextureImage->sizeY,0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage->data );// Bind the texture using GL_TEXTURE_RECTANGLE_NVglBindTexture( GL_TEXTURE_RECTANGLE_NV, texture);// Enable bilinear filtering on this textureglTexParameteri( GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_MIN_FILTER, GL_LINEAR );glTexParameteri( GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_MAG_FILTER, GL_LINEAR );


My ultimate aim is Full Window texture.


You should probably convert that to

// Generate one texture IDglGenTextures( 1, &texture );// Bind the texture using GL_TEXTURE_RECTANGLE_NVglBindTexture( GL_TEXTURE_RECTANGLE_NV, texture);// Enable bilinear filtering on this textureglTexParameteri(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);glTexParameteri(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);glTexParameteri( GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_MIN_FILTER, GL_LINEAR );glTexParameteri( GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_MAG_FILTER, GL_LINEAR );glTexImage2D( GL_TEXTURE_RECTANGLE_NV, 0, GL_RGB, TextureImage->sizeX, TextureImage->sizeY,0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage->data );


Also, GL_CLAMP_TO_BORDER is not accelerated on some GPUs and you don't need it. What you are looking for is GL_CLAMP_TO_EDGE.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.