- #1
cscott
- 782
- 1
I'm having some trouble on OS X following a tutorial that wasn't really meant for this language-OS combination.
I'm using Xcode and the GLUT+OpenGL frameworks to compile the following code. [it's supposed to open a window and display a white square and triangle on a black backdrop.]:
...I get a window but it's white with nothing in it. When I resize the window to particular sizes I can see the black background and square only but obviously something is still wrong...
The only code I can find is written in Objective-C and uses some NextStep stuff.
NeHe tutotirlas:
http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=02
http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=Mac_OS_X
I'm using Xcode and the GLUT+OpenGL frameworks to compile the following code. [it's supposed to open a window and display a white square and triangle on a black backdrop.]:
Code:
#include <OpenGL/gl.h>
#include <OpenGL/glu.h>
#include <GLUT/glut.h>
#define kWindowWidth 800
#define kWindowHeight 300
GLvoid InitGL(GLvoid);
GLvoid DrawGLScene(GLvoid);
GLvoid ReSizeGLScene(int Width, int Height);
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize (kWindowWidth, kWindowHeight);
glutInitWindowPosition (100, 100);
glutCreateWindow (argv[0]);
InitGL();
glutDisplayFunc(DrawGLScene);
glutReshapeFunc(ReSizeGLScene);
glutMainLoop();
return 0;
}
GLvoid ReSizeGLScene(int width, int height) // Resize And Initialize The GL Window
{
if (height==0) // Prevent A Divide By Zero By
{
height=1; // Making Height Equal One
}
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
glLoadIdentity(); // Reset The Projection Matrix
// Calculate The Aspect Ratio Of The Window
gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,0.1f,100.0f);
glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
glLoadIdentity(); // Reset The Modelview Matrix
}
GLvoid InitGL(GLvoid) // All Setup For OpenGL Goes Here
{
glShadeModel(GL_SMOOTH);
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClearDepth(1.0f); // Depth Buffer Setup
glEnable(GL_DEPTH_TEST); // Enables Depth Testing
glDepthFunc(GL_LEQUAL);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
}
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();
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
}
...I get a window but it's white with nothing in it. When I resize the window to particular sizes I can see the black background and square only but obviously something is still wrong...
The only code I can find is written in Objective-C and uses some NextStep stuff.
NeHe tutotirlas:
http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=02
http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=Mac_OS_X
Last edited by a moderator: