Skip to main content
gamedev.net
🔒 Locked

first opengl program in visual c++.net

Started by cellman Jan 20, 2005 at 2:30 PM 1 replies 750+ views
Original Post
cellman
cellman
I want to get started using opengl in visual c++.net 2003 standard edition.net the trouble is programs wont compiler i am not typing these programs i am pasting some code to see if it works so far it has not worked i am Using code that I found on line so my question is what headers should i use and is something wrong with this code What do I need to do before this code or one like it will compile without a problem and/or error #include #include #include #include GLenum doubleBuffer; GLint thing1, thing2; // This is usually the first function. It is called from main() // and runs only once static void Init(void) { // Set background color to black. (Intensity, red, green, blue). // Numbers may be between 0 and 1, inclusive. glClearColor(0.0, 0.0, 0.0, 0.0); glClearAccum(0.0, 0.0, 0.0, 0.0); thing1 = glGenLists(1); // create a list with 1 item glNewList(thing1, GL_COMPILE); glColor3f(1.0, 0.0, 0.0); // set the foreground color to red glRectf(-1.0, -1.0, 1.0, 0.0); // draw a rectangle glEndList(); // end list thing2 = glGenLists(1); // create a second list glNewList(thing2, GL_COMPILE); glColor3f(0.0, 1.0, 0.0); glRectf(0.0, -1.0, 1.0, 1.0); glEndList(); } static void Reshape(int width, int height) { // In OpenGL, matrices are used to manage the view. There are 2 matrix modes: // projection, which sets up the viewport and clipping boundary, and modelview // which rotates, translates, and scales objects. glViewport(0, 0, width, height); glMatrixMode(GL_PROJECTION); // set matrix mode glLoadIdentity(); // load the identity matrix into the current matrix state glMatrixMode(GL_MODELVIEW); // set matrix mode glLoadIdentity(); // load the identity matrix into the current matrix state } // This function constantly checks for pressed keys. static void Key(unsigned char key, int x, int y) { switch (key) { // Polygons have a front and back face, properties may be set for both. // glPolygonMode controls the drawing mode for the specified face(s). Faces may be // specified as GL_FRONT, GL_BACK, or GL_FRONT_AND_BACK. The mode specifies how the // polygon is to be drawn and may be GL_POINT, GL_LINE, or GL_FILL. case '1': glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); glutPostRedisplay(); break; case '2': glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); glutPostRedisplay(); break; case 27: exit(0); } } static void Draw(void) { glPushMatrix(); glScalef(0.8, 0.8, 1.0); glClear(GL_COLOR_BUFFER_BIT); glCallList(thing1); glAccum(GL_LOAD, 0.5); glClear(GL_COLOR_BUFFER_BIT); // clear the window glCallList(thing2); glAccum(GL_ACCUM, 0.5); glAccum(GL_RETURN, 1.0); glPopMatrix(); if (doubleBuffer) { glutSwapBuffers(); } else { glFlush(); } } static void Args(int argc, char **argv) { GLint i; doubleBuffer = GL_FALSE; for (i = 1; i < argc; i++) { if (strcmp(argv, "-sb") == 0) { doubleBuffer = GL_FALSE; } else if (strcmp(argv, "-db") == 0) { doubleBuffer = GL_TRUE; } } } int main(int argc, char **argv) { GLenum type; // gluInit() provides general initialization for the GLUT library glutInit(&argc, argv); Args(argc, argv); // ==== Set up display mode ==== type = GLUT_RGB | GLUT_ACCUM; // set type to RGB color with accum. // also set type to either double or single buffer type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; glutInitDisplayMode(type); // initialize the display mode glutInitWindowSize(300, 300); // set window size glutCreateWindow("OpenGL Sample Program"); // set window title Init(); // initialize OpenGL glutReshapeFunc(Reshape); glutKeyboardFunc(Key); glutDisplayFunc(Draw); glutMainLoop(); } In .net i have heard that it does not use the .h exstention is this true and could that be the problem
Promit
Promit
What are the compile errors?
SlimDX | Ventspace Blog | Twitter | Diverse teams make better games. I am currently hiring capable C++ engine developers in Baltimore, MD.
Solias
Solias
do you have glut installed?

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.