Odd 3D Invis Objects?

This is a discussion on Odd 3D Invis Objects? within the Game Programming forums, part of the General Programming Boards category; Ok, i am using a Glut Shell if you will, that i was shown on these forums. Just incase you ...

  1. #1
    #junkie
    Join Date
    Oct 2004
    Posts
    240

    Post Odd 3D Invis Objects?

    Ok, i am using a Glut Shell if you will, that i was shown on these forums. Just incase you notice lol .

    My problem is this, i am using glut and taking NeHe tutorials, i am checkin out lesson 05, making 3d objects rotate.

    Now i have made simple 3d objects before, however i have never encountered this. For some reason they are invis, and this is my first time using this glut shell. So i assume it is the shell but i have no idea what would cause this.

    And let me restate that about the invisible objects, there is a triangle and a cube, the triangle, made up of 4 other triangles to form the 3d object; then the cube, 6 quads. Very simple, each of them also have some color.

    Now the problem is that some of the triangles/quads (the flat triangles/quads ofcourse) seem to be partially invisible, and on the cube where there is solid colors, it looks almost as if certin colors overlap to disapear and junk like that. I am sure you are confused, i dont know really how to explain it. Basically some sides on these 3d pbjects are partially invisible to me, any ideas why? Here is the following code.

    Code:
    //#include <windows.h>
    #include <iostream>
    #include <gl\gl.h>
    #include <gl\glut.h>
    
        GLfloat		rquad;
        GLfloat		rtri;
        
        void draw();
    
    
    // process menu option 'op'
    void menu(int op) {
    
      switch(op) {
      case 'Q':
      case 'q':
        exit(0);
      }
    }
    
    // executed when a regular key is pressed
    void keyboardDown(unsigned char key, int x, int y) {
    
      switch(key) {
      case 'Q':
      case 'q':
      case  27:   // ESC
        exit(0);
      }
    }
    
    // executed when a regular key is released
    void keyboardUp(unsigned char key, int x, int y) {
    
    }
    
    // executed when a special key is pressed
    void keyboardSpecialDown(int k, int x, int y) {
    
    }
    
    // executed when a special key is released
    void keyboardSpecialUp(int k, int x, int y) {
    
    }
    
    // reshaped window
    void reshape(int width, int height) {
    
      GLfloat fieldOfView = 90.0f;
      glViewport (0, 0, (GLsizei) width, (GLsizei) height);
    
      glMatrixMode (GL_PROJECTION);
      glLoadIdentity();
      gluPerspective(fieldOfView, (GLfloat) width/(GLfloat) height, 0.1, 500.0);
    
      glMatrixMode(GL_MODELVIEW);
      glLoadIdentity();
    }
    
    
    void mouseClick(int button, int state, int x, int y) {
    
    }
    
    void mouseMotion(int x, int y) {
    
    }
    
    // executed when program is idle
    void idle() { 
        draw();
    }
    
    // render the scene
    void draw() {
    
      glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
      glMatrixMode(GL_MODELVIEW);
      glLoadIdentity();
      glTranslatef(-1.5f,0.0f,-6.0f);	
      
      glRotatef(rtri,0.0f,1.0f,0.0f);
      glBegin(GL_TRIANGLES);					// Start Drawing A Triangle
    		glColor3f(1.0f,0.0f,0.0f);			// Red
    		glVertex3f( 0.0f, 1.0f, 0.0f);			// Top Of Triangle (Front)
    		glColor3f(0.0f,1.0f,0.0f);			// Green
    		glVertex3f(-1.0f,-1.0f, 1.0f);			// Left Of Triangle (Front)
    		glColor3f(0.0f,0.0f,1.0f);			// Blue
    		glVertex3f( 1.0f,-1.0f, 1.0f);			// Right Of Triangle (Front)
    
    		glColor3f(1.0f,0.0f,0.0f);			// Red
    		glVertex3f( 0.0f, 1.0f, 0.0f);			// Top Of Triangle (Right)
    		glColor3f(0.0f,0.0f,1.0f);			// Blue
    		glVertex3f( 1.0f,-1.0f, 1.0f);			// Left Of Triangle (Right)
    		glColor3f(0.0f,1.0f,0.0f);			// Green
    		glVertex3f( 1.0f,-1.0f, -1.0f);			// Right Of Triangle (Right)
    
    		glColor3f(1.0f,0.0f,0.0f);			// Red
    		glVertex3f( 0.0f, 1.0f, 0.0f);			// Top Of Triangle (Back)
    		glColor3f(0.0f,1.0f,0.0f);			// Green
    		glVertex3f( 1.0f,-1.0f, -1.0f);			// Left Of Triangle (Back)
    		glColor3f(0.0f,0.0f,1.0f);			// Blue
    		glVertex3f(-1.0f,-1.0f, -1.0f);			// Right Of Triangle (Back)
    
    		glColor3f(1.0f,0.0f,0.0f);			// Red
    		glVertex3f( 0.0f, 1.0f, 0.0f);			// Top Of Triangle (Left)
    		glColor3f(0.0f,0.0f,1.0f);			// Blue
    		glVertex3f(-1.0f,-1.0f,-1.0f);			// Left Of Triangle (Left)
    		glColor3f(0.0f,1.0f,0.0f);			// Green
    		glVertex3f(-1.0f,-1.0f, 1.0f);			// Right Of Triangle (Left)
      glEnd();
      
      glLoadIdentity();					// Reset The Current Modelview Matrix
      glTranslatef(1.5f,0.0f,-6.0f);				// Move Right 1.5 Units And Into The Screen 6.0
      glRotatef(rquad,1.0f,0.0f,0.0f);			// Rotate The Quad On The X axis ( NEW )
      
    	glColor3f(0.5f,0.5f,1.0f);				// Set The Color To A Nice Blue Shade
    	glBegin(GL_QUADS);					// Start Drawing A Quad
    		glColor3f(0.0f,1.0f,0.0f);			// Set The Color To Green
    		glVertex3f( 1.0f, 1.0f,-1.0f);			// Top Right Of The Quad (Top)
    		glVertex3f(-1.0f, 1.0f,-1.0f);			// Top Left Of The Quad (Top)
    		glVertex3f(-1.0f, 1.0f, 1.0f);			// Bottom Left Of The Quad (Top)
    		glVertex3f( 1.0f, 1.0f, 1.0f);			// Bottom Right Of The Quad (Top)
    
    		glColor3f(1.0f,0.5f,0.0f);			// Set The Color To Orange
    		glVertex3f( 1.0f,-1.0f, 1.0f);			// Top Right Of The Quad (Bottom)
    		glVertex3f(-1.0f,-1.0f, 1.0f);			// Top Left Of The Quad (Bottom)
    		glVertex3f(-1.0f,-1.0f,-1.0f);			// Bottom Left Of The Quad (Bottom)
    		glVertex3f( 1.0f,-1.0f,-1.0f);			// Bottom Right Of The Quad (Bottom)
    		
    		glColor3f(1.0f,0.0f,0.0f);			// Set The Color To Red
    		glVertex3f( 1.0f, 1.0f, 1.0f);			// Top Right Of The Quad (Front)
    		glVertex3f(-1.0f, 1.0f, 1.0f);			// Top Left Of The Quad (Front)
    		glVertex3f(-1.0f,-1.0f, 1.0f);			// Bottom Left Of The Quad (Front)
    		glVertex3f( 1.0f,-1.0f, 1.0f);			// Bottom Right Of The Quad (Front)
    
    		glColor3f(1.0f,1.0f,0.0f);			// Set The Color To Yellow
    		glVertex3f( 1.0f,-1.0f,-1.0f);			// Bottom Left Of The Quad (Back)
    		glVertex3f(-1.0f,-1.0f,-1.0f);			// Bottom Right Of The Quad (Back)
    		glVertex3f(-1.0f, 1.0f,-1.0f);			// Top Right Of The Quad (Back)
    		glVertex3f( 1.0f, 1.0f,-1.0f);			// Top Left Of The Quad (Back)
    		
    		glColor3f(0.0f,0.0f,1.0f);			// Set The Color To Blue
    		glVertex3f(-1.0f, 1.0f, 1.0f);			// Top Right Of The Quad (Left)
    		glVertex3f(-1.0f, 1.0f,-1.0f);			// Top Left Of The Quad (Left)
    		glVertex3f(-1.0f,-1.0f,-1.0f);			// Bottom Left Of The Quad (Left)
    		glVertex3f(-1.0f,-1.0f, 1.0f);			// Bottom Right Of The Quad (Left)
    
    		glColor3f(1.0f,0.0f,1.0f);			// Set The Color To Violet
    		glVertex3f( 1.0f, 1.0f,-1.0f);			// Top Right Of The Quad (Right)
    		glVertex3f( 1.0f, 1.0f, 1.0f);			// Top Left Of The Quad (Right)
    		glVertex3f( 1.0f,-1.0f, 1.0f);			// Bottom Left Of The Quad (Right)
    		glVertex3f( 1.0f,-1.0f,-1.0f);			// Bottom Right Of The Quad (Right)
    	glEnd();						// Done Drawing The Quad
    
      
      glFlush();
      glutSwapBuffers();
      rtri+=0.2f;
      rquad-=0.15f;
    }
    
    // initialize OpenGL settings
    void initGL(int width, int height) {
    
      reshape(width, height);
    
      glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
      glClearDepth(1.0f);
    }
    
    // initialize GLUT settings, register callbacks, enter main loop
    int main(int argc, char** argv) {
      
      glutInit(&argc, argv);
    
      glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
      glutInitWindowSize(800, 600);
      glutInitWindowPosition(100, 100);
      glutCreateWindow("EmptyGLUT");
    
      // register glut call backs
      glutKeyboardFunc(keyboardDown);
      glutKeyboardUpFunc(keyboardUp);
      glutSpecialFunc(keyboardSpecialDown);
      glutSpecialUpFunc(keyboardSpecialUp);
      glutMouseFunc(mouseClick);
      glutMotionFunc(mouseMotion);
      glutReshapeFunc(reshape);
      glutDisplayFunc(draw);  
      glutIdleFunc(idle);
      glutIgnoreKeyRepeat(true); // ignore keys held down
    
      // create a sub menu 
      int subMenu = glutCreateMenu(menu);
      glutAddMenuEntry("Do nothing", 0);
      glutAddMenuEntry("Really Quit", 'q');
    
      // create main "right click" menu
      glutCreateMenu(menu);
      glutAddSubMenu("Sub Menu", subMenu);
      glutAddMenuEntry("Quit", 'q');
      glutAttachMenu(GLUT_RIGHT_BUTTON);
    
      initGL(800, 600);
    
      glutMainLoop();
      return 0;
    }
    Also i know i am not using any of the key commands and junk so its wasted code, like i said its just a glut overall shell program. Anyway, any ideas on why some are partially invisible?

    If there is anything else you need to know please ask, umm, i am using Dev C++, 4.9.9.0. Glut version 3.7 (beta i believe), from the main opengl website. But like i said iv made a bunch of the same type of 3D objects and i havent seen this partial invisibility thing before.

    Hope i have given you enough information to help, thanks for any replies
    01110111011000010110110001100100011011110010000001 11000101110101011010010111010000100000011011000110 10010110011001100101001000000111100101101111011101 0100100000011011100111010101100010

  2. #2
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,584
    A screenshot of the problem would be nice.

    Just hit PrtScrn - paste to your fav paint program, resample to 640x480 and convert to JPG. Click manage attachments when you post and browse to the JPG file you just created.

  3. #3
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    That GLUT framework doesnt configure your openGL rendering states. In this case you need to enable depth testing. Put this in your initGL() function

    Code:
     
    glEnable(GL_DEPTH_TEST);
    glDepthFunc(GL_LEQUAL);
    on an unrelated note: yay! someones getting some use out of the GLUT template i posted!

  4. #4
    #junkie
    Join Date
    Oct 2004
    Posts
    240
    lol yup , but thanks, i'll test it tomorrow, hope it fixes it hehe
    01110111011000010110110001100100011011110010000001 11000101110101011010010111010000100000011011000110 10010110011001100101001000000111100101101111011101 0100100000011011100111010101100010

  5. #5
    #junkie
    Join Date
    Oct 2004
    Posts
    240
    FYI, yes it fixed it, thx
    01110111011000010110110001100100011011110010000001 11000101110101011010010111010000100000011011000110 10010110011001100101001000000111100101101111011101 0100100000011011100111010101100010

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Moving objects with mouse in 3D.
    By psychopath in forum Game Programming
    Replies: 15
    Last Post: 07-10-2011, 04:20 PM
  2. How to rotate child objects in 3D
    By Arianiv in forum Game Programming
    Replies: 11
    Last Post: 04-03-2008, 05:09 AM
  3. Replies: 60
    Last Post: 12-20-2005, 10:36 PM
  4. 3D starfield
    By VirtualAce in forum Game Programming
    Replies: 6
    Last Post: 06-26-2003, 12:40 PM
  5. 3D Objects In OpenGL
    By kas2002 in forum Game Programming
    Replies: 5
    Last Post: 08-06-2002, 12:15 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21