Thread: geometry won't display!?

  1. #1
    The Right Honourable psychopath's Avatar
    Join Date
    Mar 2004
    Location
    Where circles begin.
    Posts
    1,071

    Question geometry won't display!?

    I have a function that handles all the code for creating a cube.
    I want it so when i click a dialog box button, it calls the fuction for creating a cube. I have done this but i don't see the cube!?....i think somthing is happening tho, because when i press the button, my grid changes color (for some reason it does this when there is textured geometry present as well as the grid)...so does this mean that its working, but just not displaying?

    Code:
    BOOL CALLBACK InsertBrushDlgProc(HWND hWnd, UINT Message, WPARAM wparam, LPARAM lparam)
    {
        switch(Message)
        {
            case WM_INITDIALOG:
    
            return TRUE;
            case WM_COMMAND:
                switch(LOWORD(wparam))
                {
                case IDSCUBE:					
    				glPushMatrix();
    				SolidCube(1.0, 1.0, 1.0, 0.0, 0.0, 0.0,
    					FALSE,
    					0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0,
    					0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0,
    					0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0);				
    				SwapBuffers( hDC );
    				
    				EndDialog(hWnd, IDCANCEL);
    				break;
    			
    			case IDCANCEL:
    				EndDialog(hWnd, IDCANCEL);
                    break;
                }
            break;
            default:
                return FALSE;
        }
        return TRUE;
    }
    any help will be very much appreciated!!

    -psychopath
    M.Eng Computer Engineering Candidate
    B.Sc Computer Science

    Robotics and graphics enthusiast.

  2. #2
    Registered User
    Join Date
    Aug 2003
    Posts
    1,218
    Are you translating the cube in to the scene anything? Maybe it displays but it is so close that it takes up the whole screen. Also is the color the grid changes to when you press the button the same as what your cube would be?

  3. #3
    The Right Honourable psychopath's Avatar
    Join Date
    Mar 2004
    Location
    Where circles begin.
    Posts
    1,071
    >>Are you translating the cube in to the scene anything? Maybe it displays but it is so close that it takes up the whole screen.<<

    nope

    >>Also is the color the grid changes to when you press the button the same as what your cube would be?<<

    yup

    -psychopath
    M.Eng Computer Engineering Candidate
    B.Sc Computer Science

    Robotics and graphics enthusiast.

  4. #4
    Registered User
    Join Date
    Aug 2003
    Posts
    1,218
    >>Are you translating the cube in to the scene anything? Maybe it displays but it is so close that it takes up the whole screen.<<

    >>nope

    Nope as in no I am not translating it or nope as in no it doesnt display?? Because if you are not translating it, give it a shot to translate it in to the scene some. Since the color of the grid changes to the same color as what your cube it a good guess is that the cube is being drawn too close the the screen and therefore taking up the whole screen.

  5. #5
    The Right Honourable psychopath's Avatar
    Join Date
    Mar 2004
    Location
    Where circles begin.
    Posts
    1,071
    nope as in i'm not translating it.
    i don't see how it is being drawn too close to the screen, because in the function call, parameters 4, 5, and 6 are position values, and all are set to zero.
    also I have somewhat of a camera implemented that i can move around....so if i moved back farther wouldn't the cube come into view?....because iv'e moved all over the place after trying to add the cube on the button click, and diddn't see anything other than my grid.
    I will try translations though.

    -psychopath
    M.Eng Computer Engineering Candidate
    B.Sc Computer Science

    Robotics and graphics enthusiast.

  6. #6
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    could be many things. post your initialization code.

    also: "glPushMatrix();" should always be paired with a "glPopMatrix()". Your matrix stack just keeps growing everytime you try to render that cube. It will eventually bottom out and bust throught the bottom of your video card setting fire to your entire PC.... or something.

  7. #7
    The Right Honourable psychopath's Avatar
    Join Date
    Mar 2004
    Location
    Where circles begin.
    Posts
    1,071
    the initialization code for OpenGL?....i belive this is it anyway :P :
    i broke it up into functions to cut down on code in the main source file
    Code:
    //Projection Matrix Set-Up
    BOOL ProjMatrix()
    {
    	glMatrixMode(GL_PROJECTION);						
    	glLoadIdentity();
    	gluPerspective(50.0, 1.0, 0.1, FarClipDist);
    	
    	return 0;
    }
    
    //Model View Matrix Set-Up
    BOOL ModelMatrix()
    {
    	glMatrixMode(GL_MODELVIEW);
    	glLoadIdentity();
    	
    	glShadeModel(GL_SMOOTH);							
    	glClearColor(0.0f, 0.0f, 0.0f, 0.5f);				
    	glClearDepth(1.0f);									
    	glEnable(GL_DEPTH_TEST);							
    	glEnable(GL_TEXTURE_2D);
    	glEnable(GL_COLOR_MATERIAL);							
    	glEnable(GL_DITHER);
    	glDepthFunc(GL_LEQUAL);								
    	glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);	
    	
    	gluLookAt(PositionX, PositionY, PositionZ,
    		ViewX, ViewY, ViewZ,
    		UpX, UpY, UpZ);
    	
    	return 0;
    }
    
    
    // Enable OpenGL
    
    VOID EnableOpenGL( HWND hWnd, HDC * hDC, HGLRC * hRC )
    {
    	PIXELFORMATDESCRIPTOR pfd;
    	int iFormat;
    	float ScreenDepth = 64;
    	float ColorDepth = 64;
    	
    	// get the device context (DC)
    	*hDC = GetDC( hWnd );
    	
    	// set the pixel format for the DC
    	ZeroMemory( &pfd, sizeof( pfd ) );
    	pfd.nSize = sizeof( pfd );
    	pfd.nVersion = 1;
    	pfd.dwFlags = PFD_DRAW_TO_WINDOW | 
    		PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
    	pfd.iPixelType = PFD_TYPE_RGBA;
    	pfd.cColorBits = ColorDepth;
    	pfd.cDepthBits = ScreenDepth;
    	pfd.iLayerType = PFD_MAIN_PLANE;
    	iFormat = ChoosePixelFormat( *hDC, &pfd );
    	SetPixelFormat( *hDC, iFormat, &pfd );
    	
    	// create and enable the render context (RC)
    	*hRC = wglCreateContext( *hDC );
    	wglMakeCurrent( *hDC, *hRC );
    	
    }
    
    // Disable OpenGL
    
    VOID DisableOpenGL( HWND hWnd, HDC hDC, HGLRC hRC )
    {
    	wglMakeCurrent( NULL, NULL );
    	wglDeleteContext( hRC );
    	ReleaseDC( hWnd, hDC );
    }
    M.Eng Computer Engineering Candidate
    B.Sc Computer Science

    Robotics and graphics enthusiast.

  8. #8
    The Right Honourable psychopath's Avatar
    Join Date
    Mar 2004
    Location
    Where circles begin.
    Posts
    1,071
    hello? anyone?....please?

    -psychopath
    M.Eng Computer Engineering Candidate
    B.Sc Computer Science

    Robotics and graphics enthusiast.

  9. #9
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    Vertex winding order perhaps?

  10. #10
    The Right Honourable psychopath's Avatar
    Join Date
    Mar 2004
    Location
    Where circles begin.
    Posts
    1,071
    erm.....whats a "vertex winding order"? :Þ ::embarassed::
    M.Eng Computer Engineering Candidate
    B.Sc Computer Science

    Robotics and graphics enthusiast.

  11. #11
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    Quote Originally Posted by psychopath
    erm.....whats a "vertex winding order"? :Þ ::embarassed::
    If you have back face culling enabled, the back sides of your polys wont be rendered. Thus, if you draw your polys with their backs facing forward, you wont see anything.

    try:
    glDisable(GL_CULL_FACE);
    to see if this is the problem.

  12. #12
    The Right Honourable psychopath's Avatar
    Join Date
    Mar 2004
    Location
    Where circles begin.
    Posts
    1,071
    >>try:
    glDisable(GL_CULL_FACE);
    to see if this is the problem.<<

    nope...thats not the problem either
    M.Eng Computer Engineering Candidate
    B.Sc Computer Science

    Robotics and graphics enthusiast.

  13. #13
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    It used to be that backface culling was an expensive, make that a more expensive operation than it is today. Most cards just check the final 2D points and their connectivity orders. If they are going in a clockwise direction they dont' draw them (depending on clockwise or counter clockwise order) and vice versa.

    I'm not saying this is the problem but there are only a couple of things that will cause no geometry to display.

    1. No ambient, diffuse, and/or specular light reaches the object. Ambient is the default amount of light in the system. It is an approximation of light rays bouncing around in your world. Since this is impossible to compute (in real time at least), ambient light is used which is the default lighting value if absolutely no other light is reflecting off of your object.
    Diffuse light is very similar to ambient and might be the same thing depending on your engine and implementation. Diffuse light is pretty much the same as ambient light but they are both used to get the desired level of illumination. Diffuse light can have a direction which results in nicely shaded objects. Ambient light does not have a direction associated with it. Specular light is more like a point source light shining on your object. Take a flashlight and a basketball into a small dark room. Shine the flashlight on the ball. You will see a specular circle of light on the ball. Because of its nature specular lighting functions require and x,y,z value for the location of the light whereas diffuse light does not. It usually requires an x,y,z value for the orientation of the light source...but all rays are assumed to be infinite in distance and there is no falloff associated with them. There are other types of lighting models as well but if no light is reaching your object then you won't see it.

    2. Incorrect material. If you have an object whose material absorbs all light then it will be black. Black is not the absence of light it is the absence of reflected light amongst objects who reflect light. Thus the black appearance. This is why black shirts are so hot on vey hot days. They reflect little light and absorb most of it resulting in a very hot shirt. Set your material property to a color of 255,255,255 which is white. This means your object reflects all wavelengths of light. Set your absorption values to low values and your specular component to a low value. You should see a soft shaded version of your object.

    3. You have translated the object off of the screen. If the object in question lies outside of the screen extents it naturally will not be rendered. Set your translation matrix so that the object is translated 0,0,100 from the camera. It is possible that if you have not translated the object at all...you are looking from inside of the object. Since this would cause your vertex winding order to be reversed..nothing would be rendered. So translate about 100 to 200 units on Z (GL uses a diff x,y,z scheme than DX) and this will fix the problem.

    4. Camera is pointing in wrong direction. Set the camera so that it looks at the center of your object. If you do not have an advanced camera system set up yet just use glLookAt() (I think thats it...I'm not an OpenGL guy).

    Hope that gets you off to a good start.

  14. #14
    The Right Honourable psychopath's Avatar
    Join Date
    Mar 2004
    Location
    Where circles begin.
    Posts
    1,071
    well....this at least narrows it down somewhat.
    I believe 1 and 2 are out though, as i don't have lighting enabled at the moment
    I double checked my camera setup, and thats not it.
    So this means i'll have to translations...i'll post later with the results.

    -psychopath
    M.Eng Computer Engineering Candidate
    B.Sc Computer Science

    Robotics and graphics enthusiast.

  15. #15
    The Right Honourable psychopath's Avatar
    Join Date
    Mar 2004
    Location
    Where circles begin.
    Posts
    1,071
    nope...translating it further into the screen diddn't work

    -psychopath
    M.Eng Computer Engineering Candidate
    B.Sc Computer Science

    Robotics and graphics enthusiast.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. display character size...(quite urgent..)
    By karthi in forum C Programming
    Replies: 10
    Last Post: 07-11-2007, 09:42 PM
  2. new problem with class
    By jrb47 in forum C++ Programming
    Replies: 0
    Last Post: 12-01-2006, 08:39 AM
  3. My text doesn't display
    By joeprogrammer in forum Game Programming
    Replies: 11
    Last Post: 02-23-2006, 10:01 PM
  4. about scan 7-segment display via parallel port
    By mobdawg in forum C Programming
    Replies: 4
    Last Post: 09-11-2002, 06:11 AM
  5. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 09:44 AM