Sign in to follow this  

[Beginner] Skybox problems

This topic is 2849 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi there, Got 2 problems at the moment: 1. I have a 2D skybox (disabled depth test) in which I want to move a cube in third person view. The cube itself needs to move in the direction I'm looking at (but only in Y direction), so you can't move up down (XZ plane), only in the YZ plane. The problem I'm having is making the skybox rotate when rotating the cube, atm only the cube is rotating (I know this because I drew another static cube and I can move around it) but the skybox is not. I have no idea if it's possible to use a third person camera view and a 2D skybox. But I would find it odd if it wouldn't be. 2. I've used GL_CLAMP_EDGE to make sure the skybox is rendered without seams, but now I can see white seams in between textures, it looks like they are overlapping and blending in some way. I have no idea on how to get rid of them. Code for problem 1:
void drawScene(){
	//Clear information from last draw
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	
	// Change matrixmode back to modelview
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();

	// Enables/disables wireframe
	if(wireFrame){
		glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
	}
	else{
		glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
	}

	////Draws the 2D skybox
	glEnable(GL_TEXTURE_2D);
	glDisable(GL_DEPTH_TEST);
		// distance from model
	glTranslated(0,0,-zoom);
		//Looking up down the model (without moving it, this will only change the viewing angle)
	glRotatef(yrot,1.0f,0.0f,0.0f);
	drawbox();
	glEnable(GL_DEPTH_TEST);
	glDisable(GL_TEXTURE_2D);
    
	// Temp model (simple cube)
	glutSolidCube(1);
	glRotatef(xrot,0.0f,1.0f,0.0f);
	glTranslated(xpos,0.0f,zpos);
	
	// Static cube to move round
	glPushMatrix();
	glTranslatef(0,0,-10.0f);
	glutSolidCube(1);
	glPopMatrix();

	// Print fps on screen (Loadidentity and changing to modelview is also done in these function calls)
	if(showFps==true){
		glEnable2D();
		//glColor3f(0,255,0);
		output(10,10,strFrameRate);
		glDisable2D();
	}
	//Send information to screen
	glutSwapBuffers();

	//calculate fps
	fps();
}
The drawbox fucntion is just a number of GL_BEGIN calls that draw the sides with textures bound to them. I really try to find the solution myself before bothering you guys, but I4m really stuck at the moment. Best regards Yannick

Share this post


Link to post
Share on other sites
Why do you have to translate the skybox at all?
Just apply the rotations of the camera.

Zooming is better to do by altering the projection matrix (smaller ortho, or smaller AOV for perspective).

Zooming with translation will cause you very serious problems later. (Sky is zooming in a different way that the objects, you will be totally lost when you want to apply other transformations to the objects, etc.).

I guess you meant GL_CLAMP_TO_EDGE.
Are you sure your textures are okay (I mean the images themselves)?

Do you have separate images for the sides of the cube, ore only one atlas texture?
If so, clamping to edge won't help you with the edges, that are not the edges of the atlas texture.

Share this post


Link to post
Share on other sites
Quote:
Original post by szecs
Why do you have to translate the skybox at all?
Just apply the rotations of the camera.

Zooming is better to do by altering the projection matrix (smaller ortho, or smaller AOV for perspective).

Zooming with translation will cause you very serious problems later. (Sky is zooming in a different way that the objects, you will be totally lost when you want to apply other transformations to the objects, etc.).

I guess you meant GL_CLAMP_TO_EDGE.
Are you sure your textures are okay (I mean the images themselves)?

Do you have separate images for the sides of the cube, ore only one atlas texture?
If so, clamping to edge won't help you with the edges, that are not the edges of the atlas texture.


1.
I need to make sure that the box moves in the XY plane and only the viewing angle changes with the YZ plane. That's why my glrotate (yrot ..) is called before the drawbox() and my glrotate(xrot,...) is called after drawing my model. This way the only thing that doesn't work is the skybox rotating (so now it looks like I don't move at all when I actually do).

The zooming is only to change the distance from the model (like you would do in a third person game), but do you mean I have to set the matrixmode to projection, do my zoom, change back to modelview to draw the rest?
Could you perhaps give me an example on how you would do it when looking at my code? :)

