Hey, i’m currently trying to learn OpenGL and therefore I want to write a extremly simple pong game. I’m using Mac OSX 10.6.4 and Cocoa. This is what the output of the code looks like:
And this is my code:
@implementation OpenGLView
- (void)prepareOpenGL {
glClearColor(0, 0, 0, 1);
}
- (void)reshape {
CGFloat width = self.bounds.size.width;
CGFloat height = self.bounds.size.height;
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, width, 0, height, -1, 1);
}
- (void)drawRect:(NSRect)dirtyRect {
CGFloat width = self.bounds.size.width;
CGFloat height = self.bounds.size.height;
glMatrixMode(GL_MODELVIEW);
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1, 1, 1);
glBegin(GL_LINES);
{
glVertex2f(0, height/2.0);
glVertex2f(width, height/2.0);
}
glEnd();
glBegin(GL_QUADS);
{
glVertex2f(paddle1.offset, 0);
glVertex2f(paddle1.offset + paddle1.width, 0);
glVertex2f(paddle1.offset, paddle1.height);
glVertex2f(paddle1.offset + paddle1.width, paddle1.height);
}
glEnd();
glBegin(GL_QUADS);
{
glVertex2f(100, 100);
glVertex2f(200, 100);
glVertex2f(100, 200);
glVertex2f(200, 200);
}
glEnd();
glFlush();
}
@end
I think this is not supposed to look like this, I just want a simple rectangle. Can somebody please tell me what I’m doing wrong?
thank you!