Jump to content
  • Advertisement

Archived

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

cb007sax

GLUT will not load

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

Ok, i was wondering if anyone can take a look at my code, this code works in win32, but not with glut. The model mesh''s and vertices, are fine, it just wont render. what is wrong? //*********************************// //** THE MAIN FILE FOR EVILBALLZ **// //** **// //*********************************// #include <windows.h> // Header File For Windows #include <gl\gl.h> // Header File For The OpenGL32 Library #include <gl\glu.h> // Header File For The GLu32 Library #include <gl\glaux.h> // Header File For The GLaux Library #include <gl\glut.h> #include <math.h> #include <string> #include <stdio.h> #include <fstream.h> #include <vector> // FUCK THE STANDARD // Header File For NeHeGL #pragma comment( lib, "opengl32.lib" ) // Search For OpenGL32.lib While Linking #pragma comment( lib, "glu32.lib" ) // Search For GLu32.lib While Linking #pragma comment( lib, "glaux.lib" ) // Search For GLaux.lib While Linking #pragma comment( lib, "glut32.lib") #ifndef CDS_FULLSCREEN // CDS_FULLSCREEN Is Not Defined By Some #define CDS_FULLSCREEN 4 // Compilers. By Defining It This Way, #endif /** Variables **/ // We Can Avoid Errors GLfloat xrot = 0.0f; GLfloat specular [] = { 1.0, 1.0, 1.0, 1.0 }; GLfloat shininess [] = { 100.0 }; GLfloat position [] = { 0.0, 0.0, 1.0, 0.0 }; GLuint DLid; bool line = false; typedef struct VertexStruct { float x, y, z; } Point3; std::vector cvertex; std::vector meshface; // OUR POINTS AND MESH FACES // User Defined Variables float angle; // Used To Rotate The Triangles int rot1, rot2; // Counter Variables //**********************************************************************************************// // FUNCTION DEFINITIONS // //**********************************************************************************************// Point3 normal(Point3 p1, Point3 p2, Point3 p3); // Normalizer Function int loadObj(char *filename); // Loads Objects BOOL Initialize (); // Initialize lists and properties void renderScene(); // Renders the scene to the screen //**********************************************************************************************// // MAIN FUNCTION // //**********************************************************************************************// int main(int argc, char **argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_DEPTH | GLUT_SINGLE | GLUT_RGBA); glutInitWindowPosition(100,100); glutInitWindowSize(320,320); glutCreateWindow("3D Tech- GLUT Tutorial"); Initialize(); glutDisplayFunc(renderScene); glutIdleFunc(renderScene); glutMainLoop(); return 0; } Point3 normal(Point3 p1, Point3 p2, Point3 p3) { Point3 tmp1 = {p2.x - p1.x, p2.y - p1.y, p2.z - p1.z}; Point3 tmp2 = {p3.x - p1.x, p3.y - p1.y, p3.z - p1.z}; Point3 tmp3 = {tmp1.y*tmp2.z - tmp1.z*tmp2.y, tmp1.z*tmp2.x - tmp1.x*tmp2.z, tmp1.x*tmp2.y - tmp1.y*tmp2.x}; float length = (float)sqrt( tmp3.x*tmp3.x + tmp3.y*tmp3.y + tmp3.z*tmp3.z); tmp3.x /= length; tmp3.y /= length; tmp3.z /= length; return tmp3; } int loadObj(char *filename) { ifstream fileopen("map1.x"); Point3 tempPoint; char getchar = ''$''; int k,d; int tempMesh; int numVertices; int numFaces; if(fileopen.fail()) { MessageBox(NULL, TEXT("Could not open object!"), NULL, NULL); return -1; } while(getchar != ''{'') fileopen.read(&getchar, 1); getchar = ''$''; // Just to make sure its not a { while(getchar != ''{'') fileopen.read(&getchar, 1); fileopen.read(&getchar, 1); fileopen.read(&getchar, 1); getchar = ''$''; fileopen >> numVertices; while(getchar != ''\t'') fileopen.read(&getchar, 1); for(k=0;k> tempPoint.x; fileopen.read(&getchar, 1); fileopen >> tempPoint.y; fileopen.read(&getchar, 1); fileopen >> tempPoint.z; fileopen.read(&getchar, 1); fileopen.read(&getchar, 1); cvertex.push_back(tempPoint); } // Now load the mesh! fileopen.read(&getchar, 1); fileopen.read(&getchar, 1); fileopen >> numFaces; while(getchar != ''\t'') fileopen.read(&getchar, 1); for(k=0;k> tempMesh; fileopen.read(&getchar, 1); for(d=0;d<3;d++) { fileopen >> tempMesh; fileopen.read(&getchar, 1); meshface.push_back(tempMesh); } fileopen.read(&getchar, 1); fileopen.read(&getchar, 1); fileopen.read(&getchar, 1); } fileopen.close(); return 0; } BOOL Initialize () // Any GL Init Code & User Initialiazation Goes Here { GLuint cDL; // Compile Display list; Point3 tempNormal; int k; loadObj("map1.x"); glClearColor (0.0f, 0.0f, 0.0f, 0.5f); // Black Background glClearDepth (1.0f); // Depth Buffer Setup glDepthFunc (GL_LEQUAL); // The Type Of Depth Testing (Less Or Equal) glEnable (GL_DEPTH_TEST); // Enable Depth Testing glShadeModel (GL_SMOOTH); // Select Smooth Shading glHint (GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Set Perspective Calculations To Most Accurate glEnable(GL_COLOR_MATERIAL); glEnable (GL_LIGHTING); glEnable(GL_LIGHT0); glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, specular); glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, shininess); glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE); glLightfv(GL_LIGHT0, GL_POSITION, position); glLightModelf(GL_LIGHT_MODEL_TWO_SIDE,1.0f); /* SETUP DISPLAY LIST */ cDL = glGenLists(1); glNewList(cDL,GL_COMPILE); glColor3f (0.342f, 0.453f, 0.0f); for(k=0;k

Share this post


Link to post
Share on other sites
Advertisement

  • 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!