2.
Yeah I meant GL_CLAMP_TO_EDGE, sry about that :). I have 5 different bmp's:
front,back,left,right,top. Downloaded them from http://www.3delyvisions.com/skf1.htm and changed them so they are 512x512.

*edit*
The biggest problem I am having now is not knowing if my code is coded like it should be. When I get something to work I automatically think that's the good way to code it, but one can never be sure :). Really frustrating to say the least :p.

Share this post


Link to post
Share on other sites
Here's one solution:
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
Apply_Projection(real_zoom);//but you don't to use it yet
glMatrixMode(GL_MODELVIEW);

glLoadIdentity();
Apply_rotation_of_camera();
glDisable(GL_DEPTH_TEST);
DrawSkyBox();
glLoadIdentity();
ApplyWhateverCameraTransformation_including_the_zoom_you_use();//which is not
//zoom at all btw, just distance from the camera
glEnable(GL_DEPTH_TEST);
glClear(GL_DEPTH_BUFFER_BIT);
DrawScene();
I think you have misconceptions about zooming, and I hope I haven't caused more confusion.

Share this post


Link to post
Share on other sites
Quote:
Original post by szecs
Here's one solution:
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
Apply_Projection(real_zoom);//but you don't to use it yet
glMatrixMode(GL_MODELVIEW);

glLoadIdentity();
Apply_rotation_of_camera();
glDisable(GL_DEPTH_TEST);
DrawSkyBox();
glLoadIdentity();
ApplyWhateverCameraTransformation_including_the_zoom_you_use();//which is not
//zoom at all btw, just distance from the camera
glEnable(GL_DEPTH_TEST);
glClear(GL_DEPTH_BUFFER_BIT);
DrawScene();
I think you have misconceptions about zooming, and I hope I haven't caused more confusion.


No I'm very grateful you're trying to help me out, I should be more careful with the names I use for certain things. What I meant with zooming is indeed the distance from the camera to my model.

Going to try out your code example, I'll let you know if it does what I want it to do (because explaining what I need is not that easy :D).

You can see I'm still trying to learn OpenGL and its lingo :p. Just got me the superbible and reading through it.

Best regards
Yannick

Share this post


Link to post
Share on other sites
Alright, got it to work! Could somebody please check my comments to see if I understand what's going on. This would help me a lot in the long streak :).


//Clear information from last draw
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

// Enables/disables wireframe
if(wireFrame){
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
}
else{
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
}
////Draws the 2D skybox
glPushMatrix();
glEnable(GL_TEXTURE_2D);
glDisable(GL_DEPTH_TEST);
// Rotating the scene (in this case only the skybox because the matrix gets push-popped)
glRotatef(yrot,1.0f,0.0f,0.0f);
glRotatef(xrot,0,1,0);
drawbox();
glEnable(GL_DEPTH_TEST);
glDisable(GL_TEXTURE_2D);
glClear(GL_DEPTH_BUFFER_BIT);
glPopMatrix();

//// Translating and rotating the model
// Zoom function to change distance from the camera to the model
glTranslatef(0,0,-zoom);
// Rotating the scene so it looks like you're rotating the view in 3d person
glRotatef(yrot,1,0,0);
glutSolidCube(1);
//rotating the scene without rotating the cube, looks like you are changing the direction of the cube
glRotatef(xrot,0,1,0);
glTranslatef(xpos,0,zpos);

//Static cube to move round
glPushMatrix();
//translating the camera 10 pixels "into" the screen
glTranslatef(0,0,-10.0f);
glutSolidCube(1);
glPopMatrix();

...


Thanks in advance!
Yannick

Share this post


Link to post
Share on other sites

This topic is 2849 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this