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