PDA

View Full Version : poly next to poly



brain21
11-14-2005, 05:25 AM
I have a problem with two polygones that are right next to each other. I am using NeHe's base code with IPicture support. What I do is load two jpg's as textures and draw them to quads that are right next to each other. This works, the problem is that sometimes a line apears between them. The textures are one picture slip in two, so there should no be a line there when I draw them there. It kind of looked like the line was from the same texture, but on the opposite side. So it lookes like it is borowing 1 line from the opposite side of the texture. So what I did is draw bright rectangles in the jpg's and see if they apear on the other side of the quad when I render. And they did. I can translate the quads (together) and this line apears and disapears.

Does anyone know whats happening here? Here's the code I was using:


#include <windows.h> // Header File For Windows
#include <gl\gl.h> // Header File For The OpenGL32 Library
#include <gl\glu.h> // Header File For The GLu32 Library
#include <gl\glaux.h> // Header File For The GLaux Library
#include "NeHeGL.h" // Header File For NeHeGL

#include "NeHe_IPicture.h"

#pragma comment( lib, "opengl32.lib" ) // Search For OpenGL32.lib While Linking
#pragma comment( lib, "glu32.lib" ) // Search For GLu32.lib While Linking
#pragma comment( lib, "glaux.lib" ) // Search For GLaux.lib While Linking

#ifndef CDS_FULLSCREEN // CDS_FULLSCREEN Is Not Defined By Some
#define CDS_FULLSCREEN 4 // Compilers. By Defining It This Way,
#endif // We Can Avoid Errors

GL_Window* g_window;
Keys* g_keys;

// User Defined Variables
float xpos = 0.0f, ypos = 0.0f, zpos = -10.0f;
GLuint tex[6];

BOOL Initialize (GL_Window* window, Keys* keys) // Any GL Init Code & User Initialiazation Goes Here
{
g_window = window;
g_keys = keys;

// Start Of User Initialization
BuildTexture( "pic1.bmp", tex[0] );
BuildTexture( "pic2.bmp", tex[1] );


glClearColor (1.0f, 1.0f, 1.0f, 1.0f); //Black Background
glClearDepth (1.0f); // Depth Buffer Setup
glDepthFunc (GL_LEQUAL); // The Type Of Depth Testing (Less Or Equal)
glEnable (GL_DEPTH_TEST); // Enable Depth Testing
glShadeModel (GL_SMOOTH); // Select Smooth Shading
glHint (GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);// Set Perspective Calculations To Most Accurate

glEnable( GL_TEXTURE_2D );
glDisable( GL_DEPTH_TEST );

return TRUE; // Return TRUE (Initialization Successful)
}

void Update (DWORD milliseconds) // Perform Motion Updates Here
{
float speed = (float)milliseconds / 300.0f;

if (g_keys->keyDown [VK_ESCAPE] == TRUE)// Is ESC Being Pressed?
{
TerminateApplication (g_window); // Terminate The Program
}

if (g_keys->keyDown [VK_F1] == TRUE) // Is F1 Being Pressed?
{
ToggleFullscreen (g_window); // Toggle Fullscreen Mode
}

if ( g_keys->keyDown[ VK_LEFT ] == TRUE )
{
xpos += speed;
}
else if ( g_keys->keyDown[ VK_RIGHT ] == TRUE )
{
xpos -= speed;
}

if ( g_keys->keyDown[ VK_UP ] == TRUE )
{
ypos -= speed;
}
else if ( g_keys->keyDown[ VK_DOWN ] == TRUE )
{
ypos += speed;
}

if ( g_keys->keyDown[ VK_PRIOR ] == TRUE )
{
zpos += speed;
}
else if ( g_keys->keyDown[ VK_NEXT ] == TRUE )
{
zpos -= speed;
}

}

void Draw (void)
{
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer
glLoadIdentity (); // Reset The Modelview Matrix
glTranslatef ( xpos, ypos, zpos); // Translate 6 Units Into The Screen

float x = 1.0f,
y = 1.0f,
z = 0.0f;

glBindTexture( GL_TEXTURE_2D, tex[0] );
glBegin( GL_QUADS );
glTexCoord2f( 0.0f, 1.0f ); glVertex3f( -x, y, z );
glTexCoord2f( 1.0f, 1.0f ); glVertex3f( x, y, z );
glTexCoord2f( 1.0f, 0.0f ); glVertex3f( x, -y, z );
glTexCoord2f( 0.0f, 0.0f ); glVertex3f( -x, -y, z );
glEnd();

glTranslatef( 0.0f, y+y, 0.0f );
glBindTexture( GL_TEXTURE_2D, tex[1] );
glBegin( GL_QUADS );
glTexCoord2f( 0.0f, 1.0f ); glVertex3f( -x, y, z );
glTexCoord2f( 1.0f, 1.0f ); glVertex3f( x, y, z );
glTexCoord2f( 1.0f, 0.0f ); glVertex3f( x, -y, z );
glTexCoord2f( 0.0f, 0.0f ); glVertex3f( -x, -y, z );
glEnd();

glFlush (); // Flush The GL Rendering Pipeline
}I even tried disabling the depth buffer, which changed nothing. I tried combining the textures in photoshop and using a quad strip. This worked, but I need to combine textures on the fly and different ones, that's why I need seperate polygones.

Brain21

memfr0b
11-14-2005, 07:07 AM
You're probably running into precision problems. If you want two primitives to share an edge, you have to make sure they use the same vertices for that edge. This means same parameters to glVertex* and same transformation matrizes.


glBindTexture( GL_TEXTURE_2D, tex[0] );
glBegin( GL_QUADS );
glTexCoord2f( 0.0f, 1.0f ); glVertex3f( -x, y, z );
glTexCoord2f( 1.0f, 1.0f ); glVertex3f( x, y, z );
glTexCoord2f( 1.0f, 0.0f ); glVertex3f( x, -y, z );
glTexCoord2f( 0.0f, 0.0f ); glVertex3f( -x, -y, z );
glEnd();

// don't do this, modify the vertices instead
// glTranslatef( 0.0f, y+y, 0.0f );

glBindTexture( GL_TEXTURE_2D, tex[1] );
glBegin( GL_QUADS );
glTexCoord2f( 0.0f, 1.0f ); glVertex3f( -x, 3*y, z );
glTexCoord2f( 1.0f, 1.0f ); glVertex3f( x, 3*y, z );
glTexCoord2f( 1.0f, 0.0f ); glVertex3f( x, y, z );
glTexCoord2f( 0.0f, 0.0f ); glVertex3f( -x, y, z );
glEnd();You might also need to add texture borders to get correct interpolation results on the face transition.

brain21
11-14-2005, 08:58 AM
I tried that. It didn't work. I got the same problem. I took several hours and searched around this message board. I found some things I could try like GL_CLAMP_TO_EDGE or GL_CLAMP_TO_BORDER for glTexParameteri. I will have to upgrade to OpenGL 1.2 for that I guess.

I did get it to work with something else. instead of using 0.0f and 1.0f for the texture coords, I used 2.0f/1024.0f and 1022.0f/1024.0f. This seems to work well and I can't see any seam at all.

Thanks for the responce though.

Brain21