Results 1 to 7 of 7

Thread: Problem with stencil buffer in Win32 Console

  1. #1
    Junior Member Newbie
    Join Date
    Feb 2011
    Posts
    2

    Problem with stencil buffer in Win32 Console

    Hi everyone,

    I am a new member of the forum seeking a help from openGL seniors out there

    Currently, I am doing an assignment about shadowing drawing using stencil buffer. The algorithm is alright, but it seems that when I wrote it in the Win32 Console framework , the stencil buffer was not working/disabled somehow, even when I used glEnable(GL_STENCIL_TEST), leaving no shadow rendered. When I use the framework used in all NeHe popular tutorials - he used WIN32 API to create real windows application to draw, there is a function having an argument to control the stencil buffer (0 - disable, 1- enable) , then my code can run and the shadow is displayed.

    I want to ask what is the real cause of this issue and can I enable stencil buffer manually in console environment ?

    Sorry for my bad English , thank you all.

  2. #2
    Senior Member Regular Contributor
    Join Date
    Oct 2010
    Location
    France
    Posts
    458

    Re: Problem with stencil buffer in Win32 Console

    You must activate the stencil capabilities of your window.

    On Win32 you must set the pixel format to support it with something like this (sorry for french):

    Code :
    PIXELFORMATDESCRIPTOR pfd =
    { 	 
    sizeof(PIXELFORMATDESCRIPTOR), 	//taille du descripteur de format
    1, 	//version
    PFD_SUPPORT_OPENGL |
    PFD_DRAW_TO_WINDOW |
    PFD_DOUBLEBUFFER, 	//Propriété
    PFD_TYPE_RGBA, 	//Mode de couleurs
    16, 	//Bits de couleur
    0, 0, 0, 0, 0, 0, 	//Paramètres des couleurs
    0,0, 	//Paramètres alpha
    0,0, 0, 0, 0, 	//Paramètres du buffer d'accumulation
    24, 	//Bits de profondeur      <=== Depth Buffer should be 24
    8, 	//Bits du buffer stencil  <=== STENCIL SHOULD BE 8
    0, 	//Nombre de buffers auxiliaires
    0, 	//ignoré (obsolète)
    0, 	//réservé/code>
    0, 	//ignoré (obsolète)
    0, 	//Couleur de transparence
    0 	//Ignoré (obsolète)
    };

    Hope that helps.

  3. #3
    Senior Member Regular Contributor
    Join Date
    Apr 2009
    Posts
    268

    Re: Problem with stencil buffer in Win32 Console

    Make sure you pick a pixel format with stencil buffer.
    See what glGetIntegerv(GL_STENCIL_BITS, &amp;value); returns.

  4. #4
    Junior Member Newbie
    Join Date
    Feb 2011
    Posts
    2

    Re: Problem with stencil buffer in Win32 Console

    Thanks for the help guys , really appreciate it.
    @_arts: Your code setup is for Windows application, which is pretty similar to NeHE I think. Do you know how to create the same effect with Console environment, when you do not use such WIN API function.

    @kyle_: When I use your function to print out the value , I see a bunch of zero. My initial call is glClearStencil(1.0f). Is it normal ?

  5. #5
    Senior Member Regular Contributor
    Join Date
    Apr 2009
    Posts
    268

    Re: Problem with stencil buffer in Win32 Console

    If get integer with GL_STENCIL_BITS returns zero, it means you are on pixel format without stencil.

    Also, how do you even create your context if you dont use winapi???

    For that you need a handle to a window (well, DC) on which SetPixelFormat was called with pixel format id of pixel format that does have stencil - what arts said.

  6. #6
    Senior Member Regular Contributor
    Join Date
    Oct 2010
    Location
    France
    Posts
    458

    Re: Problem with stencil buffer in Win32 Console

    Quote Originally Posted by kse7en
    Thanks for the help guys , really appreciate it.
    @_arts: Your code setup is for Windows application, which is pretty similar to NeHE I think. Do you know how to create the same effect with Console environment, when you do not use such WIN API function.
    Whether you use Win32 console or Win32 with WinMain function, you must specify the pixel format, which should be done the same way for both.

  7. #7
    Newbie OpenGL Pro
    Join Date
    Jan 2007
    Posts
    1,789

    Re: Problem with stencil buffer in Win32 Console

    It sounds to me as though you're using a framework like GLUT or SDL to create your OpenGL context. Can you confirm if this is so before we continue?

Similar Threads

  1. Win32 or Console Environment?
    By Ehsan Nekooee in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 08-14-2009, 04:27 PM
  2. Win32 Console OpenGL?
    By Omaha in forum OpenGL: Basic Coding
    Replies: 5
    Last Post: 11-06-2001, 02:58 AM
  3. Win32 console app & win32 app?????
    By UT_jerryspringer in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 09-07-2001, 04:18 PM
  4. console app VS win32 app
    By fabmathews in forum OpenGL: Basic Coding
    Replies: 9
    Last Post: 08-21-2001, 03:08 PM
  5. Add Color in Win32 Console Application
    By Acer722 in forum OpenGL: Basic Coding
    Replies: 8
    Last Post: 06-26-2001, 08:38 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