Skip to main content
GameDev.net gamedev.net
🔒 Locked

basic problem, help please!

Started by kevthecelt Apr 11, 2005 at 7:22 AM 5 replies 1.5k views
Original Post
kevthecelt
kevthecelt
ok, the lesson 32 tutorial, i have commented pretty much everything out in the main draw method to try and debug my problem bit by bit, but im really confused, all i wanna do is draw a red square, but when i compile it, it wont draw, its just a black screen, here is the code, any help would be really really appreciated as i dont know whats going on void Draw(void) { glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); glTranslatef(0.0f,0.0f,-5.0f); glBegin(GL_QUADS); glColor3f(1.0f,0.0f,0.0f); glVertex3f(-1.0f, 1.0f, 0.0f); // Top Left glVertex3f( 1.0f, 1.0f, 0.0f); // Top Right glVertex3f( 1.0f,-1.0f, 0.0f); // Bottom Right glVertex3f(-1.0f,-1.0f, 0.0f); // Bottom Left glEnd(); glFlush(); } as you can see its just a basic square thats supposed to be drawn on screen but its not working and im really confused, i get no errors when i compile, and when it runs its just a black screen,
go hard or go home :)
lemurion
lemurion
did you call SwapBuffers() after _or_ at the end of your draw() function ? If you didn't, nothing will show up on the screen.

hope that helps !
Matt
Matt
AndiDog
AndiDog
If it doesn't help, call

glMatrixMode(GL_MODELVIEW);

before glLoadIdentity();
kevthecelt
kevthecelt
thanks for the replies lads, well now i have a different problem, i can now see my square on the screen, which is red, but now everything else seems to have a red color, its like its spilling out and colouring everthing else red, any ideas?? thanks in advance
go hard or go home :)
Custard Slice
Custard Slice
Opengl is a state machine so whatever the colour is set to will be used until Opengl is told different. Try putting a glColor3f(1.0f, 1.0f, 1.0f) after you have finished drawing the red square like so:

void Draw(void){glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);glLoadIdentity();glTranslatef(0.0f,0.0f,-5.0f);glBegin(GL_QUADS);glColor3f(1.0f,0.0f,0.0f);glVertex3f(-1.0f, 1.0f, 0.0f); // Top LeftglVertex3f( 1.0f, 1.0f, 0.0f); // Top RightglVertex3f( 1.0f,-1.0f, 0.0f); // Bottom RightglVertex3f(-1.0f,-1.0f, 0.0f); // Bottom Left// set the current colour to whiteglColor3f(1.0f,1.0f,1.0f);glEnd();glFlush();}


This will set the current colour to be white which should give you the desired results.

EDIT: fixed code
kevthecelt
kevthecelt
excellent thank you very very much really really appreciate it :)
go hard or go home :)
funNgame
funNgame
glBegin(GL_QUADS);
glColor3f(1.0f,0.0f,0.0f);
glVertex3f(-1.0f, 1.0f, 0.0f); // Top Left
glVertex3f( 1.0f, 1.0f, 0.0f); // Top Right
glVertex3f( 1.0f,-1.0f, 0.0f); // Bottom Right
glVertex3f(-1.0f,-1.0f, 0.0f); // Bottom Left

You want to draw in a counter clock direction for the QUAD to face you.
glBegin(GL_QUADS);
glColor3f(1.0f,0.0f,0.0f);
//glVertex3f(-1.0f, 1.0f, 0.0f); // Top Left
glVertex3f( 1.0f, 1.0f, 0.0f); // Top Right
glVertex3f(-1.0f, 1.0f, 0.0f); // Top Left
//glVertex3f( 1.0f,-1.0f, 0.0f); // Bottom Right
glVertex3f(-1.0f,-1.0f, 0.0f); // Bottom Left
glVertex3f( 1.0f,-1.0f, 0.0f); // Bottom Right

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.