Sky Box 'Box'

Started by
7 comments, last by ManicLamb 20 years, 1 month ago
Im creating a box for my skybox, but my box seems to look all messed up... its going to be a (x) -50 to 50 (y) by -50 to 50 by (z) 0 to 50 box... The code im using is. void SkyView::renderSky() { //glBindTexture(GL_TEXTURE_2D, 2004); glBegin(GL_TRIANGLE_STRIP); //Top face glColor3f(1.0f, 1.0f, 1.0f); glVertex3f(50.0f, 50.0f, 50.0f); glVertex3f(-50.0f, 50.0f, 50.0f); glVertex3f(-50.0f, 50.0f, -50.0f); glVertex3f(50.0f, 50.0f, -50.0f); //bottom face glVertex3f(50.0f, 0.0f, 50.0f); glVertex3f(-50.0f, 0.0f, 50.0f); glVertex3f(50.0f, 0.0f, -50.0f); glVertex3f(-50.0f, 0.0f, -50.0f); //Front face glColor3f(0.0f, 1.0f, 0.0f); glVertex3f(50.0f, 50.0f, -50.0f); glVertex3f(-50.0f, 50.0f, -50.0f); glVertex3f(50.0f, 0.0f, -50.0f); glVertex3f(-50.0f, 0.0f, -50.0f); //Back face glColor3f(1.0f, 0.0f, 0.0f); glVertex3f(50.0f, 50.0f, 50.0f); glVertex3f(-50.0f, 50.0f, 50.0f); glVertex3f(-50.0f, 0.0f, 50.0f); glVertex3f(50.0f, 0.0f, 50.0f); //Left face glVertex3f(-50.0f, 50.0f, 50.0f); glVertex3f(-50.0f, 50.0f, -50.0f); glVertex3f(-50.0f, 0.0f, -50.0f); glVertex3f(-50.0f, 0.0f, 50.0f); //Right face glVertex3f(50.0f, 50.0f, 50.0f); glVertex3f(50.0f, 50.0f, -50.0f); glVertex3f(50.0f, 0.0f, -50.0f); glVertex3f(50.0f, 0.0f, 50.0f); glEnd(); Any ideas? thank you
Advertisement
FIRSTLY, why is the box so big? a two-unit box shows up exactly the same. Did you forget to disable depth testing? How exactly is it ''messed up''?
My fellow Americans I have just signed legislation that outlaws Russia forever. Bombing will commence in five minutes.
even before FIRSTLY!
please use these tags: [source]    

[/source]

...when posting code. Thank you!

Beginner in Game Development?  Read here. And read here.

 

Why are you using a triangle strip if they''re quads?

Love means nothing to a tennis player

My nothing-to-write-home-about OpenGL webpage. (please pardon the popups!)

how does it look exactly? all white I would be guessing, also... you aren''t specifying any texture coordinates.
The fault you made is that you used tri strips.
They depend on the last two written vertexes and therefore will mess things up big time, use quads.
So, to help you out a little, here is the skybox rendering function i use.
cam.p cam.h cam.b are xyz camera rotations in degrees, replace as needed.
unsigned int skyboxtex[6]; is the texture reference, replace if needed.
void draw::rendersky(void){	glDisable(GL_CULL_FACE);		glPushMatrix();	glDisable(GL_DEPTH_TEST);	glDisable(GL_LIGHTING);	glLoadIdentity();					// Reset The Current Modelview Matrix	glRotated(-cam.p,1,0,0);	glRotated(-cam.h,0,1,0);	glRotated(-cam.b,0,0,1);	glEnable( GL_TEXTURE_2D );					glBindTexture( GL_TEXTURE_2D, skyboxtex[1]);  //sets the current skin		glBegin(GL_QUADS);									// Begin Drawing Quads		// Floor		glNormal3f(0.0f, 1.0f, 0.0f);					// Normal Pointing Up		glTexCoord2f(1,0);		glVertex3f(-10.0f,-10.0f,-10.0f);				// Back Left		glTexCoord2f(1,1);		glVertex3f(-10.0f,-10.0f, 10.0f);				// Front Left		glTexCoord2f(0,1);		glVertex3f( 10.0f,-10.0f, 10.0f);				// Front Right		glTexCoord2f(0,0);		glVertex3f( 10.0f,-10.0f,-10.0f);				// Back Right		glEnd();		glBindTexture( GL_TEXTURE_2D, skyboxtex[0]);  //sets the current skin		glBegin(GL_QUADS);		// Ceiling		glNormal3f(0.0f,-1.0f, 0.0f);					// Normal Point Down		glTexCoord2f(1,0);		glVertex3f(-10.0f, 10.0f, 10.0f);				// Front Left		glTexCoord2f(1,1);		glVertex3f(-10.0f, 10.0f,-10.0f);				// Back Left		glTexCoord2f(0,1);		glVertex3f( 10.0f, 10.0f,-10.0f);				// Back Right		glTexCoord2f(0,0);		glVertex3f( 10.0f, 10.0f, 10.0f);				// Front Right		glEnd();		glBindTexture( GL_TEXTURE_2D, skyboxtex[2]);  //sets the current skin		glBegin(GL_QUADS);		// Front Wall		glNormal3f(0.0f, 0.0f, 1.0f);					// Normal Pointing Away From Viewer		glTexCoord2f(0,1);		glVertex3f(-10.0f, 10.0f,-10.0f);				// Top Left		glTexCoord2f(0,0);		glVertex3f(-10.0f,-10.0f,-10.0f);				// Bottom Left		glTexCoord2f(1,0);		glVertex3f( 10.0f,-10.0f,-10.0f);				// Bottom Right		glTexCoord2f(1,1);		glVertex3f( 10.0f, 10.0f,-10.0f);				// Top Right		glEnd();		glBindTexture( GL_TEXTURE_2D, skyboxtex[3]);  //sets the current skin		glBegin(GL_QUADS);		// Back Wall		glNormal3f(0.0f, 0.0f,-1.0f);					// Normal Pointing Towards Viewer		glTexCoord2f(0,1);		glVertex3f( 10.0f, 10.0f, 10.0f);				// Top Right		glTexCoord2f(0,0);		glVertex3f( 10.0f,-10.0f, 10.0f);				// Bottom Right		glTexCoord2f(1,0);		glVertex3f(-10.0f,-10.0f, 10.0f);				// Bottom Left		glTexCoord2f(1,1);		glVertex3f(-10.0f, 10.0f, 10.0f);				// Top Left		glEnd();		glBindTexture( GL_TEXTURE_2D, skyboxtex[4]);  //sets the current skin		glBegin(GL_QUADS);		// Left Wall		glNormal3f(1.0f, 0.0f, 0.0f);					// Normal Pointing Right		glTexCoord2f(0,1);		glVertex3f(-10.0f, 10.0f, 10.0f);				// Top Front		glTexCoord2f(0,0);		glVertex3f(-10.0f,-10.0f, 10.0f);				// Bottom Front		glTexCoord2f(1,0);		glVertex3f(-10.0f,-10.0f,-10.0f);				// Bottom Back		glTexCoord2f(1,1);		glVertex3f(-10.0f, 10.0f,-10.0f);				// Top Back		glEnd();		glBindTexture( GL_TEXTURE_2D, skyboxtex[5]);  //sets the current skin		glBegin(GL_QUADS);		// Right Wall		glNormal3f(-1.0f, 0.0f, 0.0f);					// Normal Pointing Left		glTexCoord2f(0,1);		glVertex3f( 10.0f, 10.0f,-10.0f);				// Top Back		glTexCoord2f(0,0);		glVertex3f( 10.0f,-10.0f,-10.0f);				// Bottom Back		glTexCoord2f(1,0);		glVertex3f( 10.0f,-10.0f, 10.0f);				// Bottom Front		glTexCoord2f(01,1);		glVertex3f( 10.0f, 10.0f, 10.0f);				// Top Front		glEnd();											// Done Drawing Quads	glPopMatrix();	glEnable(GL_DEPTH_TEST);	glEnable(GL_CULL_FACE);	}

the skybox textures should be loaded with these setting's.
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP);


---------------------------------
For an overdose of l33tness, flashbang.nu

[edited by - lc_overlord on March 5, 2004 6:02:54 PM]
here is co-ords for a skybox using triangles


//Format X,Y,Z ,U,V
//Where to tris make up one quad it is the same side -- duh
// Skybox
// Front
TEXTURE=6
-40.0 -40.0 -40.0 0.0 0.0
-40.0 40.0 -40.0 0.0 1.0
40.0 40.0 -40.0 1.0 1.0
TEXTURE=6
40.0 40.0 -40.0 1.0 1.0
40.0 -40.0 -40.0 1.0 0.0
-40.0 -40.0 -40.0 0.0 0.0
// Right
TEXTURE=9
40.0 -40.0 -40.0 0.0 0.0
40.0 40.0 -40.0 0.0 1.0
40.0 40.0 40.0 1.0 1.0
TEXTURE=9
40.0 40.0 40.0 1.0 1.0
40.0 -40.0 40.0 1.0 0.0
40.0 -40.0 -40.0 0.0 0.0
// Back
TEXTURE=8
-40.0 -40.0 40.0 1.0 0.0
-40.0 40.0 40.0 1.0 1.0
40.0 40.0 40.0 0.0 1.0
TEXTURE=8
40.0 40.0 40.0 0.0 1.0
40.0 -40.0 40.0 0.0 0.0
-40.0 -40.0 40.0 1.0 0.0
// Left
TEXTURE=7
-40.0 -40.0 -40.0 1.0 0.0
-40.0 40.0 -40.0 1.0 1.0
-40.0 40.0 40.0 0.0 1.0
TEXTURE=7
-40.0 40.0 40.0 0.0 1.0
-40.0 -40.0 40.0 0.0 0.0
-40.0 -40.0 -40.0 1.0 0.0
// Bottom
TEXTURE=11
-40.0 -40.0 -40.0 0.0 0.0
40.0 -40.0 -40.0 0.0 1.0
40.0 -40.0 40.0 1.0 1.0
TEXTURE=11
40.0 -40.0 40.0 1.0 1.0
-40.0 -40.0 40.0 1.0 0.0
-40.0 -40.0 -40.0 0.0 0.0
// Top
TEXTURE=10
-40.0 40.0 -40.0 0.0 1.0
40.0 40.0 -40.0 0.0 0.0
40.0 40.0 40.0 1.0 0.0
TEXTURE=10
40.0 40.0 40.0 1.0 0.0
-40.0 40.0 40.0 1.0 1.0
-40.0 40.0 -40.0 0.0 1.0
Spy
Hi, yeah sorry i didnt realise i used GL_TRIANGLE_STRIP for it.. I quickly changed it too polygon, but this didnt make much difference. The box was ok for the front face and left face but it had diaganols running all over on the other faces. Thanks for that code im gonna give it go now!

Ill keep you posted on how it goes!
Thanks
Doh I''m an Idiot! Yeah it was a case of just changin it too GL_QUADS, i was thinking the GL_POLYGON was the way you did it... anyways thanks again!

This topic is closed to new replies.

Advertisement