1. Welcome to the new MacRumors forums. See our announcement and read our FAQ

OpenGL help!

Discussion in 'Mac Programming' started by Blakeasd, Oct 6, 2010.

  1. macrumors 6502a

    I am working on an example out of the OpenGL super bible and I am having some problems. I am trying to draw a rectangle/square on top of the background.
    Here is my code:
    - (void)drawRect:(NSRect)dirtyRect {
    	//Clear the view with the current clearing color
    	//Set the current drawing color to red
    	//         R      G    B
    	glColor3f(1.0f, 0.0f, 0.0f);
    	//Draw a filled rectangle with the current color
    	glRectf(-25.0f, 25.0f, 25.0f, -25.0f);
    	//Flush drawing commands
    	//Set up the rendering state
    	glClearColor(0.0f, 0.0f, 1.0f, 1.0f);
    This is not working however. The book suggests I should use GLUT for my interface, however I like Cocoa. Does anyone know why this code is not working?
  2. macrumors 68000

    Define 'not working'

    Doesn't compile? Runs but doesn't draw what you want?

    Dumb question, but have you already initialized OpenGL elsewhere in your program?
  3. macrumors 68030


    Not a dumb question, first thing I thought of.

    This appears to be a subclass of NSView or some other NSView subclass. Generally one uses CGContext**** commands to draw in this method...
  4. macrumors 68000

  5. macrumors 6502a

    Yes, OpenGL is imported. The code works, but doesn't display the proper thing. It should display a small rectangle. It does not. I know the OpenGL is working because I can draw my background. Please help and thanks!
  6. macrumors 6502a

    Figured it out Thanks
  7. macrumors 68000

    What was the fix?
  8. macrumors 6502a

    I found a different way to do it
  9. macrumors 6502a

    Your projection or modelview matrix is wrong.

Share This Page