OpenGL help!

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

  1. macrumors 6502a

    Joined:
    Dec 29, 2009
    #1
    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:
    Code:
    - (void)drawRect:(NSRect)dirtyRect {
    	//Clear the view with the current clearing color
    	glClear(GL_COLOR_BUFFER_BIT);
    	//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
    	glFlush();
    	//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?
    Thanks
    Blake
     
  2. macrumors 68000

    Joined:
    Mar 29, 2009
    Location:
    USA
    #2
    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

    jared_kipe

    Joined:
    Dec 8, 2003
    Location:
    Seattle
    #3
    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

    Joined:
    Mar 29, 2009
    Location:
    USA
  5. thread starter macrumors 6502a

    Joined:
    Dec 29, 2009
    #5
    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. thread starter macrumors 6502a

    Joined:
    Dec 29, 2009
    #6
    Figured it out Thanks
     
  7. macrumors 68000

    Joined:
    Mar 29, 2009
    Location:
    USA
    #7
    What was the fix?
     
  8. thread starter macrumors 6502a

    Joined:
    Dec 29, 2009
    #8
    I found a different way to do it
     
  9. macrumors 6502a

    Joined:
    Sep 30, 2001
    #9
    Your projection or modelview matrix is wrong.
     

Share This Page