rendering a cube

Started by
0 comments, last by joey81 22 years, 4 months ago
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....
Advertisement
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 )
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 :P)

This topic is closed to new replies.

Advertisement