PDA

View Full Version : FLICKERING PROBLEM.....Please Help



zadeh79
08-03-2006, 03:31 PM
Can someone please help me find out why the texture is flickering? HERE IS MY CODE:


#include <OpenGLSB.h>
#include <GLTools.h>
#include "glbmp.h"


GLfloat a = 0.0;
GLfloat s = 0.0;
GLfloat x = 0.0;
GLfloat y = 0.0;
GLfloat anisosize;


void init(void)
{

glEnable(GL_MULTISAMPLE);
glEnable(GL_DEPTH_TEST);
glEnable(GL_TEXTURE_3D);

}


void RenderScene(void)
{


GLuint texture = 0;

glbmp_t bitmap;

glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

glbmp_LoadBitmap("grass.bmp", 1, &bitmap);

//generate and bind the OpenGL texture
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture);


//copy data from bitmap into texture
glTexImage2D(GL_TEXTURE_2D, 0, 3, bitmap.width, bitmap.height,0, GL_RGB, GL_UNSIGNED_BYTE, bitmap.rgb_data);


glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_R, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);



glViewport(0, 0, 1024, 768);
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);


glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(75.0, 1.0, -2.0, 2.0);


glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

gluLookAt(0.0, 0.0, 0.0, 0.0 ,0.0, 0.0, 0.0, 1.0, 0.0);


glShadeModel(GL_SMOOTH);



glFrontFace(GL_CCW);
glEnable(GL_CULL_FACE);


glBegin(GL_QUAD_STRIP);

glTexCoord3f(0.0, 0.0, 0.0);
glVertex3f(0.0f, 0.0f, 0.0f);

glTexCoord3f(0.0, 1.0, 0.0);
glVertex3f(0.0f, 1.0f, 0.0f);

glTexCoord3f(1.0, 1.0, 0.0);
glVertex3f(1.0f, 1.0f, 0.0f);

glTexCoord3f(1.0, 0.0, 0.0);
glVertex3f(1.0f, 0.0f, 0.0f);

glEnd();





glDeleteTextures(1, &texture);
glbmp_FreeBitmap(&bitmap);


glutSwapBuffers();


}


void TimerFunction(int value)
{

glutTimerFunc(1, TimerFunction, 1);

glutPostRedisplay();
}


void SpecialKeys(int key, int x, int y)
{
if (key == GLUT_KEY_RIGHT)
s = s - .015;

if (key == GLUT_KEY_LEFT)
s = s + .015;

if (key == GLUT_KEY_UP)
a = a + .015;

if (key == GLUT_KEY_DOWN)
a = a - .015;


glutPostRedisplay();
}


int main(int argc, char *argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH | GLUT_MULTISAMPLE);
glutInitWindowSize(1024, 768);
glutCreateWindow("STONES OF");
glutDisplayFunc(RenderScene);
glutSpecialFunc(SpecialKeys);
glutTimerFunc(1, TimerFunction, 1);
init();

glutMainLoop();

return 0;
}

RigidBody
08-03-2006, 03:34 PM
glEnable(GL_TEXTURE_3D); could be the problem.

ahem... and glTexCoord3f, too. what you need is

glEnable(GL_TEXTURE_2D);
glTexImage2D(...);
glTexCoord2f(...);

zadeh79
08-03-2006, 03:47 PM
I already tried changing that to glEnable(GL_TEXTURE_2d) and it DID NOT STOP FLICKERING.

RigidBody
08-03-2006, 03:49 PM
YOU ARE A BIT FRUSTRATED, AREN'T YOU?????

maybe you should take into consideration to clear the color and depth buffer.

zadeh79
08-03-2006, 03:53 PM
glEnable(GL_TEXTURE_2D);
glTexImage2D(...);
glTexCoord2f(...);

I tried all of this and for some reason it didn't stop flickering..

......... I HAVE A NEWER INtel MOTHERBOARD WITH ONBOARD VIDEO. I'M WONDERiNG IF THAT COULD BE PART OF THE PROBLEM.

RigidBody
08-03-2006, 04:03 PM
does "all of this" include clearing the depth buffer?

btw: it's not a good idea to load and destroy the bitmap each time the scene is redrawn. a better way is to load the bitmap and use glTexImage2D once, right after you've made the gl context current.

zadeh79
08-03-2006, 05:42 PM
ALL RIGHT, THE FLICKERING WENT AWAY. THNX.