Cocoa OpenGL...HELP!

Dogcow

Registered
I'm trying to use the example in /Developer/Examples/OpenGL/Cocoa/CocoaGL to draw a single pixel inside the MyOpenGLView. Does anyone have any experience trying to do this? I've simplified the drawRect function to:

- (void) drawRect: (NSRect) rect
{
glViewport(0, 0, (GLsizei) rect.size.width, (GLsizei) rect.size.height);
NSLog(@"Width: %f, Height: %f", rect.size.width, rect.size.height);

glClearColor(0.0, 0.0, 0.0, 0.0);

glClear(GL_COLOR_BUFFER_BIT+GL_DEPTH_BUFFER_BIT+GL_STENCIL_BUFFER_BIT);

glColor3f(1.0,1.0,1.0);
glVertex2f(50,50);

[[self openGLContext] flushBuffer];
}

I added these two lines...I though they'd draw a pixel:

glColor3f(1.0,1.0,1.0);
glVertex2f(50,50);

Any suggestions? I'd really appreciate it...

-Dogcow "moof!"
 
From what little OpenGL I remember, you'd have to enclose your call to glVertex between glBegin and glEnd:

Code:
glBegin(GL_POINTS);

 glColor3f(1.0,1.0,1.0);
 glVertex2f(50,50);

glEnd();

The glBegin() tells OpenGL what kind of things you want to draw using your glVertex()es. Among the other types for glBegin are GL_LINES, GL_TRIANGLES, and GL_QUADS.

I suggest you also visit the OpenGL forum at http://www.idevgames.com/forum/
 
Yeah, I thought I might need those...

However, even with that added, nothing shows up in the view other than the black background.

Ideas? CocoaGL is rather difficult since most OpenGL people don't know cocoa and most cocoa people don't know opengl... Any help would be appreciated...

Thanks,
-Dogcow "moof!"
 
Turns out what I was forgetting was the fact that I have to use values between -1 and 1... *oops*

-Dogcow "moof!
 
Back
Top