Page 1 of 2 12 LastLast
Results 1 to 10 of 19

Thread: initialize window

  1. #1
    Junior Member Newbie
    Join Date
    Jul 2003
    Posts
    14

    initialize window

    I know that to initialize openGL window, I have to have :

    glClearColor(0,0,0,0);
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
    glSwapBuffer();

    Then I draw some things in the windows. Now my problem is, how would I clear the window again? How do I make them all back to black again?
    I did try that 3 lines of codes again, it only flashed me with black color for maybe .1 sec then go back to the same screen that I already drew things.

  2. #2
    Member Contributor
    Join Date
    Mar 2003
    Location
    Suffolk, United Kingdom
    Posts
    99

    Re: initialize window

    You should do -

    glClearColor();
    glClear(); // clears back-buffer

    // draw stuff here (goes in back buffer)

    SwapBuffers(); // swaps back buffer to screen

    Does that make sense?

    [This message has been edited by Rog (edited 07-09-2003).]

  3. #3
    Junior Member Newbie
    Join Date
    Jul 2003
    Posts
    14

    Re: initialize window

    yea i've tried that, in fact, this is what i tried but the old drawing still there, i don't know if i missunderstood the concept.

    cout << "one\n";
    glClearColor(0,0,0,0);
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
    glutSwapBuffers();
    cout << "two\n";
    glClearColor(0,0,0,0);
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
    glutSwapBuffers();
    cout << "three\n";
    glClearColor(0,0,0,0);
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
    glutSwapBuffers();

    it went through and printed out one,two,three (in the console/dos/whatever u call it); but in the openGL window, the drawing r still there.

  4. #4
    Member Contributor
    Join Date
    Mar 2003
    Location
    Suffolk, United Kingdom
    Posts
    99

    Re: initialize window

    Did you initialise glut to use double-buffering?

  5. #5
    Senior Member OpenGL Guru
    Join Date
    Jun 2000
    Location
    Gastonia, NC, USA
    Posts
    2,068

    Re: initialize window

    How about posting more of your code, because that will clear the window.
    But you must have somewhere in your code, calling the drawing routine after the clear.


    Normaly...

    clear screen

    draw something

    swapbuffers


    Originally posted by kentut:
    I know that to initialize openGL window, I have to have :

    glClearColor(0,0,0,0);
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
    glSwapBuffer();

    Then I draw some things in the windows. Now my problem is, how would I clear the window again? How do I make them all back to black again?
    I did try that 3 lines of codes again, it only flashed me with black color for maybe .1 sec then go back to the same screen that I already drew things.

  6. #6
    Senior Member Regular Contributor
    Join Date
    May 2002
    Location
    York, UK
    Posts
    128

    Re: initialize window

    Godo idea is to get some code from the various tutorials on the net ...

    e.g. nehe.gamedev.net

    Rob

  7. #7
    Junior Member Newbie
    Join Date
    Jul 2003
    Posts
    14

    Re: initialize window

    Yea I use double buffering
    Here's my code :

    ////////////////////////////

    void options()
    {
    cout << "one\n";
    glClearColor(0,0,0,0);
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
    glutSwapBuffers();
    cout << "two\n";
    glClearColor(0,0,0,0);
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
    glutSwapBuffers();
    cout << "three\n";
    glClearColor(0,0,0,0);
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
    glutSwapBuffers();
    }

    ///////////////////////////////

    void main_option()
    { /* some drawing, and make the value of icon_move to be -6 or -9 so that it goes to the keyboardfunc then keyboardfunc call options func */ }

    ///////////////////////////////

    void display()
    {
    glEnable(GL_DEPTH_TEST);
    glClearColor(0,0,0,1);
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    gluLookAt(0,0,5,0,0,0,0,1,0);

    main_options();

    glutSwapBuffers();
    }

    ////////////////////////////////

    void key(unsigned char key, int x, int y)
    {
    switch(key) {
    case 13:
    switch(icon_move) {
    case -6:
    options();
    break;
    case -9:
    exit(0);
    break;
    }
    glutPostRedisplay();
    }

  8. #8
    Junior Member Newbie
    Join Date
    Jul 2003
    Posts
    14

    Re: initialize window

    I must have drawing routine after clear the window? Just say I have to do something like:

    GLfloat black[] = {0,0,0,1};
    glMaterialfv(GL_FRONT,GL_AMBIENT,black);
    glutSolidCube(1);

    like that?

  9. #9
    Senior Member OpenGL Guru
    Join Date
    Jun 2000
    Location
    Gastonia, NC, USA
    Posts
    2,068

    Re: initialize window

    Your code does not make any sense, why are you calling clear screen so many times? also all the swap buffers call's?

    Also with material function, you have to enable lighting for it to work and enable the material function also.
    If you want to just have a colored cube, use glColor command.

    If you are drawing one object and it is not moving then you don't need double buffers.
    You clear the screen each time your draw because you would be writing on top of the previous image if you don't clear it.

    I must have drawing routine after clear the window? Just say I have to do something like:
    Yes, because if it draw before the clear window you drawing will be earsed.

    What is it you are trying to do?
    Maybe work as suggested with some examples programs to get an understanding of 3D graphics and openGL functions.

    Look at some of my glut examples on my website.
    www.angelfire.com/linux/nexusone/


    Originally posted by kentut:
    I must have drawing routine after clear the window? Just say I have to do something like:

    GLfloat black[] = {0,0,0,1};
    glMaterialfv(GL_FRONT,GL_AMBIENT,black);
    glutSolidCube(1);

    like that?

  10. #10
    Junior Member Newbie
    Join Date
    Jul 2003
    Posts
    14

    Re: initialize window

    Originally posted by nexusone:
    Your code does not make any sense, why are you calling clear screen so many times? also all the swap buffers call's?

    Because I can't clear my windows. Even after 3 times of clearing it, it still shows me the drawing I have instead of black screen.

    Originally posted by nexusone:
    Also with material function, you have to enable lighting for it to work and enable the material function also.
    If you want to just have a colored cube, use glColor command.

    If you are drawing one object and it is not moving then you don't need double buffers.
    You clear the screen each time your draw because you would be writing on top of the previous image if you don't clear it.

    No I actually have some lighting and some movement. I just cut some of my code so that the code is not too long and shows only the part that is relevant to clearing the window.

Page 1 of 2 12 LastLast

Similar Threads

  1. How to initialize GL 1.0 pointers with GL3.h
    By M/\dm/\n in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 11-26-2009, 12:27 PM
  2. Replies: 1
    Last Post: 10-02-2001, 10:11 AM
  3. How initialize an open gl window in visual c++6
    By frog in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 01-24-2001, 11:08 AM
  4. How to initialize and use Voodoo2??
    By HoHo in forum OpenGL: Basic Coding
    Replies: 6
    Last Post: 01-13-2001, 10:22 AM
  5. Replies: 6
    Last Post: 12-04-2000, 11:48 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean