Advertisement

skybox (crazy stuff goin on)

Started by April 12, 2001 10:05 PM
7 comments, last by deadbeat 23 years, 7 months ago
I've been reading the forums for things related to skybox's and am still missing a few important pieces. I read that I should disable the depth buffer to make the skybox big and all surrounding (for lack of a better description that will have to work). I'm just not sure the exact code for that. Also I would need to reaarange the way my quad is drawn right (flip from front to back)? So that the textures are facing the inside of the cube? glBindTexture(GL_TEXTURE_2D, texture[0]); glBegin(GL_QUADS); glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f); glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 1.0f); glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, 1.0f); glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, 1.0f); glEnd(); this is an example of one side of my cube. thanks in advance. -db jeff@hype52.com www.pricezapper.com Edited by - deadbeat on April 13, 2001 3:21:12 AM
-dbjeff@hype52.comwww.pricezapper.com
That''s one method of doing it...
To disable the depth testing just disable GL_DEPTH_TEST.
And yes, the vertex order would have to be reversed!
------------------------------Piggies, I need more piggies![pig][pig][pig][pig][pig][pig]------------------------------Do not invoke the wrath of the Irken elite. [flaming]
Advertisement
okie it works. but now it's being weird (it was doing this before).
pieces are getting cut off? its weird..

pic showing what i mean

my draw function code (based on a slightly modified nehes new base + stolen stuff from lesson 10/23):
    	glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);	// Clear Screen And Depth Buffer	glLoadIdentity ();										// Reset The Modelview Matrix	//GLfloat x_m, y_m, z_m, u_m, v_m;						// Floating Point For Temp X, Y, Z, U And V Vertices	GLfloat xtrans = -xpos;									// Used For Player Translation On The X Axis	GLfloat ztrans = -zpos;									// Used For Player Translation On The Z Axis	GLfloat ytrans = -walkbias-0.25f;						// Used For Bouncing Motion Up And Down	GLfloat sceneroty = 360.0f - yrot;						// 360 Degree Angle For Player Direction//	int numtriangles;										// Integer To Hold The Number Of Triangles	glRotatef(lookupdown,1.0f,0,0);							// Rotate Up And Down To Look Up And Down	glRotatef(sceneroty,0,1.0f,0);							// Rotate Depending On Direction Player Is Facing		glTranslatef(xtrans, ytrans, ztrans);					// Translate The Scene Based On Player Position	// Front Face	glDisable(GL_DEPTH_TEST);										// Enable Depth Testing	glEnable(GL_CLAMP);	glBindTexture(GL_TEXTURE_2D, texture[0]);						// Bind texture	glBegin(GL_QUADS);		glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,  1.0f,  1.0f);	// Top Left Of The Texture and Quad		glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,  1.0f,  1.0f);	// Top Right Of The Texture and Quad		glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f,  1.0f);	// Bottom Right Of The Texture and Quad		glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f,  1.0f);	// Bottom Left Of The Texture and Quad	glEnd();	// Back Face	glBindTexture(GL_TEXTURE_2D, texture[1]);						// Bind texture	glBegin(GL_QUADS);		glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f);	// Bottom Left Of The Texture and Quad		glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f,  1.0f, -1.0f);	// Top Left Of The Texture and Quad		glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f,  1.0f, -1.0f);	// Top Right Of The Texture and Quad		glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f);	// Bottom Right Of The Texture and Quad	glEnd();	// Top Face	glBindTexture(GL_TEXTURE_2D, texture[2]);					// Bind texture	glBegin(GL_QUADS);		glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f,  1.0f, -1.0f);	// Top Left Of The Texture and Quad		glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f,  1.0f,  1.0f);	// Bottom Left Of The Texture and Quad		glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f,  1.0f,  1.0f);	// Bottom Right Of The Texture and Quad		glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f,  1.0f, -1.0f);	// Top Right Of The Texture and Quad	glEnd();	// Bottom Face	glBindTexture(GL_TEXTURE_2D, texture[3]);					// Bind texture	glBegin(GL_QUADS);		glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f,  1.0f);	// Bottom Right Of The Texture and Quad		glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f,  1.0f);	// Bottom Left Of The Texture and Quad		glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, -1.0f, -1.0f);	// Top Left Of The Texture and Quad		glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, -1.0f, -1.0f);	// Top Right Of The Texture and Quad	glEnd();	// Left Face	glBindTexture(GL_TEXTURE_2D, texture[4]);					// Bind texture	glBegin(GL_QUADS);		glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,  1.0f, -1.0f);	// Top Left Of The Texture and Quad		glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f,  1.0f,  1.0f);	// Top Right Of The Texture and Quad		glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f,  1.0f);	// Bottom Right Of The Texture and Quad		glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f);	// Bottom Left Of The Texture and Quad	glEnd();	// Right face	glBindTexture(GL_TEXTURE_2D, texture[5]);					// Bind texture	glBegin(GL_QUADS);		glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f,  1.0f);	// Bottom Left Of The Texture and Quad		glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f,  1.0f,  1.0f);	// Top Left Of The Texture and Quad		glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,  1.0f, -1.0f);	// Top Right Of The Texture and Quad		glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f);	// Bottom Right Of The Texture and Quad	glEnd();	glDisable(GL_CLAMP);	glEnable(GL_DEPTH_TEST);											// Enable Depth Testing}    


on a side note what does glFlush() do?

edit: sorry code space is so big and ugly.

-db
jeff@hype52.com
www.pricezapper.com

Edited by - deadbeat on April 13, 2001 3:24:20 AM
-dbjeff@hype52.comwww.pricezapper.com
the vertices have to be in the near<->far depth buffer range

make your near buffer 0.1 and far 100000 (then slowly bringing them closer until you dont clip objects in your scene


http://members.xoom.com/myBollux
Try removing the enable/disable of GL_CLAMP I don''t think you need that in there anyway.

glFlush tells the driver to execute all commands it''s got in it''s various buffers. i.e. just because you ran through a loop to draw a series of quads dosn''t neccisarryly mean that they''ve already been drawn. glFlush tells the driver to execute all commands before continuing.
------------------------------Piggies, I need more piggies![pig][pig][pig][pig][pig][pig]------------------------------Do not invoke the wrath of the Irken elite. [flaming]
thank you both for your responses. zedzeek could you go into a little bit more detail, *please*? its not gl_clamp......

source code -if anyone wants to look (its 800k cuz of skybox images)

any more suggestions greatly appreciated.

-db
jeff@hype52.com
www.pricezapper.com
-dbjeff@hype52.comwww.pricezapper.com
Advertisement
This has noting to do with your clipping problem, but as for clamping, set the wrapping parameter of your skybox texture objects to GL_CLAMP, that's the correct way to do it :

//should ideally be done at texture object creation time
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);

At least that's the way I'm doing it.

Edited by - /*Vince*/ on April 14, 2001 3:53:15 PM
make your near clip plane smaller like so.

void ReshapeGL (int width, int height)
{

gluPerspective (45.0f, (GLfloat)(width)/(GLfloat)(height), 0.1f, 100.0f);

}

http://members.xoom.com/myBollux
thank you!!!

-db
jeff@hype52.com
www.pricezapper.com
-dbjeff@hype52.comwww.pricezapper.com

This topic is closed to new replies.

Advertisement