PDA

View Full Version : My first glut window is see-through!!



NewbieBen
06-28-2001, 03:47 AM
I am just taking my first steps in open gl.
I will be using it for my Msc project.

My problem is, i can create a window using glut, and position it and size it correctly.

But i cannot display anything in it.
Even though i have set glClearColor to black, and used glclear(colorbufferbit), it doesnt go black. It is totally transparent and takes a snapshot of the desktop(icons and wall paper).

have a look at the code in my reply below!.
Can anyone see any problems?

I am using Borland C++ builder 4 and glut!!
I have set up the project as a console project.

Is it something to do with DC's or RC's. I thought glut took care of all that for you??

Is my Graphics card just crap(most games using opengl seem to work ok)
Please help!!



[This message has been edited by NewbieBen (edited 06-28-2001).]

Zeus_666
06-28-2001, 03:54 AM
Hi,
Have you set up the drawing function, if you have not, then you need to and in that function tell the program to clear the screen then depending on weather you are using double or single buffering add

Single buffering - glFlush ();
double buffering - glSwapBuffers ();

NewbieBen
06-28-2001, 04:26 AM
I think i have done all of that. The code has come from the red book mostly!

The resize function,the fullscreen function all work ok. The window is being displayed, but it is not black!.

have a look at the code (it is short):


void init()
{
glEnable(GL_DEPTH_TEST);
glClearColor(0.0,0.0,0.0,0.0);

}

void display()
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);


glPushMatrix();


glColor3f(1.0,1.0,1.0);
glOrtho(0.0,1.0,0.0,1.0,-1.0,1.0);
glBegin(GL_POLYGON);
glVertex3f(0.25,0.25,0.0);
glVertex3f(0.75,0.25,0.0);
glVertex3f(0.75,0.75,0.0);
glVertex3f(0.25,0.75,0.0);
glEnd();

glPopMatrix();

glFlush();
}

int main(int argc, char* argv[])
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_RGB|GLUT_SINGLE);
glutInitWindowSize(250,250);
glutInitWindowPosition(100,100);
glutCreateWindow("hello");
init();
// glutReshapeFunc(reshape);
//glutKeyboardFunc(keyboard);
glutDisplayFunc(display);

glutMainLoop();

return 0;
}

Do i Have to tell it which window to draw to, is it clearing something else that isnt being displayed??

Or is it just my PC being crap!

Cheers for the reply so far.

NewbieBen
06-28-2001, 05:31 AM
Hey Zeus 666.

If you are still out there, can u have a look at my code please.

I am stumped!!

Cheers for looking

Deiussum
06-28-2001, 05:41 AM
I ran your code and it worked just fine for me. What do you have for a video card and OS?

NewbieBen
06-28-2001, 04:45 PM
help me anyone?

Please.
What is goin on?

Surely i havent stumped you all?

NewbieBen
06-28-2001, 04:49 PM
AH Dieussium.
Firstly cheers for replying.
Secondly, I am using windows 98 i think.
The graphics card is an 8 meg ATI rage pro.
Pretty old and crusty, but then im not asking it to do too much.
Could it be a driver problem or something.

[This message has been edited by NewbieBen (edited 06-28-2001).]

NewbieBen
06-29-2001, 03:56 AM
Cheers for looking guys.
Deiussum, i checked out my card and the drivers. It was just a Driver problem, and everything works fine now after a 45 minute download.

Why is it always the last thing you check is the one that saves you?

Anyway, im gonna start playing with some graphics code now. Im working for the whole Summer on this project, so dont be surprised to hear from me again!!!

Many thanks people!

ffish
06-29-2001, 04:38 AM
One more thing to learn about quickly NewbieBen. You would typically call glOrtho (or glFrustum or gluPerspective) in your GLUT reshape function and you'd call them on your GL_PROJECTION matrix. The projection matrix handles all your viewing volume type stuff and the (default) GL_MODELVIEW matrix handles all your modelling and drawing code. It's important to distinguish between them. If you're going to be doing OpenGL stuff all summer, I'd advise buying the red book (OpenGL Programming Guide Third Edition - The Official Guide to Learning OpenGL, Version 1.2) and pretty much reading it cover to cover. There are older editions online if you search. BTW, you may have to change your user name if you're gonna be posting all summer http://www.opengl.org/discussion_boards/ubb/wink.gif

dhoffman
06-29-2001, 09:02 AM
I think that most people don't check any more things after they have checked the thing that saved them because they have already been saved and that is normally why the last thing checked is always the one that saves you. Duhhhhhhh!
As for me, usually the last thing I check is also the first thing I check.
Arrr, shiver me timbers!

NewbieBen
07-02-2001, 01:48 PM
Thanks a lot everyone.

I got the red book and am just getting to grips with a bit of animation.

Many thanks for the info on GLU Matrixes and that glu Ortho. Am i right in thinking that i can use GLU ortho to scale the window?

So that maybe i can use it to always get a best view of an object/scene.

So many questions at the moment, but its still all new to me!!

ffish
07-02-2001, 05:32 PM
It's best to use other functions to "scale" your window (glTranslate, glScale). Also look into the glFrustum and gluPerspective calls. IMHO they set up a much nicer viewing volume. glOrtho is typically used for more specialised applications (CAD, HUDs)

Hope that helps.