Skip to main content
GameDev.net gamedev.net
🔒 Locked

GL mess

Started by Kaze Feb 23, 2005 at 11:38 PM 9 replies 1.9k views
Original Post
Kaze
Kaze
i havent been using gl that long but have got a program running but there are a few problems the first texturer i draw is always messed up and (the smilly guy and the wall are on the same level) here it looks fine at first but as i move my character some polygonnes dont draw for a frame causing a blinking effect and the depth buffer desent work i can post some code if someone gives me a hint at where the problem might be
CRACK123
CRACK123
Hi,

First thing I would check is glTexParametef calls and see if I have GL_CLAMP or GL_CLAMP_TO_EDGE set. You probably want GL_REPEAT. Regarding the blinking effect, it is hard to say - maybe you are not swapping the buffers or calling the function after swapping the buffers. This shouldn't be the case but nonetheless its good to make sure.

Posting the specific code probably could help.
The more applications I write, more I find out how less I know
Kaze
Kaze
theres a lot of code but if i had to take a blind guess how baout the init code
void EnableOpenGL (HWND hWnd, HDC *hDC, HGLRC *hRC){   // PIXELFORMATDESCRIPTOR pfd;    int iFormat;    /* get the device context (DC) */    *hDC = GetDC (hWnd);    /* set the pixel format for the DC */   // ZeroMemory (&pfd, sizeof (pfd));   static	PIXELFORMATDESCRIPTOR pfd=					// pfd Tells Windows How We Want Things To Be	{		sizeof(PIXELFORMATDESCRIPTOR),					// Size Of This Pixel Format Descriptor		1,								// Version Number		PFD_DRAW_TO_WINDOW |						// Format Must Support Window		PFD_SUPPORT_OPENGL |						// Format Must Support OpenGL		PFD_DOUBLEBUFFER,						// Must Support Double Buffering		PFD_TYPE_RGBA,							// Request An RGBA Format		32,								// Select Our Color Depth		0, 0, 0, 0, 0, 0,						// Color Bits Ignored		0,								// No Alpha Buffer		0,								// Shift Bit Ignored		0,								// No Accumulation Buffer		0, 0, 0, 0,							// Accumulation Bits Ignored		16,								// 16Bit Z-Buffer (Depth Buffer)		0,								// No Stencil Buffer		0,								// No Auxiliary Buffer		PFD_MAIN_PLANE,							// Main Drawing Layer		0,								// Reserved		0, 0, 0								// Layer Masks Ignored	};    iFormat = ChoosePixelFormat (*hDC, &pfd);    SetPixelFormat (*hDC, iFormat, &pfd);    /* create and enable the render context (RC) */    *hRC = wglCreateContext( *hDC );    wglMakeCurrent( *hDC, *hRC );     glMatrixMode(GL_PROJECTION);						// Select The Projection MatrixgluPerspective(45.0f,(GLfloat)700/(GLfloat)500,0.0f,100.0f);	glMatrixMode(GL_MODELVIEW);	glLoadIdentity(); 	glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);	//glScalef(1, -1, 1);   glEnable(GL_TEXTURE_2D);glEnable(GL_BLEND);	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);glClearDepth(1.0f);							// Depth Buffer SetupglEnable(GL_DEPTH_TEST);						// Enables Depth TestingglDepthFunc(GL_LEQUAL);	glShadeModel(GL_SMOOTH);glColor4f(1.0f,1.0f,1.0f,1.0f);glClearColor (1.0f, 0.0f, 0.0f, 1.0f);}


im not sure about glTexParametef, what am i supose to do with it(what does it do)
Ademan555
Ademan555
We need to see your texture registering code (wherever you call gluGen2DMipmaps() or glTexImage2D()) and/or your rendering code, especially where you draw your ground

-Dan
When General Patton died after World War 2 he went to the gates of Heaven to talk to St. Peter. The first thing he asked is if there were any Marines in heaven. St. Peter told him no, Marines are too rowdy for heaven. He then asked why Patton wanted to know. Patton told him he was sick of the Marines overshadowing the Army because they did more with less and were all hard-core sons of bitches. St. Peter reassured him there were no Marines so Patton went into Heaven. As he was checking out hi
Kaze
Kaze
Kaze
Kaze
im using code from the NeHe tutorials to load images, the ground and walls are bmp and the smilly guy a .tga. as for the ground rendering code it nothing very impressive


glBindTexture(GL_TEXTURE_2D, glgrass);
for (xrep=0;xrep<15;xrep++){
for (yrep=0;yrep<15;yrep++){
glBegin(GL_QUADS);

glVertex3f(xrep, yrep, 0.0f); glTexCoord2f(0.0f, 0.0f);
glVertex3f( xrep+1, yrep, 0.0f); glTexCoord2f(1.0f, 0.0f);
glVertex3f( xrep+1,yrep+1, 0.0f); glTexCoord2f(1.0f, 1.0f);
glVertex3f(xrep,yrep +1, 0.0f); glTexCoord2f(0.0f, 1.0f);
glEnd();

}}
Ademan555
Ademan555
When your using immediate mode (what your doing) any glVertex function will "send" the vertex, meaning that that vertex is "set in stone" and any glTexCoord glColor glNormal calls, will all affect the NEXT vertex, so try switching your glTexCoord2f() calls with your glVertex3f() calls so it looks like

edit: for the record glVertexAttrib calls with the index of 0 "send" the vertex as well

glTexCoord2f( . . . ); glVertex3f( . . . );

double edit: to clarify in most implementations i sincerely doubt that the vertex will be sent over on a glVertex call, but rather it will be stored in an array and on glEnd() the array is sent over (but i assume vendors have freedom in how this is implemented, but i beleive it would be faster the way i just outlined)

triple edit!!!!: move your glBegin( . . . )/glEnd() calls outside of the loop, should boost performance (for the reasons stated above)

hope that helps
-Dan
When General Patton died after World War 2 he went to the gates of Heaven to talk to St. Peter. The first thing he asked is if there were any Marines in heaven. St. Peter told him no, Marines are too rowdy for heaven. He then asked why Patton wanted to know. Patton told him he was sick of the Marines overshadowing the Army because they did more with less and were all hard-core sons of bitches. St. Peter reassured him there were no Marines so Patton went into Heaven. As he was checking out hi
python_regious
python_regious
The "polygons flickering" effect is most likely a depth buffer aliasing effect. Increase your depth buffer resolution ( it's 16 at the moment, which is shit, increase it to 24 ).
If at first you don't succeed, redefine success.
Ademan555
Ademan555
No i dont think its a depth buffer issue, first of all because it just looks like a vertex is missing, and second of all depth buffer problems tend to be parallell to the near and far clip planes if you know what im saying. Plus hes not that close or far for that matter

hope that helps
-Dan
When General Patton died after World War 2 he went to the gates of Heaven to talk to St. Peter. The first thing he asked is if there were any Marines in heaven. St. Peter told him no, Marines are too rowdy for heaven. He then asked why Patton wanted to know. Patton told him he was sick of the Marines overshadowing the Army because they did more with less and were all hard-core sons of bitches. St. Peter reassured him there were no Marines so Patton went into Heaven. As he was checking out hi
python_regious
python_regious
Quote:
Original post by Anonymous Poster
I got money on the blinking being cause his near plane is 0.0f


Oh dear god, I missed that. There's your problem right there. Increase it to 1.0 or something.
If at first you don't succeed, redefine success.
kburkhart84
kburkhart84
That's what it is. The equations GL uses aren't stable if you make that parameter 0. I had that problem about a year ago. Make the value 1 or 0.1 or something like that.


Topic Locked

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

Sign in to reply to this topic.