Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

saisoft

Cube will not show on screen, help????

This topic is 5667 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Here is the source code #include <windows.h> #include <gl/glut.h> void display(void); void ChangeSize(GLsizei w, GLsizei h); double rot = 0.0f; int main(int argc, char** argv) { glutInit (&argc, argv) ; glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB) ; glutInitWindowSize (800, 600) ; glutInitWindowPosition (100, 100) ; glutCreateWindow ("First Chapter - Opening an OpenGL Window") ; glClearColor(0.0f,0.0f,0.0f,1.0f); glEnable(GL_DEPTH_TEST); glutDisplayFunc(display); glutReshapeFunc(ChangeSize); glutMainLoop(); return 0 ; } void display() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer glLoadIdentity(); // Done Drawing The Quad glTranslatef(500.0f,300.0f,0.0f); if(rot == 360.0) rot = 0.0; glRotatef(rot,0.0,1.0,0.0); glBegin(GL_QUADS); //top glColor3f(1.0f,0.0f,0.0f); glVertex3f(0.0f,0.0f,0.0f); glVertex3f(0.0f,0.0f,-1.0f); glVertex3f(1.0f,0.0f,-1.0f); glVertex3f(1.0f,0.0f,0.0f); //bottom glColor3f(0.0f,1.0f,0.0f); glVertex3f(0.0f,-1.0f,0.0f); glVertex3f(0.0f,-1.0f,-1.0f); glVertex3f(1.0f,-1.0f,-1.0f); glVertex3f(1.0f,-1.0f,0.0f); //front glColor3f(0.0f,0.0f,1.0f); glVertex3f(0.0f,0.0f,0.0f); glVertex3f(1.0f,0.0f,0.0f); glVertex3f(1.0f,-1.0f,0.0f); glVertex3f(0.0f,-1.0f,0.0f); //back glColor3f(1.0f,1.0f,0.0f); glVertex3f(0.0f,0.0f,-1.0f); glVertex3f(1.0f,0.0f,-100.0f); glVertex3f(1.0f,-1.0f,-1.0f); glVertex3f(0.0f,-1.0f,-1.0f); //left glColor3f(1.0f,0.0f,1.0f); glVertex3f(0.0f,0.0f,0.0f); glVertex3f(0.0f,0.0f,-1.0f); glVertex3f(0.0f,-1.0f,-1.0f); glVertex3f(0.0f,-1.0f,0.0f); //right glColor3f(0.0f,1.0f,1.0f); glVertex3f(1.0f,0.0f,0.0f); glVertex3f(1.0f,0.0f,-1.0f); glVertex3f(1.0f,-1.0f,-1.0f); glVertex3f(1.0f,-1.0f,0.0f); glEnd(); rot+=0.25f; glutSwapBuffers(); glutPostRedisplay(); } void ChangeSize(GLsizei w, GLsizei h) { if (h==0) // Prevent A Divide By Zero By { h=1; // Making Height Equal One } glViewport(0, 0, w, h); // Reset The Current Viewport glMatrixMode(GL_PROJECTION); // Select The Projection Matrix glLoadIdentity(); // Reset The Projection Matrix // Calculate The Aspect Ratio Of The Window // (Field of view, aspect ratio, near, far) gluPerspective(45.0f,(GLfloat)w/(GLfloat)h,1.0f,400.0f); glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix glLoadIdentity(); // Reset The Modelview Matrix }

Share this post


Link to post
Share on other sites
Advertisement
You''re not drawing within the view frustum.

Try changing:

glTranslatef(500.0f,300.0f,0.0f);

to

glTranslatef(0.0f,0.0f,-10.0f);

Oh, and one of your quads need fixing .

Share this post


Link to post
Share on other sites
Wow thankyou, please explain this too me, i thought by moving 500 over and 300 up, i was moving near the center and then drawing my object from their, thanks so much, explain if u can

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!