Opengl doesnt work

hello, I have this code

* simple.c
* This program draws a white rectangle on a black background.

/* E. Angel, Interactive Computer Graphics */

/* A Top-Down Approach with OpenGL, Third Edition */

/* Addison-Wesley Longman, 2003 */

#ifdef __APPLE__
#include <GLUT/glut.h>
#include <GL/glut.h> /* glut.h includes gl.h and glu.h*/

void display(void)

/* clear window */


/* draw unit square polygon */

glVertex2f(-0.5, -0.5);
glVertex2f(-0.5, 0.5);
glVertex2f(0.5, 0.5);
glVertex2f(0.5, -0.5);

/* flush GL buffers */



void init()

/* set clear color to black */

/* glClearColor (0.0, 0.0, 0.0, 0.0); */
/* set fill color to white */

/* glColor3f(1.0, 1.0, 1.0); */

/* set up standard orthogonal view with clipping */
/* box as cube of side 2 centered at origin */
/* This is default view and these statement could be removed */

/* glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0); */

int main(int argc, char** argv)

/* Initialize mode and open a window in upper left corner of screen */
/* Window title is name of program (arg[0]) */

/* You must call glutInit before any other OpenGL/GLUT calls */
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);


and it does not work on my mac using xcode. It has 13 erros saying things like "_glBegin", referenced from:
display() in File.o and at the end the last error is linker command failed with exit code 1 (use -v to see invocation).

Please help me, thank you!
The function "glBegin()" is a core part of the OpenGL library, did you remember to link to "Opengl32.lib" or "libopengl32.a"?

EDIT: Also copy paste the errors, it doesn't do anyone any good for us to guess at what you're talking about.
Last edited on
I am using xcode on mac, I hate mac! I am going to get a windows as soon as possible.

EDIT: And why is this error occuring? linker command failed with exit code 1 (use -v to see invocation
Last edited on
Because you need to link the libraries
┬┐which compiler are you using? for gcc it would be -l{GL,glut}
The bigger picture here is that you're trying to code in C++ without an understanding of what the tools do. You need to go back and learn what a compiler is and what it does to turn a single text file into a single binary object, and what a linker is and ow it turns many binary objects into a single library or executable.

If you knew the basics, you would ave been able to answer this question yourself. Understanding the basics will help you enormously in the future.
Topic archived. No new replies allowed.