Jump to content
  • Advertisement


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


rendering a cube

This topic is 6128 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

I''ve used a OpenGL in console application that supports MFC to create a rotating cube... The codes are as follows.... // 3D Cube.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include "3D Cube.h" #include #include #include #include #include #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // The one and only application object CWinApp theApp; using namespace std; void changeSize(int w, int h) { // Prevent a divide by zero, when window is too short // (you cant make a window of zero width). if(h == 0) h = 1; float ratio = 1.0* w / h; // Reset the coordinate system before modifying glMatrixMode(GL_PROJECTION); glLoadIdentity(); // Set the viewport to be the entire window glViewport(0, 0, w, h); // Set the correct perspective. gluPerspective(45,ratio,1,1000); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt(0.0,0.0,5.0, 0.0,0.0,-1.0, 0.0f,1.0f,0.0f); } void DrawCube(void) { static GLfloat wAngleX = 0.0f; static GLfloat wAngleY = 0.0f; static GLfloat wAngleZ = 0.0f; glClearColor(0.0f, 0.0f, 0.0f, 1.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glPushMatrix(); glTranslatef(0.0f, 0.0f, 0.0f); glRotatef(wAngleX, 1.0f, 0.0f, 0.0f); glRotatef(wAngleY, 0.0f, 1.0f, 0.0f); glRotatef(wAngleZ, 0.0f, 0.0f, 1.0f); wAngleX += 0.05f; wAngleY += 0.05f; wAngleZ += 0.05f; glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); glBegin(GL_QUADS); glColor3f(1.0,0.0,0.0); glVertex3f(-0.5,0.5,0.5); glColor3f(1.0,0.0,0.0); glVertex3f(0.5,0.5,0.5); glColor3f(1.0,0.0,0.0); glVertex3f(0.5,-0.5,0.5); glColor3f(1.0,0.0,0.0); glVertex3f(-0.5,-0.5,0.5); glColor3f(1.0,0.0,0.0); glVertex3f(0.5,0.5,0.5); glColor3f(1.0,0.0,0.0); glVertex3f(0.5,0.5,-0.5); glColor3f(1.0,0.0,0.0); glVertex3f(0.5,-0.5,-0.5); glColor3f(1.0,0.0,0.0); glVertex3f(0.5,-0.5,0.5); glColor3f(1.0,0.0,0.0); glVertex3f(-0.5,0.5,-0.5); glColor3f(1.0,0.0,0.0); glVertex3f(0.5,0.5,-0.5); glColor3f(1.0,0.0,0.0); glVertex3f(0.5,-0.5,-0.5); glColor3f(1.0,0.0,0.0); glVertex3f(-0.5,-0.5,-0.5); glColor3f(1.0,0.0,0.0); glVertex3f(-0.5,0.5,0.5); glColor3f(1.0,0.0,0.0); glVertex3f(-0.5,0.5,-0.5); glColor3f(1.0,0.0,0.0); glVertex3f(-0.5,-0.5,-0.5); glColor3f(1.0,0.0,0.0); glVertex3f(-0.5,-0.5,0.5); glColor3f(1.0,0.0,0.0); glVertex3f(-0.5f, 0.5f, 0.5f); glColor3f(1.0,0.0,0.0); glVertex3f(0.5f, 0.5f, 0.5f); glColor3f(1.0,0.0,0.0); glVertex3f(0.5f, 0.5f, -0.5f); glColor3f(1.0,0.0,0.0); glVertex3f(-0.5f, 0.5f, -0.5f); glColor3f(1.0,0.0,0.0); glVertex3f(-0.5f, -0.5f, 0.5f); glColor3f(1.0,0.0,0.0); glVertex3f(0.5f, -0.5f, 0.5f); glColor3f(1.0,0.0,0.0); glVertex3f(0.5f, -0.5f, -0.5f); glColor3f(1.0,0.0,0.0); glVertex3f(-0.5f, -0.5f, -0.5f); glEnd(); glPopMatrix(); glFinish(); glutSwapBuffers(); } int _tmain(int argc, char **argv) { int nRetCode = 0; // initialize MFC and print and error on failure if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0)) { // TODO: change error code to suit your needs cerr << _T("Fatal Error: MFC initialization failed") << endl; nRetCode = 1; } else { printf("This is a rotating cube !!\n"); glutInit(&argc, argv); glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA); glutInitWindowPosition(200,150); glutInitWindowSize(320,320); glutCreateWindow("Rotating Cube"); glutDisplayFunc(DrawCube); glutIdleFunc(DrawCube); glutReshapeFunc(changeSize); glutMainLoop(); } return nRetCode; } I need to render a .bmp file onto the surface of this cube... But i do not know how to go about doing it.... Can anyone help me??? Pls dun tel me to refer to NeHe tutorials on ''Quadratics'' cos i tried reading them but cant seem to understand.... Thanks in advance....

Share this post

Link to post
Share on other sites
I know you didn''t want to hear this but check out tutorial lesson 6 it doesn''t talk about quadratics and that other stuff it just focuses on texture mapping. That is about the best I can do for you... it''s fairly straight forward... if that still doesn''t help you just email me and I''ll try and give you a detail description...

I''m don''t know much but I can try to help... just email me at... Shadow_0f_Light@Yahoo.com

(the ''0'' in ''Of'' is a zero )

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!