PDA

View Full Version : OpenGL Coding


Dogcow
09-27-2002, 12:15 AM
I've got my program compiling now, but it brings up a blank window (white) that turns black if I drag other windows over it (or move it to my other monitor.) Also, it shows nothing on it, and according to instructions I've found online, it should have a triangle and rectangle rendered.

If anybody wants the entire Project Builder project, I can upload it (312k before compression), or if you can figure out what's wrong from the code, here it is:

#include <OpenGL/gl.h> // Header File For The OpenGL32 Library
#include <OpenGL/glu.h> // Header File For The GLu32 Library
#include <GLUT/glut.h> // Header File For The GLut Library

typedef void GLvoid; //fixes compatibility problems between old OpenGL and newer...

GLvoid InitGL(GLvoid);
GLvoid DrawGLScene(GLvoid);
GLvoid ReSizeGLScene(int Width, int Height);

int main(int argc, char** argv) //general stuff to set OpenGL up...
{
glutInit(&argc, argv);
glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize (500, 500);
glutInitWindowPosition (100, 100);
glutCreateWindow (argv[0]);

InitGL();

glutDisplayFunc(DrawGLScene); //calls main draw function
glutReshapeFunc(ReSizeGLScene);

glutMainLoop();

return 0;
}

void InitGL(){
}

GLvoid DrawGLScene(GLvoid) // Here's Where We Do All The Drawing
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer
glLoadIdentity(); // Reset The View

glTranslatef(-1.5f,0.0f,-6.0f);

glBegin(GL_TRIANGLES); // Drawing Using Triangles
glVertex3f( 0.0f, 1.0f, 0.0f); // Top
glVertex3f(-1.0f,-1.0f, 0.0f); // Bottom Left
glVertex3f( 1.0f,-1.0f, 0.0f); // Bottom Right
glEnd(); // Finished Drawing The Triangle

glBegin(GL_QUADS); // Draw A Quad
glVertex3f(-1.0f, 1.0f, 0.0f); // Top Left
glVertex3f( 1.0f, 1.0f, 0.0f); // Top Right
glVertex3f( 1.0f,-1.0f, 0.0f); // Bottom Right
glVertex3f(-1.0f,-1.0f, 0.0f); // Bottom Left
glEnd();
// Done Drawing The Quad
}


void ReSizeGLScene(int Width, int Height){
}

Thanks in advance,
-Dogcow "moof!"
Visit The Underground (http://theunderground.eon.com.au)

below
09-27-2002, 01:37 AM
Hi Dogcow,

while I am unable to find out what is wrong with your code, check

http://nehe.gamedev.net/tutorials/macosxcocoa/lesson02.zip

It seems that you are going through this OpenGL tutorial, but have been trying to follow the PC side. Check the Cocoa examples, which may seem intimidating first. But they show how to "properly" handle OpenGL in a Cocoa environment (methinks). The Cocoa examples are listed at the end of each page and are just a little different from what the PC folks do.

It may be that the project files don't open in the new project builder, when I have some time I will check into that.

Alex

Dogcow
09-27-2002, 01:43 AM
Yeah, the cocoa one does compile and run fine on my machine, but it's huge. I need to get something much smaller working first so I can understand what's going on.

It will compile fine, you just have to let it upgrade that project to the newer version...


-Dogcow "moof!"
Visit The Underground (http://theunderground.eon.com.au)

blb
09-27-2002, 02:17 AM
Originally posted by Dogcow
Yeah, the cocoa one does compile and run fine on my machine, but it's huge. I need to get something much smaller working first so I can understand what's going on.

It will compile fine, you just have to let it upgrade that project to the newer version...


-Dogcow "moof!"
Visit The Underground (http://theunderground.eon.com.au)
It's not that big, just a few hundred lines of code, and not code all packed together.

Anyway, your problem is most likely that you need to tell it you are done. Since you're using GLUT and double-buffering, put a call to glutSwapBuffers() at the end of DrawGLScene(). If you were using single-buffering, glFlush() would be the call to use.

below
09-27-2002, 03:06 AM
Hi dogcow,

I am unsure what your goal is, but I would recommend some reading on Cocoa, preferably in Aaron Hillerman's excellent "Cocoa Programming for Mac OS X".
Actually not that much is needed to understand the "huge" framework for the OpenGL examples.

I really think the Cocoa examples present the way OpenGL should be done for most applications under OS X, and once you understand a little about what they do (e.g. the view architecture) they are no more intimidating than the pure "DOS" examples.

If you have more questions, let me know

Alex

Dogcow
09-27-2002, 10:48 AM
Originally posted by below
Hi dogcow,

I am unsure what your goal is, but I would recommend some reading on Cocoa, preferably in Aaron Hillerman's excellent "Cocoa Programming for Mac OS X".
Actually not that much is needed to understand the "huge" framework for the OpenGL examples.

I really think the Cocoa examples present the way OpenGL should be done for most applications under OS X, and once you understand a little about what they do (e.g. the view architecture) they are no more intimidating than the pure "DOS" examples.

If you have more questions, let me know

Alex

I have his book but a) he focuses mainly on objective c- I need to use just c or c++ b) he doesn't teach opengl at all c) I need my program to work cross platform...just hand someone my .cpp file and let them compile it.

-Dogcow "moof!"
Visit The Underground (http://theunderground.eon.com.au)

below
09-29-2002, 05:59 PM
Hi dogcow,

the section on creating a custom view however will enable you to understand what the Cocoa examples do. I now see your problem however. I will look through my OGL samples. I am sure I had a plain C project that works, so you might be able to compare it to yours.

Bye,

Alex

below
10-04-2002, 03:23 AM
Hm, I am pretty sure the little program I have here worked pre-10.2... Now I have the similar results. (White window)

Will investigate...

Alex