Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 9 of 9

Thread: Object on the box

  1. #1
    Junior Member Newbie
    Join Date
    Dec 2010
    Posts
    10

    Object on the box

    Hi all!

    I drew a room by drawing a cube (funtion drawRoom()). this cube I didn't draw the front face in order to see the inner side. then I drew a smaller cube on the room (function drawcube())but it didn't appear. exactly they couldn't appear at the same time. when i removed drawRoom(), the cube appeared.

    Anyone can help me! how can I make them appear together.

  2. #2
    Super Moderator OpenGL Lord
    Join Date
    Dec 2003
    Location
    Grenoble - France
    Posts
    5,655

    Re: Object on the box

    Are you sure depth testing is enabled ?
    Are sure the small cube is inside the big one, and not behind ?

  3. #3
    Junior Member Newbie
    Join Date
    Dec 2010
    Posts
    10

    Re: Object on the box

    yeah I'm completely sure.
    and moreover, I have just drawn the front face of the room, it didn't appear as well even though I don't use GL_CULL_FACE

  4. #4
    Super Moderator OpenGL Lord
    Join Date
    Dec 2003
    Location
    Grenoble - France
    Posts
    5,655

    Re: Object on the box

    Does this change if you draw front face last ?
    Then you have no depth test. Do you require a depth buffer, when asking for a GL context ?

  5. #5
    Junior Member Newbie
    Join Date
    Dec 2010
    Posts
    10

    Re: Object on the box

    can you give me your email then i can show you more detail

  6. #6
    Junior Member Newbie
    Join Date
    Dec 2010
    Posts
    10

    Re: Object on the box

    if I draw the front face last, and disable depth test, the screen is full with the color that I set to front face, nothing i can see except for that color

  7. #7
    Super Moderator OpenGL Lord
    Join Date
    Dec 2003
    Location
    Grenoble - France
    Posts
    5,655

    Re: Object on the box

    You will have to provide your code, it sound you are doing several things wrong.


    Try to post the smallest compilable code that still show the problem, and do not forget to enclose it in
    Code :
    ...
    blocks

  8. #8
    Junior Member Newbie
    Join Date
    Dec 2010
    Posts
    10

    Re: Object on the box

    Code :
     
    // main.cpp
     
    #include <windows.h>
    #include "MyObject.h"
     
    #pragma comment (lib,"opengl32.lib")
    #pragma comment (lib,"glaux.lib")
    #pragma comment (lib,"glu32.lib")
    #pragma comment (lib,"glut32.lib")
     
     
    MyObject MO;
    COGLTexture *TextureList = new COGLTexture[2];
    void InitTextures(void)
    {
    	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
    	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
     
    	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
     
    	TextureList[0].LoadFromFile("floor.bmp");
    	TextureList[1].LoadFromFile("tex2.bmp");
     
    	glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
     
    }
     
     
    void Display(void)
    {
    	glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
    	glLoadIdentity();
     
    	glTranslatef(0.0f,0.0f,-35.0f);	
     
    	MO.drawRoom(TextureList);
    	glFlush();			//Finish rendering
    	glutSwapBuffers();
    }
     
    void Reshape(int x, int y)
    {
    	if (y == 0 || x == 0) return;  //Nothing is visible then, so return
    	//Set a new projection matrix
    	glMatrixMode(GL_PROJECTION);  
    	glLoadIdentity();
    	//Angle of view:40 degrees
    	//Near clipping plane distance: 0.5
    	//Far clipping plane distance: 20.0
    	gluPerspective(40.0,(GLdouble)x/(GLdouble)y,0.0,20.0);
    	glMatrixMode(GL_MODELVIEW);
    	glViewport(0,0,x,y);  //Use the whole window for rendering
    }
    int main (int argc, char **argv)
    {
    	//Initialize GLUT
    	glutInit(&amp;argc, argv);
    	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB |GLUT_DEPTH);
    	glutInitWindowSize(1500,900);
    	//Create a window with rendering context and everything else we need
    	glutCreateWindow("Intro");
    	glClearColor(0.0,0.0,0.0,0.0);
     
    	glEnable(GL_DEPTH_TEST);
    	InitTextures();
     
    	glutDisplayFunc(Display);
    	glutReshapeFunc(Reshape);
    	glutMainLoop();
     
    	return 0;
    }

    then here is MyObject.cpp
    Code :
    #include "MyObject.h"
    #include <iostream>
    #pragma comment (lib,"opengl32.lib")
    #pragma comment (lib,"glaux.lib")
    #pragma comment (lib,"glu32.lib")
    #pragma comment (lib,"glut32.lib")
     
    void MyObject::drawRoom(COGLTexture *TextureList)
    {
    		glEnable(GL_TEXTURE_2D);
    			// floor
    			TextureList[0].SetActive();
    			glBegin(GL_QUADS);					
    				glTexCoord2f(1.0,0.0); glVertex3f(-20.0f,-12.0f,-14.0f);				// Back Left
    				glTexCoord2f(1.0,1.0); glVertex3f(-20.0f,-12.0f, 14.0f);				// Front Left
    				glTexCoord2f(0.0,1.0); glVertex3f( 20.0f,-12.0f, 14.0f);				// Front Right
    				glTexCoord2f(0.0,0.0); glVertex3f( 20.0f,-12.0f,-14.0f);				// Back Right
    			glEnd();
     
    			// ceiling
    			TextureList[1].SetActive();
    			glBegin(GL_QUADS);
    				glTexCoord2f(1.0,1.0); glVertex3f(-20.0f, 12.0f, 14.0f);				// Front Left
    				glTexCoord2f(1.0,0.0); glVertex3f(-20.0f, 12.0f,-14.0f);				// Back Left
    				glTexCoord2f(0.0,0.0); glVertex3f( 20.0f, 12.0f,-14.0f);				// Back Right
    				glTexCoord2f(0.0,1.0); glVertex3f( 20.0f, 12.0f, 14.0f);				// Front Right
    			glEnd();
    		glDisable(GL_TEXTURE_2D);
     
    		glBegin(GL_QUADS);
    			glColor3f(1.0, 0.95, 0.5);
     
     
    			glVertex3f(-20.0f, 12.0f,-14.0f);				// Top Left
    			glVertex3f(-20.0f,-12.0f,-14.0f);				// Bottom Left
    			glVertex3f( 20.0f,-12.0f,-14.0f);				// Bottom Right
    			glVertex3f( 20.0f, 12.0f,-14.0f);				// Top Right
     
    			glColor3f(0.93,0.85,0.45);
     
    					// Top Left
     
    			glVertex3f(-20.0f, 12.0f, 14.0f);				// Top Front
    			glVertex3f(-20.0f,-12.0f, 14.0f);				// Bottom Front
    			glVertex3f(-20.0f,-12.0f,-14.0f);				// Bottom Back
    			glVertex3f(-20.0f, 12.0f,-14.0f);				// Top Back
     
    			glVertex3f( 20.0f, 12.0f,-14.0f);				// Top Back
    			glVertex3f( 20.0f,-12.0f,-14.0f);				// Bottom Back
    			glVertex3f( 20.0f,-12.0f, 14.0f);				// Bottom Front
    			glVertex3f( 20.0f, 12.0f, 14.0f);				// Top Front
     
    			glVertex3f( 20.0f, 12.0f, 14.0f);				// Top Right
    			glVertex3f( 20.0f,-12.0f, 14.0f);				// Bottom Right
    			glVertex3f(-20.0f,-12.0f, 14.0f);				// Bottom Left
    			glVertex3f(-20.0f, 12.0f, 14.0f);		
    		glEnd();
    // smaller face 
    		glBegin(GL_QUADS);
    			glColor3f(0.0,0.0,1.0);
    			glVertex3f(-10.0f, 6.0f,-7.0f);				// Top Left
    			glVertex3f(-10.0f,-6.0f,-7.0f);				// Bottom Left
    			glVertex3f( 10.0f,-6.0f,-7.0f);				// Bottom Right
    			glVertex3f( 10.0f, 6.0f,-7.0f);
    		glEnd();
     
    }

  9. #9
    Member Regular Contributor
    Join Date
    Mar 2003
    Location
    Los Angeles
    Posts
    386

    Re: Object on the box

    Your problems lie in the call to gluPerspective in your reshape function. The last 2 parameters are supposed to specify the distance from the camera to the front and back clipping planes. You set the front value to 0.0. If you read the documention you'll see that this value must always be positive (i.e. greater than zero, zero causes undefined results). Set it to 1.0 and run your code. You'll probably get a black screen. This is because your back clipping plane is set to 20.0, but all the vertices on the back face of your cube have been translated way beyond to 20 units (to -14 + -35 = -49). Your smaller quad has been translated to -42 (= -7 + -35). So none of your quad vertices are in the viewing volume. Simplest fix is to set the back clipping plane value to -50 (out of the viewing volume).

    Perhaps you thought that a rear clipping plane distance of 20 would be sufficient since the back wall of your room has vertices at -14? You must also remember that you translate the entire room by -35 in Z, which moves that back wall to Z = -49.
    Am I doing your homework for you?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •