News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

Can't get a rendering context, wglCreateContext fails

Started by hamper, November 11, 2013, 10:30:52 PM

Previous topic - Next topic

hamper

dedndave,

Looks good to me, but you should really get out of the habit of using "dd". We all should be using "dword" now.

dedndave

lol - ok
but - mine works and yours doesn't   :lol:

testing your code a bit...........

i created the structure the same way you did, in the initialized data section
the displayed context handle was, again, non-zero
so - that part is ok

i also changed my code to use wglChoosePixelFormat and wglSetPixelFormat,
rather than ChoosePixelFormat and SetPixelFormat
no problem - that part is ok
(i suspect the wgl calls are just wrappers that call the GDI equiv)

there appears to be only 1 other main difference in my code and yours that might be causing the problem
that is that i perform the GL initialization during WM_CREATE
and - you perform the initialization before the message loop

hope that was helpful

dedndave

by the way
here is the second test program
maybe you can see something i missed

dedndave

out of curiosity, i decided to try the code you posted in Reply #2
i added a Beep for successful creation
it seems to work ok, here (EDIT: well, no triangle)
perhaps there is something amiss with your import libraries or build batch file ?

hamper

Hi again dedndave,

That's interesting, and maybe the cause of the problem??

According to the API:
"The WM_CREATE message is sent when an application requests that a window be created by calling the CreateWindowEx or CreateWindow function. The window procedure of the new window receives this message after the window is created, but before the window becomes visible. The message is sent before the CreateWindowEx or CreateWindow function returns."

Now my window is already up and running on the desktop before the message box arrives informing me that getting a rendering context failed. So the WM_CREATE message has already been sent, but I have not processed it before asking for a rendering context. That sounds promising, and possibly the cause of the problem? So I'm guessing that the current sequence of my program is:

WM_CREATE message gets sent, but not yet processed
CreateWindowEx creates and displays the window
   (the way I have coded it, it automatically displays the window on the desktop as part of the function call)
So if the window has been created and displayed already, has the WM_CREATE message been processed yet?
I guess it must have been (somehow), to create and display the window. But not in my message loop?
But somewhere in the meantime, I've asked for a rendering context for a window that may or may not have been created yet.

Oh boy am I confused now?

I'll have to try processing the WM_CREATE message first, before asking for a rc. Maybe that's the solution??


dedndave

ok - here's a kicker   :redface:

when i closed your window, i noticed a brief image
i wasn't able to capture it to make a screen-shot
but, i added a few Sleep calls to observe
interestingly enough, i see a triangle in there   :P

GoneFishing

Quote from: dedndave on November 12, 2013, 06:58:19 AM
out of curiosity, i decided to try the code you posted in Reply #2
i added a Beep for successful creation
it seems to work ok, here (EDIT: well, no triangle)
perhaps there is something amiss with your import libraries or build batch file ?

No Beep here , Dave  - Could not get rendering context
Interestingly that when the function succeeded the eax is always (well , at least in 3 different implementations - yours, mine and in masm example)  00010000

Quote from: dedndave on November 12, 2013, 07:12:35 AM
ok - here's a kicker   :redface:

when i closed your window, i noticed a brief image
i wasn't able to capture it to make a screen-shot
but, i added a few Sleep calls to observe
interestingly enough, i see a triangle in there   :P

no luck here again

dedndave

probably means that it's not a "real" windows device context
it's a context, as defined in openGL, which is likely nothing more than filled-in structure,
which includes the actual HDC created within the library code

hamper

Well I don't.


Here's a summary of my original post so far:

I still don't know what's wrong with my original program.
Window gets created and displayed.
Message box gets displayed, announcing that the request for a rendering context has failed.
No definitive answer or analysis so far as to why this happens.
No one likes my programming.
Time for bed.
Later
lol

dedndave

nothing personal about your code
it's just that we get used to seeing things a certain way
and it becomes fast and easy to spot errors when done that way
when someone comes along and writes without using pre-defined contants, etc, it's harder to find problems
believe me, your not the first one to do it that way

i don't have much experience with OpenGL, but would like to learn, also
so - maybe i'll play with this a little more later in the day

GoneFishing

