Archived

This topic is now archived and is closed to further replies.

kevbogsp

Texturing quads

Recommended Posts

I posted about 2 weeks ago trying to find a solution to quads being broken into triangles when texturing. Because quads are broken into triangles, a "line" exists on the shared edge of the triangles. I do not want a perspective texture, rather, the checkerboard texture I apply to the quad should be evenly spaced along the borders of the quad (i.e. each square along an edge should have the same width). I have included some sample code this time (most of which was taken from the OpenGL Programming Guide) - I am working in Linux: #include #include #include #define checkImageWidth 64 #define checkImageHeight 64 static GLubyte checkImage[checkImageHeight][checkImageWidth][4]; static GLubyte otherImage[checkImageHeight][checkImageWidth][4]; static GLuint texName[2]; void makeCheckImages(void) { int i, j, c; for(i=0; i[j][0] = (GLubyte) c; checkImage[i][j][1] = (GLubyte) c; checkImage[i][j][2] = (GLubyte) c; checkImage[i][j][3] = 255; c = (((i&0x10)==0)^((j&0x10)==0))*255; otherImage[i][j][0] = (GLubyte) c; otherImage[i][j][1] = (GLubyte) 0; otherImage[i][j][2] = (GLubyte) 0; otherImage[i][j][3] = 255; } } } void init(void) { glClearColor(0.0, 0.0, 0.0, 0.0); glShadeModel(GL_FLAT); glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LESS); glClearDepth(1.0); makeCheckImages(); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glGenTextures(2, texName); glBindTexture(GL_TEXTURE_2D, texName[0]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, checkImageWidth, checkImageHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, checkImage); glBindTexture(GL_TEXTURE_2D, texName[1]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, checkImageWidth, checkImageHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, checkImage); glEnable(GL_TEXTURE_2D); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(-3.0, 3.0, -3.0, 3.0, -3.0, 3.0); } void display(void) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glBindTexture(GL_TEXTURE_2D, texName[0]); glBegin(GL_QUADS); glTexCoord2f(0.0, 0.0); glVertex3f(-1.0, -1.0, 0.0); glTexCoord2f(0.0, 1.0); glVertex3f(-2.0, 1.0, 0.0); glTexCoord2f(1.0, 1.0); glVertex3f(0.0, 1.0, 0.0); glTexCoord2f(1.0, 0.0); glVertex3f(0.0, -1.0, 0.0); glEnd(); glBindTexture(GL_TEXTURE_2D, texName[1]); glBegin(GL_QUADS); glTexCoord2f(0.0, 0.0); glVertex3f(1.5, -1.0, 0.0); glTexCoord2f(0.0, 1.0); glVertex3f(1.0, 1.0, 0.0); glTexCoord2f(1.0, 1.0); glVertex3f(0.5, 1.0, 0.0); glTexCoord2f(1.0, 0.0); glVertex3f(0.5, -1.0, 0.0); glEnd(); glFlush(); } int main(int argc, char** argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); glutInitWindowSize(700, 700); glutInitWindowPosition(100, 100); glutCreateWindow("hello"); init(); glutDisplayFunc(display); glutMainLoop(); return 0; } Thanks

Share this post


Link to post
Share on other sites
First off: Please post your code between [*source] and [*/source] tags (without the *). That way, the browser wont eat half the cpp code and it makes your post a lot more readable.

To fix your problem: glShadeModel(GL_SMOOTH) instead of GL_FLAT should do the trick.

Sander Maréchal
[Lone Wolves Game Development][RoboBlast][Articles][GD Emporium][Webdesign][E-mail]


[edited by - sander on October 7, 2003 5:59:31 AM]

Share this post


Link to post
Share on other sites
Uh... well... that''s very weird. OpenGL shouldn''t be doing that. Can you perhaps post a screenshot? I''m kinda run out of ideas here and I''d like to see the problem.

PS: If you don''t have a hosting space, look for a member called Nervo. He can host images for gamedev. You could also mail me the pic.

Sander Maréchal
[Lone Wolves Game Development][RoboBlast][Articles][GD Emporium][Webdesign][E-mail]

Share this post


Link to post
Share on other sites
I think I found something else.

glBindTexture(GL_TEXTURE_2D, texName[0]);
glBegin(GL_QUADS);
glTexCoord2f(0.0, 0.0);
glVertex3f(-1.0, -1.0, 0.0);
glTexCoord2f(0.0, 1.0);
glVertex3f(-2.0, 1.0, 0.0);
glTexCoord2f(1.0, 1.0);
glVertex3f(0.0, 1.0, 0.0);
glTexCoord2f(1.0, 0.0);
glVertex3f(0.0, -1.0, 0.0);
glEnd();

glBindTexture(GL_TEXTURE_2D, texName[1]);
glBegin(GL_QUADS);
glTexCoord2f(0.0, 0.0);
glVertex3f(1.5, -1.0, 0.0);
glTexCoord2f(0.0, 1.0);
glVertex3f(1.0, 1.0, 0.0);
glTexCoord2f(1.0, 1.0);
glVertex3f(0.5, 1.0, 0.0);
glTexCoord2f(1.0, 0.0);
glVertex3f(0.5, -1.0, 0.0);
glEnd();

You are converting doubles into floats. There''s no guarantee that they''ll end up the same (floating point rounding error). In the above code, change all numbers in the glVertex and glTecCoord calls to float. EG:

glTexCoord2f(1.0f, 0.0f);

instead of

glTexCoord2f(1.0, 0.0);

BTW: Don''t you get a huge amount of errors like "conversion from double to float, possible loss of data" when you compile your program?


Sander Maréchal
[Lone Wolves Game Development][RoboBlast][Articles][GD Emporium][Webdesign][E-mail]

Share this post


Link to post
Share on other sites
Using floats did not change the results.

I have posted a better description of my problem at

http://www-viz.tamu.edu/students/kevbogsp/quadtexture.html

This is a rough page with a few images I threw together. Can you let me know if my reasoning is correct and if there is a way to fix it?

Thanks

Share this post


Link to post
Share on other sites
That is a much better sescription of your problem. Your reasoning is also correct. However, I see no way to fix your problem without the use of projected textures.

Sorry, can''t help you. Maybe one of the OpenGL guru''s around here like YannL know how to fix it.

Sander Maréchal
[Lone Wolves Game Development][RoboBlast][Articles][GD Emporium][Webdesign][E-mail]

Share this post


Link to post
Share on other sites