opengl DC question

This is a discussion on opengl DC question within the Game Programming forums, part of the General Programming Boards category; Hi every1; Ok, im done on reviewing vector math. now im reading this code in this book"game programming with opengl". ...

  1. #1
    Registered User SAMSAM's Avatar
    Join Date
    Nov 2001
    Posts
    218

    opengl DC question

    Hi every1;

    Ok, im done on reviewing vector math.

    now im reading this code in this book"game programming with opengl". i have 3 questions for three parts.

    i broke the parts in 3 sections.

    Code:
    HDC  g_HDC                //global  DC
    question 1:is this device context similar in concept to the hdc memory context that we create in win API to write onto (like in
    DDB bitmap functions , bitblt ,,stretchblt)?


    Code:
    HGLRC  hRC;
    HDC  hdc;
    ////////////
    
    case WM_CREATE:
    
    hdc = GetDC(hwnd);
    g_HDC = hdc;
    SetupPixelFormat(hdc);
    
    
    hRC = wglCreateContext(hdc);
    wglMakeCurrent(hdc, hRC);
    
    return 0;
    break;
    question 2: why there is no ReleaseDC(hwnd, hdc); function
    in the above code. as its routily done in win API?


    then in the body of opengl code during rendering phase we have:

    Code:
    //////////////
    glTranslatef(,,,,,,,,,,,,,);
    glRotatef(,,,,,,,,,,,,,,,,,);
    glColor3f(,,,,,,,,,,,,,,,,,,);
    glBegin(GL_TRIANGLE);
    glVertex3f(,,,,,,,,,,,,,,,,)
    
    glVertex3f(,,,,,,,,,,,,,,,,)
    
    glVertex3f(,,,,,,,,,,,,,,,,)
    
    glEnd();
    
    SwapBuffers(g_HDC);       //bring back buffer to forground
    
    TranslateMessage(&msg);
    DispatchMessage(&msg);
    
    ///////////////////////////
    *if answer to question 1 is yes disregard this one.

    question 3: why couldnt we simply make hdc global like;

    HDC hdc;

    and use it throuout the program so we dont need a second copy of it as g_HDC .? is it because we have to have 2 different device context , one for window procedure and one for opengl calls
    .so how come they are identical?

    why there is no ReleaseDC function for g_HDC neither?


    thanks
    silver or travis should know these.
    Last edited by SAMSAM; 02-24-2003 at 12:45 PM.

  2. #2
    Registered User
    Join Date
    Sep 2002
    Posts
    1,640
    question: why there is no ReleaseDC(hwnd, hdc); function
    in the above code. as its routily done in win API?
    It's done to clear up the memory taken by the Device Context,
    It's not required, But it's nice,safer and more stable to do so.

    question: why couldnt we simply make hdc global like;
    Matter of opinion, What suits you best...

    why there is no ReleaseDC function for g_HDC neither?
    Same reason.

  3. #3
    Banned
    Join Date
    Jan 2003
    Posts
    1,708
    silver or travis should know these.
    to be quite honest with ya I never paid all that much attention to that device context stuff. I learned enough to be able to write my own opengl enabled window, but then I was like 'ok good enough time to move on to some real opengl' and I have been using NeHe's basecode ever since

  4. #4
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,859
    >> question 1:is this device context similar in concept to the hdc memory context that we create in win API to write onto (like in
    DDB bitmap functions , bitblt ,,stretchblt)?

    it is exactly the same


    >>question 2: why there is no ReleaseDC(hwnd, hdc); function
    in the above code. as its routily done in win API?

    I think you will find a ReleaseDC() in the clean up ie WM_CLOSE / DeInit() if from gametutorials.com

    >> It's not required, But it's nice,safer and more stable to do so.

    AFAIK it is required. It is allocating a resouce which must be freed. As it is once per app instance it will be a small leak and probably cleaned up by windows. Put that into a msg like WM_PAINT and see what happens.

    >>question 3: why couldnt we simply make hdc global like;

    g_ is from Hungarian notation

    g_iVariable would be a global int
    g_dwVariable would be a global DWORD ect
    Last edited by novacain; 02-25-2003 at 10:06 PM.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  5. #5
    Registered User SAMSAM's Avatar
    Join Date
    Nov 2001
    Posts
    218
    thx nova .

    but there is no deinit() function ,anywhere in the code.
    and there is none in WM_CLOSE section:

    case WM_CLOSE:

    wglMakeCurrent(hdc, NULL);
    wglDeleteContext(hRC);
    PostQuitMessage(0);
    return 0;
    break;

    in fact this book is a little bit loose on details(passive on some major opengl concept) and general rule.


    ie:some of the codes actually dont perform their purpose;

    chapter 4-->if u push VK_ESCAPE, nothing happens.

    i had to create WM_KEYDOWN and move VK_ESCAPE from WM_CHAR , to be able to use the escape option.

    and a few others.

    nehe tutorial done in a few pages. is much more efficient and generous on details ,with no warning and errors than this book of 800 pages(to be fair ,the 2 ppl who wrote ,know what they
    are teaching but they are not relaying it very well)

    by the way about global;
    if i declare a variable like this:

    BOOL g_flip = TRUE;

    and later use it in the body of the code like this:

    if(flip == TRUE)

    or

    if(g_flip == TRUE)

    i noticed the compiler treat them as the same.
    is it true, that g_ part is not part of the variable,s name?

  6. #6
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,859
    from MSDN

    wglMakeCurrent(HDC , HGLRC );

    "If hglrc is NULL, the function makes the calling thread's current rendering context no longer current, and releases the device context that is used by the rendering context. In this case, hdc is ignored. "


    >>is it true, that g_ part is not part of the variable,s name?

    No. Hungarian notation is a system to help variable naming. The compiler does not treat the variable differently.

    in your example

    if(flip == TRUE)

    should be an undeclared variable just as if you had misspelled it.


    >>know what they are teaching but they are not relaying it very well

    its always a matter of finding a source of info that you can relate too.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  7. #7
    Registered User SAMSAM's Avatar
    Join Date
    Nov 2001
    Posts
    218
    thank you for doing my job (searching MSDN) for me.

    as they say "search first ask later".

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. OpenGL Camera Question
    By Astra in forum Game Programming
    Replies: 2
    Last Post: 03-25-2007, 01:53 PM
  2. first opengl game, problems.
    By n3v in forum Game Programming
    Replies: 1
    Last Post: 07-11-2006, 08:22 PM
  3. OpenGL question
    By sand_man in forum Game Programming
    Replies: 4
    Last Post: 11-08-2004, 06:05 AM
  4. OpenGL question
    By rayrayj52 in forum Game Programming
    Replies: 6
    Last Post: 11-07-2004, 02:54 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21