Obviously , it works when called inside WM_CREATE handler routine
Let's make a little  surprise to hamper and draw a nice multicolored triangle for his awakening (sounds a bit
philosophical though)  next morning ?  :biggrin:

Farabi

Tell me if this doesnot worked on your.

Quote
fEnableOpenGL proc uses esi edi hWnd:dword,lphDC:dword,lpwRC:dword
   LOCAL pfd:PIXELFORMATDESCRIPTOR
   LOCAL iFormat:dword
   LOCAL fwglChoosePixelFormatARB:dword
   LOCAL valid:dword
   LOCAL pixformat,numformat:dword
   LOCAL buff[256]:Dword
   
      invoke memfill,addr pfd,sizeof    PIXELFORMATDESCRIPTOR,0
      invoke GetDC,hWnd
      mov esi,lphDC
      push eax
      pop [esi]
      mov edi,lpwRC
      mov pfd.nSize,sizeof PIXELFORMATDESCRIPTOR
      mov pfd.nVersion,1
      mov pfd.dwFlags, PFD_DRAW_TO_WINDOW or PFD_SUPPORT_OPENGL or PFD_DOUBLEBUFFER  ;or PFD_DRAW_TO_BITMAP or PFD_SUPPORT_GDI
      mov pfd.iPixelType,PFD_TYPE_RGBA
      mov pfd.cColorBits,24
      mov pfd.cDepthBits,16
      mov pfd.iLayerType,PFD_MAIN_PLANE
      mov pfd.cStencilBits,8
      mov pfd.cAccumBits,24
      
      invoke ChoosePixelFormat,[esi],addr pfd
      .if eax==0
         invoke MessageBox,hWnd,CADD("Failed at ChoosePixelFormat Function"),0,0
         ret
      .endif
      mov iFormat,eax
      invoke SetPixelFormat,[esi],iFormat,addr pfd
      .if eax==FALSE
         invoke MessageBox,hWnd,CADD("Failed at SetPixelFormat Function"),0,0
         ret
      .endif
      
      invoke wglCreateContext,[esi]
      .if eax==0
         invoke MessageBox,hWnd,CADD("Failed at wglCreateContext Function"),0,0
         ret
      .endif
      push eax
      pop [edi]
      
      invoke wglMakeCurrent,[esi],[edi]
      .if eax==FALSE
         invoke MessageBox,hWnd,CADD("Failed at wglMakeCurrent Function"),0,0
         ret
      .endif
      ret
   
      invoke fEnableMultiSampling
      .if eax!=-1
         invoke wglGetProcAddress,CADD("wglChoosePixelFormatARB")
         .if eax==0
            invoke MessageBox,0,CADD("No wglChoosePixelFormatARB detected"),0,0
         .endif
         ; Multi Sample Anti aliasing is available
         mov fwglChoosePixelFormatARB,eax
         
         lea eax,numformat
         push eax
         lea eax,pixformat
         push eax
         push 1
         push offset fAttributes
         push offset iAttribute
         mov eax,lphDC
         push [eax]
         call fwglChoosePixelFormatARB
      ;   add esp,6*4
         mov valid,eax
         
         .if valid==TRUE
            .if numformat>1
               
            .endif
         .endif
         
      .else
      ;   invoke MessageBox,0,CADD("No Multi Sample detected"),0,0
      .endif
   
   ret
fEnableOpenGL endp
http://farabidatacenter.url.ph/MySoftware/
My 3D Game Engine Demo.

Contact me at Whatsapp: 6283818314165

GoneFishing


Farabi

Here is how to use it

invoke fEnableOpenGL,hWnd,addr hDC,addr hRC


Make sure hDC and hRC is on .data section. If you able to run above code, I'll give you all of my tools, and I will guide you into creating a rendering engine.

Use this as a framework https://www.asuswebstorage.com/navigate/s/04AAECE4836447E29B9E0A0AAA5D13DCY
Use RadAsm and edit the MainSection procedure to start making a rendering engine, it can load a 3D models called TRI Format. I'll upload the exporter for the tri format tools.
http://farabidatacenter.url.ph/MySoftware/
My 3D Game Engine Demo.

Contact me at Whatsapp: 6283818314165

GoneFishing

#29
...