Game Development Community

Replacing skybox with 2D bitmap

by Drew Robson · in Torque Game Engine · 10/08/2007 (9:28 pm) · 7 replies

Hi all,

I'd like to replace the skybox with a 2D background image, like in Kingdom Elemental - http://www.chroniclogic.com/image/kingdomelemental/ke_5.jpg

I'm trying to create a similar effect - a small, rotatable area (with Advanced Camera) with a flat background. Before I dig into sky.cc, has anyone here done this before, or experienced with the sky code?

Thanks

#1
10/08/2007 (10:47 pm)
Quote:I'd like to replace the skybox with a 2D background image, like in Kingdom Elemental -
Why aren't you simply using a non-sky image?
#2
10/08/2007 (10:54 pm)
Because the background image I'd like is static, like a gui element. A non-sky image still moves with camera rotation, and is rendered across multiple skybox panes, with perspective/distance.
#3
10/09/2007 (1:04 am)
Just draw a big quad and render it at infinity.
#4
10/09/2007 (3:59 am)
My first attempt here

I'm on the right track now, thanks.
#5
10/09/2007 (4:07 am)
Cool. Although, couldn't you achieve the same effect by using the standard skybox, texturing all the faces with solid gray barring the front face?
#6
10/09/2007 (4:16 am)
I've done that in the past, but this time I've got an overhead orbit camera, so as the viewport rotates, I can see the other faces.
#7
10/09/2007 (6:33 am)
Success - a texture is rendered as a background to the mission, instead of a skybox. Look Here. Still have to test it with my own images, but it uses the skybox images system so very easy to change. This is a static background independent of camera viewport.

Let me know if there's anything wrong with the below code. [EDIT: It throws an error in Debug mode when trying to delete the terrain block in the mission editor. I recompiled in Release and deleted the terrain block from the mission file manually before running the game.]

In terrains/sky.cc -

In Sky::renderObject, replace:
glBegin(GL_TRIANGLE_FAN);
      glVertex3f(-1, -1, 1);
      glVertex3f(-1,  1, 1);
      glVertex3f( 1,  1, 1);
      glVertex3f( 1, -1, 1);
   glEnd();

With:
glEnable(GL_TEXTURE_2D);
	glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_REPLACE);
	glDepthMask(GL_FALSE);
	glBindTexture(GL_TEXTURE_2D,mSkyHandle[1].getGLName());
	glBegin(GL_QUADS);
		glTexCoord2f (0.0, 0.0);
		glVertex3f(-1, -1, 1);
		glTexCoord2f (1.0, 0.0);
		glVertex3f(-1, 1, 1);
		glTexCoord2f (1.0, 1.0);
		glVertex3f(1, 1, 1);
		glTexCoord2f (0.0, 1.0);
		glVertex3f(1, -1, 1);                 
	glEnd();

And make this change below:

// render(state);