PDA

View Full Version : Making a room



nergal
10-27-2002, 02:16 AM
I want to make a simple room with textures.
How to? I made a cube with six planes. But I want to have the camera inside the cube so it looks like a room. One more question. How to set texture repetition, cause the texture is just stretched now, so it looks wrong.
And another problem is when I rotate the cube or make it pretty big then some sides dissapear suddenly. How to demand opengl how deep in the screen it should render, I think it have something to do with that.
This is the code I made for the cube:
void createRoom(float langd, float hojd, float bredd, GLuint texture_id)
{
glPushMatrix();
glBindTexture ( GL_TEXTURE_2D, texture_id);
glBegin(GL_QUADS);
/*front*/
glTexCoord2f(1.0f, 0.0f);
glVertex3f(0.0f, 0.0f, 0.0f); //bottom left
glTexCoord2f(1.0f, 1.0f);
glVertex3f(langd, 0.0f, 0.0f); //bottom right
glTexCoord2f(0.0f, 1.0f);
glVertex3f(langd, hojd, 0.0f); // top right
glTexCoord2f(0.0f, 0.0f);
glVertex3f(0.0f, hojd ,0.0f); //top left

/*Back*/
glTexCoord2f(0.0f, 0.0f);
glVertex3f(langd, 0.0f, bredd); //bottom right
glTexCoord2f(1.0f, 0.0f);
glVertex3f(langd, hojd, bredd); //top right
glTexCoord2f(1.0f, 1.0f);
glVertex3f(0.0f, hojd, bredd); // top left
glTexCoord2f(0.0f, 1.0f);
glVertex3f(0.0f, 0.0f, bredd); //bottom left

/*Top*/
glTexCoord2f(0.0f, 0.0f);
glVertex3f(0.0f, hojd, 0.0f); //top left
glTexCoord2f(1.0f, 0.0f);
glVertex3f(0.0f, hojd, bredd); //bottom left
glTexCoord2f(1.0f, 1.0f);
glVertex3f(langd, hojd,bredd); //bottom right
glTexCoord2f(0.0f, 1.0f);
glVertex3f(langd, hojd, 0.0f); //top right

/*botten*/
glTexCoord2f(1.0f, 0.0f);
glVertex3f(langd, 0.0f, 0.0f); //top right
glTexCoord2f(1.0f, 1.0f);
glVertex3f(0.0f, 0.0f, 0.0f); //top left
glTexCoord2f(0.0f, 1.0f);
glVertex3f(0.0f, 0.0f, bredd); //bottom left
glTexCoord2f(0.0f, 0.0f);
glVertex3f(langd, 0.0f, bredd); //bottom right

/*Right*/
glTexCoord2f(1.0f, 0.0f);
glVertex3f(langd, 0.0f, bredd); // bottom right
glTexCoord2f(1.0f, 1.0f);
glVertex3f(langd, hojd, bredd); // top right
glTexCoord2f(0.0f, 1.0f);
glVertex3f(langd, hojd, 0.0f); // top left
glTexCoord2f(0.0f, 0.0f);
glVertex3f(langd, 0.0f, 0.0f); // bottom left

/*Left*/
glTexCoord2f(0.0f, 0.0f);
glVertex3f(0.0f, 0.0f, 0.0f); //bottom left
glTexCoord2f(1.0f, 0.0f);
glVertex3f(0.0f, 0.0f, bredd); //bottom right
glTexCoord2f(1.0f, 1.0f);
glVertex3f(0.0f, hojd, bredd); //top right
glTexCoord2f(0.0f, 1.0f);
glVertex3f(0.0f, hojd, 0.0f); //top left

glEnd();
glDisable(GL_TEXTURE_2D);
glPopMatrix();
}



[This message has been edited by nergal (edited 10-27-2002).]

Leyder Dylan
10-27-2002, 02:41 AM
Your sides dissapear suddenly ? Mmh, just change your "gluPerspective", the 2 lasts params. Set the first one to 0.1 and the last one set with a higher value than your cube size.

Here's the function :

GLvoid ReSizeGLScene(GLsizei width, GLsizei height) // Resize And Initialize The GL Window
{

// Prevent A Divide By Zero By making Height Equal One
if (height == 0)
height = 1;

// Reset The Current Viewport
glViewport(0,0,width,height);

// Select The Projection Matrix
glMatrixMode(GL_PROJECTION);

// Reset The Projection Matrix
glLoadIdentity();

// Calculate The Aspect Ratio Of The Window
gluPerspective(45.0f,(GLfloat) width / (GLfloat) height, 0.1f, 5000.0f);

// Select The Modelview Matrix
glMatrixMode(GL_MODELVIEW);

// Reset The Modelview Matrix
glLoadIdentity();

}


Next, we need to see you texture loading function.

Overmind
10-27-2002, 07:32 AM
If you want to repeat the textures you have to specify higher texture coordinates. For example, when you want your textures to repeat five times, you have to use 5.0 as texture coordinates.

Also you have to set GL_TEXTURE_WRAP_S and GL_TEXTURE_WRAP_T to GL_REPEAT when loading the texture.