The MASM Forum

General => The Campus => Topic started by: hamper on November 11, 2013, 10:30:52 PM

Title: Can't get a rendering context, wglCreateContext fails
Post by: hamper on November 11, 2013, 10:30:52 PM
I'm having a problem getting even a very simple OpenGL program to work. The problem is that the function wglCreateContext always fails, and returns zero. I can't see where the problem is, so can anyone spot where I'm going wrong? Help, please.
My system has no problem whatsoever running OpenGL .exe programs, so it can't be the video card or drivers etc.
And I've checked the program (with message boxes) up to the point where it fails, and everything seems to be working fine.
Getting exasperated.
Any ideas anyone?
Thanks in advance.


;--------------------------------------------------------------------------------------
; A simple OpenGL example                                                   ogltest.asm
;--------------------------------------------------------------------------------------

.686
.model flat,stdcall
option casemap:none

includelib user32
includelib kernel32
includelib opengl32

;--------------------------------------------------------------------------------------

CreateWindowExA      proto :dword,:dword,:dword,:dword,:dword,:dword,
                           :dword,:dword,:dword,:dword,:dword,:dword
DefWindowProcA       proto :dword,:dword,:dword,:dword
DispatchMessageA     proto :dword
ExitProcess          proto :dword
GetMessageA          proto :dword,:dword,:dword,:dword
GetModuleHandleA     proto :dword
LoadCursorA          proto :dword,:dword
LoadIconA            proto :dword,:dword
PostQuitMessage      proto :dword
RegisterClassExA     proto :dword
windowproc           proto :dword,:dword,:dword,:dword
GetDC                proto :dword
wglChoosePixelFormat proto :dword,:dword
wglSetPixelFormat    proto :dword,:sdword,:dword
wglCreateContext     proto :dword
wglMakeCurrent       proto :dword,:dword
wglDeleteContext     proto :dword
ReleaseDC            proto :dword,:dword
glBegin              proto :dword
glEnd                proto
glVertex2fv          proto :dword
MessageBoxA          proto :dword,:dword,:dword,:dword

point struct
   x dword ?
   y dword ?
point ends

msgst struct
   hwnd    dword ?
   message dword ?
   wparam  dword ?
   lparam  dword ?
   time    dword ?
   pt      point <>
msgst ends

windowclasstype struct
   wcsize        dword ?
   style         dword ?
   addrwp        dword ?
   classeb       dword ?
   windoweb      dword ?
   proghandle    dword ?
   liconhandle   dword ?
   cursorhandle  dword ?
   colour        dword ?
   menuhandle    dword ?
   addrclassname dword ?
   siconhandle   dword ?
windowclasstype ends

pfdtype struct
   nsize           word  40
   nversion        word  1
   dwflags         dword 36   ; PFD_DRAW_TO_WINDOW + PFD_SUPPORT_OPENGL
   ipixeltype      byte  0
   ccolorbits      byte  32
   credbits        byte  0
   credshift       byte  0
   cgreenbits      byte  0
   cgreenshift     byte  0
   cbluebits       byte  0
   cblueshift      byte  0
   calphabits      byte  0
   calphashift     byte  0
   caccumbits      byte  0
   caccumredbits   byte  0
   caccumgreenbits byte  0
   caccumbluebits  byte  0
   caccumalphabits byte  0
   cdepthbits      byte  32
   cstencilbits    byte  0
   cauxbuffers     byte  0
   ilayertype      byte  0
   breserved       byte  0
   dwlayermask     dword 0
   dwvisiblemask   dword 0
   dwdamagemask    dword 0
pfdtype ends

;--------------------------------------------------------------------------------------

.const
classname   byte "SimpleWinClass",0
windowtitle byte "The window title",0
mymbtitle   byte "Alert",0
mymbtext    byte "Could not get rendering context",0

.data?
msg       msgst <>
mywc      windowclasstype <>
winhandle dword ?
dchandle  dword ?
rchandle  dword ?

.data
pfd pfdtype <>
myvertex1 real4 0.0,0.0
myvertex2 real4 1.0,0.0
myvertex3 real4 0.5,0.87

.code
start:

;######################################################################################

;---------- fill up the window class structure variable and get the program handle etc.

mov mywc.wcsize,48
mov mywc.style,35                    ; CS_VREDRAW + CS_HREDRAW + CS_OWNDC
mov mywc.addrwp,offset windowproc
mov mywc.classeb,0
mov mywc.windoweb,0
push 0
call GetModuleHandleA
mov mywc.proghandle,eax
push 32515                           ; A black ! in a yellow triangle
push 0
call LoadIconA
mov mywc.liconhandle,eax
mov mywc.siconhandle,eax
push 32515                           ; A crosshair
push 0
call LoadCursorA
mov mywc.cursorhandle,eax
mov mywc.colour,2                    ; desktop colour
mov mywc.menuhandle,0
mov mywc.addrclassname,offset classname

;---------- register the window class

push offset mywc
call RegisterClassExA

;---------- create and display the window

push 0
push mywc.proghandle
push 0
push 0
push 340                           ; window height
push 320                           ; window width
push 230                           ; window top position
push 480                           ; window left position
push 269418496                     ; WS_VISIBLE + title bar, title, icon, icon menu,
                                   ;    min, max and close buttons, sizing borders
push offset windowtitle
push mywc.addrclassname
push 0                             ; default
call CreateWindowExA
mov winhandle,eax

;---------- get a device context

push winhandle
call GetDC
mov dchandle,eax

;---------- choose pixel format

push offset pfd
push dchandle
call wglChoosePixelFormat

;---------- set pixel format

push offset pfd
push eax
push dchandle
call wglSetPixelFormat

;---------- get rendering context (** FAILS **)

push dchandle
call wglCreateContext
mov  rchandle,eax


cmp eax,0
jne sofarsogood

push 0
push offset mymbtitle
push offset mymbtext
push 0
call MessageBoxA

sofarsogood:

; program WOULD now continue, but doesn't get this far
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: GoneFishing on November 11, 2013, 11:33:16 PM
Hi hamper,
It would be better if you posted the complete source code so we can reproduce the problem on our machines
and find out what's going wrong there .
You may use "code" tags to incapsulate your code into the post .

Take a look into the \MASM32\examples\exampl04\opengl example folder . Maybe it gives you some idea .

EDIT: pay attention to WM_CREATE handling routine of window procedure in the example code 
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: hamper on November 11, 2013, 11:54:18 PM
;--------------------------------------------------------------------------------------
; A simple OpenGL example                                                   ogltest.asm
;--------------------------------------------------------------------------------------

.686
.model flat,stdcall
option casemap:none

includelib user32
includelib kernel32
includelib opengl32

;--------------------------------------------------------------------------------------

CreateWindowExA      proto :dword,:dword,:dword,:dword,:dword,:dword,
                           :dword,:dword,:dword,:dword,:dword,:dword
DefWindowProcA       proto :dword,:dword,:dword,:dword
DispatchMessageA     proto :dword
ExitProcess          proto :dword
GetMessageA          proto :dword,:dword,:dword,:dword
GetModuleHandleA     proto :dword
LoadCursorA          proto :dword,:dword
LoadIconA            proto :dword,:dword
PostQuitMessage      proto :dword
RegisterClassExA     proto :dword
windowproc           proto :dword,:dword,:dword,:dword
GetDC                proto :dword
wglChoosePixelFormat proto :dword,:dword
wglSetPixelFormat    proto :dword,:sdword,:dword
wglCreateContext     proto :dword
wglMakeCurrent       proto :dword,:dword
wglDeleteContext     proto :dword
ReleaseDC            proto :dword,:dword
glBegin              proto :dword
glEnd                proto
glVertex2fv          proto :dword
MessageBoxA          proto :dword,:dword,:dword,:dword

point struct
   x dword ?
   y dword ?
point ends

msgst struct
   hwnd    dword ?
   message dword ?
   wparam  dword ?
   lparam  dword ?
   time    dword ?
   pt      point <>
msgst ends

windowclasstype struct
   wcsize        dword ?
   style         dword ?
   addrwp        dword ?
   classeb       dword ?
   windoweb      dword ?
   proghandle    dword ?
   liconhandle   dword ?
   cursorhandle  dword ?
   colour        dword ?
   menuhandle    dword ?
   addrclassname dword ?
   siconhandle   dword ?
windowclasstype ends

pfdtype struct
   nsize           word  40
   nversion        word  1
   dwflags         dword 36   ; PFD_DRAW_TO_WINDOW + PFD_SUPPORT_OPENGL
   ipixeltype      byte  0
   ccolorbits      byte  32
   credbits        byte  0
   credshift       byte  0
   cgreenbits      byte  0
   cgreenshift     byte  0
   cbluebits       byte  0
   cblueshift      byte  0
   calphabits      byte  0
   calphashift     byte  0
   caccumbits      byte  0
   caccumredbits   byte  0
   caccumgreenbits byte  0
   caccumbluebits  byte  0
   caccumalphabits byte  0
   cdepthbits      byte  32
   cstencilbits    byte  0
   cauxbuffers     byte  0
   ilayertype      byte  0
   breserved       byte  0
   dwlayermask     dword 0
   dwvisiblemask   dword 0
   dwdamagemask    dword 0
pfdtype ends

;--------------------------------------------------------------------------------------

.const
classname   byte "SimpleWinClass",0
windowtitle byte "The window title",0
mymbtitle   byte "Alert",0
mymbtext    byte "Could not get rendering context",0

.data?
msg       msgst <>
mywc      windowclasstype <>
winhandle dword ?
dchandle  dword ?
rchandle  dword ?

.data
pfd pfdtype <>
myvertex1 real4 0.0,0.0
myvertex2 real4 1.0,0.0
myvertex3 real4 0.5,0.87

.code
start:

;######################################################################################

;---------- fill up the window class structure variable and get the program handle etc.

mov mywc.wcsize,48
mov mywc.style,35                    ; CS_VREDRAW + CS_HREDRAW + CS_OWNDC
mov mywc.addrwp,offset windowproc
mov mywc.classeb,0
mov mywc.windoweb,0
push 0
call GetModuleHandleA
mov mywc.proghandle,eax
push 32515                           ; A black ! in a yellow triangle
push 0
call LoadIconA
mov mywc.liconhandle,eax
mov mywc.siconhandle,eax
push 32515                           ; A crosshair
push 0
call LoadCursorA
mov mywc.cursorhandle,eax
mov mywc.colour,2                    ; desktop colour
mov mywc.menuhandle,0
mov mywc.addrclassname,offset classname

;---------- register the window class

push offset mywc
call RegisterClassExA

;---------- create and display the window

push 0
push mywc.proghandle
push 0
push 0
push 340                           ; window height
push 320                           ; window width
push 230                           ; window top position
push 480                           ; window left position
push 269418496                     ; WS_VISIBLE + title bar, title, icon, icon menu,
                                   ;    min, max and close buttons, sizing borders
push offset windowtitle
push mywc.addrclassname
push 0                             ; default
call CreateWindowExA
mov winhandle,eax

;---------- get a device context

push winhandle
call GetDC
mov dchandle,eax

;---------- choose pixel format

push offset pfd
push dchandle
call wglChoosePixelFormat

;---------- set pixel format

push offset pfd
push eax
push dchandle
call wglSetPixelFormat

;---------- get rendering context (** FAILS **)

push dchandle
call wglCreateContext
mov  rchandle,eax


cmp eax,0
jne sofarsogood

push 0
push offset mymbtitle
push offset mymbtext
push 0
call MessageBoxA

sofarsogood:

; program WOULD now continue, but doesn't get this far

push rchandle
push dchandle
call wglMakeCurrent

push 4                  ; triangles
call glBegin
push offset myvertex1
call glVertex2fv
push offset myvertex2
call glVertex2fv
push offset myvertex3
call glVertex2fv
call glEnd

msgloopstart:
push 0
push 0
push winhandle
push offset msg
call GetMessageA
cmp eax,0
je msgloopend
push offset msg
call DispatchMessageA
jmp msgloopstart
msgloopend:
push 0
call ExitProcess

;######################################################################################

;---------- the window procedure

windowproc proc hwnd:dword,message:dword,wparam:dword,lparam:dword

cmp message,16 ; WM_CLOSE
je its16

; default processing
push lparam
push wparam
push message
push hwnd
call DefWindowProcA
ret

its16:
   push rchandle
   call wglDeleteContext
   push dchandle
   push winhandle
   call ReleaseDC
push 0
call PostQuitMessage
ret

windowproc endp

;--------------------------------------------------------------------------------------

end start
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: GoneFishing on November 12, 2013, 12:03:46 AM
Thanks hamper  :t
much better

Look what I did:
Quote
;---------- get rendering context (** FAILS **)

push dchandle
call wglCreateContext
mov  rchandle,eax

    push MB_OK
    push offset mymbtitle
    push LastError$()
    push 0
    call MessageBox

cmp eax,0
jne sofarsogood

push 0
push offset mymbtitle
push offset mymbtext
push 0
call MessageBoxA

and what I got:
QuoteThe pixel format is invalid

Think  :t
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: hamper on November 12, 2013, 12:59:07 AM
Ok, but any ideas why?
The functions wglChoosePixelFormat and wglSetPixelFormat don't return with any errors.
I also tried various combinations of values in the elements of the pfd, but nothing made any difference.
So at the moment I'm none the wiser, and still searching for the solution.
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: GoneFishing on November 12, 2013, 01:35:42 AM
Did you try to declare pfd like that?:
pfd PIXELFORMATDESCRIPTOR <>
Ok, no one here but you can make you wiser  ;)
Did you compared your source code with that in opengl example? Are there any differences?
Well, I intermixed them a little and made wglCreateContext  return status SUCCESS:

;--------------------------------------------------------------------------------------
; A simple OpenGL example                                                   ogltest.asm
;--------------------------------------------------------------------------------------

include \masm32\include\masm32rt.inc

includelib \masm32\lib\opengl32.lib

;--------------------------------------------------------------------------------------

CreateWindowExA      proto :dword,:dword,:dword,:dword,:dword,:dword,
                           :dword,:dword,:dword,:dword,:dword,:dword
DefWindowProcA       proto :dword,:dword,:dword,:dword
DispatchMessageA     proto :dword
ExitProcess          proto :dword
GetMessageA          proto :dword,:dword,:dword,:dword
GetModuleHandleA     proto :dword
LoadCursorA          proto :dword,:dword
LoadIconA            proto :dword,:dword
PostQuitMessage      proto :dword
RegisterClassExA     proto :dword
windowproc           proto :dword,:dword,:dword,:dword
GetDC                proto :dword
wglChoosePixelFormat proto :dword,:dword
wglSetPixelFormat    proto :dword,:sdword,:dword
wglCreateContext     proto :dword
wglMakeCurrent       proto :dword,:dword
wglDeleteContext     proto :dword
ReleaseDC            proto :dword,:dword
glBegin              proto :dword
glEnd                proto
glVertex2fv          proto :dword
MessageBoxA          proto :dword,:dword,:dword,:dword

point struct
   x dword ?
   y dword ?
point ends

msgst struct
   hwnd    dword ?
   message dword ?
   wparam  dword ?
   lparam  dword ?
   time    dword ?
   pt      point <>
msgst ends

windowclasstype struct
   wcsize        dword ?
   style         dword ?
   addrwp        dword ?
   classeb       dword ?
   windoweb      dword ?
   proghandle    dword ?
   liconhandle   dword ?
   cursorhandle  dword ?
   colour        dword ?
   menuhandle    dword ?
   addrclassname dword ?
   siconhandle   dword ?
windowclasstype ends

;--------------------------------------------------------------------------------------

.const
classname   byte "SimpleWinClass",0
windowtitle byte "The window title",0
mymbtitle   byte "Alert",0
mymbtext    byte "Could not get rendering context",0

.data?
msg       msgst <>
mywc      windowclasstype <>
winhandle dword ?
dchandle  dword ?
rchandle  dword ?

.data

PixFrm PIXELFORMATDESCRIPTOR <>
myvertex1 real4 0.0,0.0
myvertex2 real4 1.0,0.0
myvertex3 real4 0.5,0.87

.code
start:

;######################################################################################

;---------- fill up the window class structure variable and get the program handle etc.

mov mywc.wcsize,48
mov mywc.style,35                    ; CS_VREDRAW + CS_HREDRAW + CS_OWNDC
mov mywc.addrwp,offset windowproc
mov mywc.classeb,0
mov mywc.windoweb,0
push 0
call GetModuleHandleA
mov mywc.proghandle,eax
push 32515                           ; A black ! in a yellow triangle
push 0
call LoadIconA
mov mywc.liconhandle,eax
mov mywc.siconhandle,eax
push 32515                           ; A crosshair
push 0
call LoadCursorA
mov mywc.cursorhandle,eax
mov mywc.colour,2                    ; desktop colour
mov mywc.menuhandle,0
mov mywc.addrclassname,offset classname

;---------- register the window class

push offset mywc
call RegisterClassExA

;---------- create and display the window

push 0
push mywc.proghandle
push 0
push 0
push 340                           ; window height
push 320                           ; window width
push 230                           ; window top position
push 480                           ; window left position
push 269418496                     ; WS_VISIBLE + title bar, title, icon, icon menu,
                                   ;    min, max and close buttons, sizing borders
push offset windowtitle
push mywc.addrclassname
push 0                             ; default
call CreateWindowExA
mov winhandle,eax

invoke ShowWindow,winhandle,SW_SHOWNORMAL
invoke UpdateWindow,winhandle
call       DoEvents
ret



;######################################################################################

DoEvents PROC
LOCAL m:MSG
StartLoop: ; Check for waiting messages
invoke PeekMessage,ADDR m,0,0,0,PM_NOREMOVE
or eax,eax
jz NoMsg
invoke GetMessage,ADDR m,NULL,0,0
or eax,eax
jz ExitLoop
invoke TranslateMessage,ADDR m
invoke DispatchMessage,ADDR m
jmp StartLoop
NoMsg: ; No pending messages: draw the scene
;invoke DrawScene
jmp StartLoop
ExitLoop: mov eax,m.wParam
ret
DoEvents ENDP

;----------

comment *

DrawScene proc

YOUR DRAWING CODE HERE ;-)

DrawScene endp

*

;---------- the window procedure

windowproc  PROC hWin:DWORD,uMsg:DWORD,wParam:DWORD,lParam:DWORD
LOCAL WINRect:RECT
LOCAL PixFormat:DWORD

.if uMsg == WM_CREATE
invoke GetDC,hWin
mov dchandle,eax
mov ax,SIZEOF PixFrm
mov PixFrm.nSize,ax
mov PixFrm.nVersion,1
mov PixFrm.dwFlags,PFD_DRAW_TO_WINDOW or PFD_SUPPORT_OPENGL or PFD_DOUBLEBUFFER
mov PixFrm.dwLayerMask,PFD_MAIN_PLANE
mov PixFrm.iPixelType,PFD_TYPE_RGBA
mov PixFrm.cColorBits,8
mov PixFrm.cDepthBits,16
mov PixFrm.cAccumBits,0
mov PixFrm.cStencilBits,0
invoke ChoosePixelFormat,dchandle,ADDR PixFrm
mov PixFormat,eax
invoke SetPixelFormat,dchandle,PixFormat,ADDR PixFrm
or eax,eax
jz NoPixelFmt
invoke wglCreateContext,dchandle
mov rchandle,eax
                        fn MessageBox,0,LastError$(),"Last Error Text",MB_OK


NoPixelFmt:
return 0

.elseif uMsg == WM_SIZE
invoke GetClientRect,hWin,ADDR WINRect

return 0

.elseif uMsg == WM_CLOSE

mov eax,rchandle
or eax,eax
jz NoGlDC
; Delete our objects
invoke  wglDeleteContext,rchandle
                        invoke  ExitProcess,0
NoGlDC:
      invoke ReleaseDC,hWin,dchandle
      invoke DestroyWindow,hWin
return 0
.elseif uMsg == WM_DESTROY
invoke PostQuitMessage,NULL
return 0
.endif
invoke DefWindowProc,hWin,uMsg,wParam,lParam
ret

windowproc endp

;--------------------------------------------------------------------------------------

end start


runs a bit slowly 
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: hamper on November 12, 2013, 02:10:41 AM
I thank you for your efforts vertograd, but it doesn't leave me any the wiser.

Sure, I'm using my own names for things, like the pixel format descriptor structure type and the structure variable, but that shouldn't make any difference so long as the structure itself is properly defined, contains all the right elements in the right data types, and is correctly initialised - which I think it all is, unless you can spot an error somewhere?

And sure, I could just copy and paste one of the numerous example programs, then assemble it and it will probably work. But that's not really the point is it? I spent ages learning C, then ages learning assembly language, then ages more learning the Windows API and how to get a window operating on the desktop in both C and assembly language, and am now trying to learn how to program graphics using OpenGL. None of this is for profit, or for business reasons - just out of a personal interest in trying to learn things that I didn't know before.

I don't need double-buffering (yet) because all I'm trying to do is render a simple triangle into a window. I hope to expand into selecting (non-default) matrix modes, pushing and popping the matrix stack, performing transformations, and getting coloured perspective views etc. fairly soon, I hope. But for the moment I can't get even a triangle up :icon_redface:

So if I just want to draw a spinning, multi-coloured triangle and learn nothing about WHY it works, I could just fire up my C compiler with an example program designed by someone else, and call it that - done, so now put it all away.

Please don't think I'm being critical - I'm not, and I DO greatly appreciate your efforts. But what I really could do with some help on is whereabouts in MY program the fault lies.

Thanks
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: GoneFishing on November 12, 2013, 02:41:22 AM
Quote... So if I just want to draw a spinning, multi-coloured triangle and learn nothing about WHY it works, I could just fire up my C compiler with an example program designed by someone else ...
IMO it's probably the best way to start with opengl ...
Some time ago I started with DirectX in that manner . I found 4 tutorials from DirectX SDK translated into MASM:
Creating device
Rendering simple multicolored triangle, then spinning triangle  and so on
From them I knew about the structure of graphics application which has Init, Draw / Render,Cleanup routines etc.

... and it was a real fight with my first triangle ... and I won it  ;)
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: dedndave on November 12, 2013, 04:09:44 AM
first, use INVOKE rather than PUSH/PUSH/CALL
much easier to read - and much easier to debug   :t

second, rather than initializing the values of the pfd structure in the definition, do it in the data section
also - use the already defined structure and constants
    .DATA

pfd PIXELFORMATDESCRIPTOR <sizeof PIXELFORMATDESCRIPTOR,1,PFD_DRAW_TO_WINDOW or PFD_SUPPORT_OPENGL,PFD_TYPE_RGBA,32,,,,,,,,,,,,,,32,,,,,PFD_MAIN_PLANE,,>

otherwise, you can define pfd in the uninitialized data section and initialize it with code
the values you are currently using are most likely the reason the call is failing
it will be much easier to troubleshoot and update if you use the standard structure and constants

finally, rather than performing the OGL initialization in the main proc, between CreateWindowEx and the message loop,
perform it when the WndProc receives the WM_CREATE message
once the window has been created, it needs a message loop running to process messages

just because ChoosePixelFormat and SetPixelFormat are happy, doesn't mean wglCreateContext will be
they may very well accept values that CreateContext will not
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: hamper on November 12, 2013, 04:46:00 AM
"second, rather than initializing the values of the pfd structure in the definition, do it in the data section"
I understood that if values were assigned to structure elements in the declaration, then those values would become the default values when the variable is subsequently defined using <>. Are you saying that's incorrect?

PFD_MAIN_PLANE is the default (0) anyway.
PFD_TYPE_RGBA is the default (0) anyway.
Both are symbolic constants that simply get replaced by the actual values (0) by the preprocessor, as I understand it, so stating 0 has exactly the same effect as stating PFD_MAIN_PLANE does it not?

I always seem to come in for a lot of criticism because I prefer to use my own labels and tags, and because I prefer to use pushes and calls rather than the invoke method.
But apart from the fact that you don't like my programming "style", can you shed any light on my programming "content", and where the problem lies?
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: hamper on November 12, 2013, 04:49:40 AM
"just because ChoosePixelFormat and SetPixelFormat are happy, doesn't mean wglCreateContext will be
they may very well accept values that CreateContext will not"

Such as? The program content is fully presented, up to the point where the problem lies. Does anything stand out that would cause wglCreateContext to fail even though the pixel format is successfully chosen and set?
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: dedndave on November 12, 2013, 05:07:11 AM
 :biggrin:
when it comes to "style", you are preaching to the choir - lol
i much prefer to do things my own way - much like you
i learned assembly back in the 70's - much like you

but, over time, i have found that certain things are easier "the other way"
it's ok to add that to your learning curve

as for specific content, i am writing a little code of my own, at the moment
i want to see where the problem lies
in order for me to debug your code, i need to be able to read and understand it
so, i am writing a simple window program that creates the context and deletes it when the window is destroyed
and that's all it does
when i have it up and running, i can substitute pieces of your code to see where it fails
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: hamper on November 12, 2013, 05:19:25 AM
Well, if it helps this is my bog standard "get a simple window up on the desktop" program.
But you won't like it :eusa_snooty:


;--------------------------------------------------------------------------------------
; A simple window                                                      simplewindow.asm
;--------------------------------------------------------------------------------------

.686
.model flat,stdcall
option casemap:none

includelib user32
includelib kernel32

;--------------------------------------------------------------------------------------

CreateWindowExA  proto :dword,:dword,:dword,:dword,:dword,:dword,
                       :dword,:dword,:dword,:dword,:dword,:dword
DefWindowProcA   proto :dword,:dword,:dword,:dword
DispatchMessageA proto :dword
ExitProcess      proto :dword
GetMessageA      proto :dword,:dword,:dword,:dword
GetModuleHandleA proto :dword
LoadCursorA      proto :dword,:dword
LoadIconA        proto :dword,:dword
PostQuitMessage  proto :dword
RegisterClassExA proto :dword
windowproc       proto :dword,:dword,:dword,:dword

point struct
   x dword ?
   y dword ?
point ends

msgst struct
   hwnd    dword ?
   message dword ?
   wparam  dword ?
   lparam  dword ?
   time    dword ?
   pt      point <>
msgst ends

windowclasstype struct
   wcsize        dword ?
   style         dword ?
   addrwp        dword ?
   classeb       dword ?
   windoweb      dword ?
   proghandle    dword ?
   liconhandle   dword ?
   cursorhandle  dword ?
   colour        dword ?
   menuhandle    dword ?
   addrclassname dword ?
   siconhandle   dword ?
windowclasstype ends

;--------------------------------------------------------------------------------------

.const
classname   byte "SimpleWinClass",0
windowtitle byte "The window title",0

.data?
msg       msgst <>
mywc      windowclasstype <>
winhandle dword ?

.code
start:

;######################################################################################

;---------- fill up the window class structure variable and get the program handle etc.

mov mywc.wcsize,48
mov mywc.style,3
mov mywc.addrwp,offset windowproc
mov mywc.classeb,0
mov mywc.windoweb,0
push 0
call GetModuleHandleA
mov mywc.proghandle,eax
push 32515
push 0
call LoadIconA
mov mywc.liconhandle,eax
mov mywc.siconhandle,eax
push 32515
push 0
call LoadCursorA
mov mywc.cursorhandle,eax
mov mywc.colour,2
mov mywc.menuhandle,0
mov mywc.addrclassname,offset classname

;---------- register the window class

push offset mywc
call RegisterClassExA

;---------- create and display the window

push 0
push mywc.proghandle
push 0
push 0
push 300         ; window height
push 500         ; window width
push 100         ; window top position
push 100         ; window left position
push 269418496
push offset windowtitle
push mywc.addrclassname
push 0
call CreateWindowExA
mov winhandle,eax

;---------- the message loop

msgloopstart:
push 0
push 0
push winhandle
push offset msg
call GetMessageA
cmp eax,0
je msgloopend
push offset msg
call DispatchMessageA
jmp msgloopstart
msgloopend:
push 0
call ExitProcess

;######################################################################################

;---------- the window procedure

windowproc proc hwnd:dword,message:dword,wparam:dword,lparam:dword

cmp message,16 ; WM_CLOSE
je its16

; default processing
push lparam
push wparam
push message
push hwnd
call DefWindowProcA
ret

its16:
push 0
call PostQuitMessage
ret

windowproc endp

;--------------------------------------------------------------------------------------

end start
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: dedndave on November 12, 2013, 05:50:31 AM
got that up and running - it displays a non-zero handle value
take a look...........
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: jj2007 on November 12, 2013, 05:53:14 AM
Quote from: hamper on November 12, 2013, 05:19:25 AM
But you won't like it :eusa_snooty:

If you are a productive coder with this style, why not?
You might like \Masm32\examples\exampl07\slickhuh\slickhuh.asm ;-)
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: hamper on November 12, 2013, 06:03:07 AM
dedndave,

Looks good to me, but you should really get out of the habit of using "dd". We all should be using "dword" now.
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: dedndave on November 12, 2013, 06:11:19 AM
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
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: dedndave on November 12, 2013, 06:24:51 AM
by the way
here is the second test program
maybe you can see something i missed
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: 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 ?
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: hamper on November 12, 2013, 06:59:57 AM
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??

Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: 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
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: GoneFishing on November 12, 2013, 07:26:21 AM
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
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: dedndave on November 12, 2013, 07:30:41 AM
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
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: hamper on November 12, 2013, 07:32:10 AM
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
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: dedndave on November 12, 2013, 07:36:25 AM
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
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: GoneFishing on November 12, 2013, 07:43:50 AM
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:
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: Farabi on November 12, 2013, 07:48:02 AM
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
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: GoneFishing on November 12, 2013, 07:53:23 AM
can't figure out how to use it  :(
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: Farabi on November 12, 2013, 08:02:02 AM
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.
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: GoneFishing on November 12, 2013, 08:11:58 AM
...
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: Farabi on November 12, 2013, 08:20:23 AM
Quote from: vertograd on November 12, 2013, 08:11:58 AM
intriguing ...
I will try but please clearify several things :
hRC - a handle to window rectangle
hDC -               to device context (but you're calling GetDC inside your proc? )
and what is a macro CADD? EDIT: OK, I've found it !
anyway you'd better to give us (beginners) the whole application example  ;)

Use a blank variable. That variable will be filled with a new hDC, you dont need to create one. It will creating it for you.
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: Farabi on November 12, 2013, 08:24:59 AM
Quote from: vertograd on November 12, 2013, 08:11:58 AM
intriguing ...
I will try but please clearify several things :
hRC - a handle to window rectangle
hDC -               to device context (but you're calling GetDC inside your proc? )
and what is a macro CADD? EDIT: OK, I've found it !
anyway you'd better to give us (beginners) the whole application example  ;)

This is the whole applications https://www.asuswebstorage.com/navigate/s/04AAECE4836447E29B9E0A0AAA5D13DCY but it wont worked on yours because MASM changed the inc file structure, that is why you need to use my tools. Im still synching my tools to the server. After it done, I'll give it to you. You may use it for commercial or non commercial purpose, I'll tell you everything. I guess I need to pass my legacy.
Title: Good morning , hamper !
Post by: GoneFishing on November 12, 2013, 08:45:53 AM
Here it is  :icon_exclaim:

;--------------------------------------------------------------------------------------
; A simple OpenGL example                                                   ogltest.asm
;--------------------------------------------------------------------------------------

include \masm32\include\masm32rt.inc

includelib \masm32\lib\opengl32.lib

;--------------------------------------------------------------------------------------

CreateWindowExA      proto :dword,:dword,:dword,:dword,:dword,:dword,
                           :dword,:dword,:dword,:dword,:dword,:dword
DefWindowProcA       proto :dword,:dword,:dword,:dword
DispatchMessageA     proto :dword
ExitProcess          proto :dword
GetMessageA          proto :dword,:dword,:dword,:dword
GetModuleHandleA     proto :dword
LoadCursorA          proto :dword,:dword
LoadIconA            proto :dword,:dword
PostQuitMessage      proto :dword
RegisterClassExA     proto :dword
windowproc           proto :dword,:dword,:dword,:dword
GetDC                proto :dword
wglChoosePixelFormat proto :dword,:dword
wglSetPixelFormat    proto :dword,:sdword,:dword
wglCreateContext     proto :dword
wglMakeCurrent       proto :dword,:dword
wglDeleteContext     proto :dword
ReleaseDC            proto :dword,:dword
glBegin              proto :dword
glEnd                proto
glVertex2fv          proto :dword
MessageBoxA          proto :dword,:dword,:dword,:dword
DrawScene            proto
point struct
   x dword ?
   y dword ?
point ends

msgst struct
   hwnd    dword ?
   message dword ?
   wparam  dword ?
   lparam  dword ?
   time    dword ?
   pt      point <>
msgst ends

windowclasstype struct
   wcsize        dword ?
   style         dword ?
   addrwp        dword ?
   classeb       dword ?
   windoweb      dword ?
   proghandle    dword ?
   liconhandle   dword ?
   cursorhandle  dword ?
   colour        dword ?
   menuhandle    dword ?
   addrclassname dword ?
   siconhandle   dword ?
windowclasstype ends

;--------------------------------------------------------------------------------------

.const
classname   byte "SimpleWinClass",0
windowtitle byte "The window title",0
mymbtitle   byte "Alert",0
mymbtext    byte "Could not get rendering context",0

.data?
msg       msgst <>
mywc      windowclasstype <>
winhandle dword ?
dchandle  dword ?
rchandle  dword ?

.data

PixFrm PIXELFORMATDESCRIPTOR <>
myvertex1 real4 0.0,0.0
myvertex2 real4 1.0,0.0
myvertex3 real4 0.5,0.87

.code
start:

;######################################################################################

;---------- fill up the window class structure variable and get the program handle etc.

mov mywc.wcsize,48
mov mywc.style,35                    ; CS_VREDRAW + CS_HREDRAW + CS_OWNDC
mov mywc.addrwp,offset windowproc
mov mywc.classeb,0
mov mywc.windoweb,0
push 0
call GetModuleHandleA
mov mywc.proghandle,eax
push 32515                           ; A black ! in a yellow triangle
push 0
call LoadIconA
mov mywc.liconhandle,eax
mov mywc.siconhandle,eax
push 32515                           ; A crosshair
push 0
call LoadCursorA
mov mywc.cursorhandle,eax
mov mywc.colour,2                    ; desktop colour
mov mywc.menuhandle,0
mov mywc.addrclassname,offset classname

;---------- register the window class

push offset mywc
call RegisterClassExA

;---------- create and display the window

push 0
push mywc.proghandle
push 0
push 0
push 340                           ; window height
push 320                           ; window width
push 230                           ; window top position
push 480                           ; window left position
push 269418496                     ; WS_VISIBLE + title bar, title, icon, icon menu,
                                   ;    min, max and close buttons, sizing borders
push offset windowtitle
push mywc.addrclassname
push 0                             ; default
call CreateWindowExA
mov winhandle,eax

invoke ShowWindow,winhandle,SW_SHOWNORMAL
invoke UpdateWindow,winhandle
call       DoEvents
ret



;######################################################################################

DoEvents PROC
LOCAL m:MSG
StartLoop: ; Check for waiting messages
invoke PeekMessage,ADDR m,0,0,0,PM_NOREMOVE
or eax,eax
jz NoMsg
invoke GetMessage,ADDR m,NULL,0,0
or eax,eax
jz ExitLoop
invoke TranslateMessage,ADDR m
invoke DispatchMessage,ADDR m
jmp StartLoop
NoMsg: ; No pending messages: draw the scene
invoke DrawScene
jmp StartLoop
ExitLoop: mov eax,m.wParam
ret
DoEvents ENDP

;----------

;comment *

DrawScene proc

push rchandle
push dchandle
call wglMakeCurrent

push 4                  ; triangles
call glBegin
push offset myvertex1
call glVertex2fv
push offset myvertex2
call glVertex2fv
push offset myvertex3
call glVertex2fv
call glEnd
ret
DrawScene endp

;*

;---------- the window procedure

windowproc  PROC hWin:DWORD,uMsg:DWORD,wParam:DWORD,lParam:DWORD
LOCAL WINRect:RECT
LOCAL PixFormat:DWORD

.if uMsg == WM_CREATE
invoke GetDC,hWin
mov dchandle,eax
mov ax,SIZEOF PixFrm
mov PixFrm.nSize,ax
mov PixFrm.nVersion,1
mov PixFrm.dwFlags,36
;mov PixFrm.dwLayerMask,PFD_MAIN_PLANE
mov PixFrm.iPixelType,0
mov PixFrm.cColorBits,32
mov PixFrm.cDepthBits,32
mov PixFrm.cAccumBits,0
mov PixFrm.cStencilBits,0
invoke ChoosePixelFormat,dchandle,ADDR PixFrm
mov PixFormat,eax
invoke SetPixelFormat,dchandle,PixFormat,ADDR PixFrm
or eax,eax
jz NoPixelFmt
                       ; int 3
invoke wglCreateContext,dchandle
mov rchandle,eax
                       ; int 3
                        fn MessageBox,0,hex$(eax),"Title",MB_OK

                        fn MessageBox,0,LastError$(),"Last Error Text",MB_OK


NoPixelFmt:
return 0

                  .elseif uMsg == WM_PAINT

                        invoke DrawScene
                       
                        return 0

.elseif uMsg == WM_SIZE
invoke GetClientRect,hWin,ADDR WINRect

return 0

.elseif uMsg == WM_CLOSE

mov eax,rchandle
or eax,eax
jz NoGlDC
; Delete our objects
invoke  wglDeleteContext,rchandle
                        invoke  ExitProcess,0
NoGlDC:
      invoke ReleaseDC,hWin,dchandle
      invoke DestroyWindow,hWin
return 0
.elseif uMsg == WM_DESTROY
invoke PostQuitMessage,NULL
return 0
.endif
invoke DefWindowProc,hWin,uMsg,wParam,lParam
ret

windowproc endp

;--------------------------------------------------------------------------------------

end start

Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: Farabi on November 12, 2013, 08:53:25 AM
 :t congrats that is the first step. Next is model loader.
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: GoneFishing on November 12, 2013, 09:02:55 AM
Quote from: Farabi on November 12, 2013, 08:02:02 AM
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.

Thank you for the link. I've already downloaded it . I have no RadAsm installed. Can I do it in QEDITOR or VS?

Quote from: Farabi on November 12, 2013, 08:53:25 AM
:t congrats that is the first step. Next is model loader.

Thanks
You're too quick  :biggrin:
I think next step would be to change the color of triangle, then  to draw a multi-colored one 
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: drizz on November 12, 2013, 09:04:55 AM
Quote from: hamper on November 12, 2013, 07:32:10 AM
No definitive answer or analysis so far as to why this happens.

You need to use functions from gdi32.dll ChoosePixelformat() SetPixelformat() instead of wgl prefixed ones.

http://www.opengl.org/archives/resources/faq/technical/mswindows.htm
Read 5.190 - 5.210
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: Farabi on November 12, 2013, 09:25:47 AM
Quote from: vertograd on November 12, 2013, 09:02:55 AM
Quote from: Farabi on November 12, 2013, 08:02:02 AM
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.

Thank you for the link. I've already downloaded it . I have no RadAsm installed. Can I do it in QEDITOR or VS?

Quote from: Farabi on November 12, 2013, 08:53:25 AM
:t congrats that is the first step. Next is model loader.

Thanks
You're too quick  :biggrin:
I think next step would be to change the color of triangle, then  to draw a multi-colored one

Here is RadAsm. Changing the color of triangle is simple, use

invoke glcolor4f,FP4(1.),FP4(1.),FP4(1.)   ; white
invoke glcolor4f,FP4(1.),FP4(0.),FP4(0.)   ; Red
etc...etc...etc


You can also use an array of real4 or real8 as the color data.


RadAsm: https://www.asuswebstorage.com/navigate/s/3DA934576973451996A474B01BE762C7Y
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: GoneFishing on November 12, 2013, 10:38:06 AM
...
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: Siekmanski on November 12, 2013, 11:12:46 AM
This is a basic Ogl example I did for my little nephew some years ago. He wanted to become a game programmer.
It has some basic stuff as background image, 2D and 3D drawing, line drawing, textures, transparency and an image loader (bmp gif jpeg) to load textures from file or from the resource to get him started.
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: dedndave on November 12, 2013, 11:33:48 AM
very nice, as always, Marinus   :t
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: Siekmanski on November 12, 2013, 12:30:45 PM
Thanks  :biggrin:
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: dedndave on November 13, 2013, 06:21:24 AM
doing some reading.....

i learned that i can use glGetString(GL_VERSION) to get my version level
on my old XP machine, i get 1.4.0, a far cry from the 3+ or whatever is current
at any rate, the version may account for varying results we are seeing

also, found some nice tutorials
there seems to be many of them out there

http://www.mbsoftworks.sk/ (http://www.mbsoftworks.sk/)

a subject that i am particularly interested in...
http://www.lighthouse3d.com/opengl/terrain/ (http://www.lighthouse3d.com/opengl/terrain/)
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: GoneFishing on November 13, 2013, 07:27:45 AM
...
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: hamper on November 13, 2013, 07:59:30 AM
Well, I've re-written my program to do all the global OpenGL initialisation stuff in the window procedure in response to receiving a WM_CREATE message. Also to use PeekMessageA and to do the frame rendering if there's no message pending. I've also tried using the gdi32.lib versions ChoosePixelFormat and SetPixelFormat instead of the opengl32.lib "wgl" prefix versions...

All to no avail. Still can't get a rendering context. And still can't see what's wrong with my program. But here is my latest version, just in case anyone is actually interested in trying to help me find out where the problem is, as opposed to just berating my programming style, trying to be slick and funny, or promoting software that's nothing to do with the subject of this thread. But I'm not holding my breath. I'll give it a couple of days to see if this forum is actually capable of helping solve my problem. If not, then my assembly notes, C notes, API notes and OpenGL notes are all going on the fire, condemned to the "what a complete waste of time all that was" tray.

;--------------------------------------------------------------------------------------
; An OpenGL example                                                      opengltest.asm
;--------------------------------------------------------------------------------------

.686
.model flat,stdcall
option casemap:none

includelib user32
includelib kernel32
includelib opengl32

;--------------------------------------------------------------------------------------

CreateWindowExA      proto :dword,:dword,:dword,:dword,:dword,:dword,
                           :dword,:dword,:dword,:dword,:dword,:dword
DefWindowProcA       proto :dword,:dword,:dword,:dword
DispatchMessageA     proto :dword
ExitProcess          proto :dword
GetModuleHandleA     proto :dword
LoadCursorA          proto :dword,:dword
LoadIconA            proto :dword,:dword
PeekMessageA         proto :dword,:dword,:dword,:dword,:dword
PostQuitMessage      proto :dword
RegisterClassExA     proto :dword
windowproc           proto :dword,:dword,:dword,:dword
GetDC                proto :dword
wglChoosePixelFormat proto :dword,:dword
wglSetPixelFormat    proto :dword,:sdword,:dword
wglCreateContext     proto :dword
wglMakeCurrent       proto :dword,:dword
wglDeleteContext     proto :dword
ReleaseDC            proto :dword,:dword
glViewport           proto :sdword,:sdword,:sdword,:sdword
glMatrixMode         proto :dword
glOrtho              proto :real8,:real8,:real8,:real8,:real8,:real8
glClearColor         proto :real4,:real4,:real4,:real4
glClear              proto :dword
glPushMatrix         proto
glPopMatrix          proto
glRotatef            proto :real4,:real4,:real4,:real4
glBegin              proto :dword
glEnd                proto
glColor3fv           proto :dword
glVertex3fv          proto :dword
glFlush              proto
wglSwapBuffers       proto :dword
rendernextframe      proto

point struct
   x dword ?
   y dword ?
point ends

msgst struct
   hwnd    dword ?
   message dword ?
   wparam  dword ?
   lparam  dword ?
   time    dword ?
   pt      point <>
msgst ends

windowclasstype struct
   wcsize        dword ?
   style         dword ?
   addrwp        dword ?
   classeb       dword ?
   windoweb      dword ?
   proghandle    dword ?
   liconhandle   dword ?
   cursorhandle  dword ?
   colour        dword ?
   menuhandle    dword ?
   addrclassname dword ?
   siconhandle   dword ?
windowclasstype ends

pfdtype struct
   nsize           word  40
   nversion        word  1
   dwflags         dword 4133
   ipixeltype      byte  0
   ccolorbits      byte  32
   credbits        byte  0
   credshift       byte  0
   cgreenbits      byte  0
   cgreenshift     byte  0
   cbluebits       byte  0
   cblueshift      byte  0
   calphabits      byte  0
   calphashift     byte  0
   caccumbits      byte  0
   caccumredbits   byte  0
   caccumgreenbits byte  0
   caccumbluebits  byte  0
   caccumalphabits byte  0
   cdepthbits      byte  32
   cstencilbits    byte  0
   cauxbuffers     byte  0
   ilayertype      byte  0
   breserved       byte  0
   dwlayermask     dword 0
   dwvisiblemask   dword 0
   dwdamagemask    dword 0
pfdtype ends

;--------------------------------------------------------------------------------------

.const
classname   byte "SimpleWinClass",0
windowtitle byte "The window title",0

.data?
msg        msgst <>
mywc       windowclasstype <>
winhandle  dword ?
dchandle   dword ?
rchandle   dword ?

.data
pfd        pfdtype <>
myortho    real8 1.0,1.0,-1.0,1.3,0.5,1.5
mybgcolour real4 0.0,0.0,0.0,1.0
myrot      real4 0.0,0.0,0.0,1.0
myrotsdw   sdword 0
myvertices real4 0.0,1.0,1.0,0.87,-0.5,1.0,-0.87,-0.5,1.0
mycolours  real4 1.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0

.code
start:

;######################################################################################

;---------- fill up the window class structure variable and get the program handle etc.

mov mywc.wcsize,48
mov mywc.style,35
mov mywc.addrwp,offset windowproc
mov mywc.classeb,0
mov mywc.windoweb,0
push 0
call GetModuleHandleA
mov mywc.proghandle,eax
push 32515
push 0
call LoadIconA
mov mywc.liconhandle,eax
mov mywc.siconhandle,eax
push 32515
push 0
call LoadCursorA
mov mywc.cursorhandle,eax
mov mywc.colour,2
mov mywc.menuhandle,0
mov mywc.addrclassname,offset classname

;---------- register the window class

push offset mywc
call RegisterClassExA

;---------- create and display the window

push 0
push mywc.proghandle
push 0
push 0
push 340         ; window height
push 320         ; window width
push 230         ; window top position
push 480         ; window left position
push 269418496
push offset windowtitle
push mywc.addrclassname
push 0
call CreateWindowExA
mov winhandle,eax

;---------- the message loop

msgloopstart:
   push 1                 ; messages will be retrieved
   push 0
   push 0
   push winhandle
   push offset msg
   call PeekMessageA
   cmp eax,0
   jne messageretrieved
   call rendernextframe   ; no message pending, so render next frame
   jmp msgloopstart
messageretrieved:
   cmp msg.message,18         ; WM_QUIT
   je msgloopend
   push offset msg
   call DispatchMessageA
   jmp msgloopstart
msgloopend:
   push rchandle
   call wglDeleteContext
   push dchandle
   push winhandle
   call ReleaseDC
   push 0
   call ExitProcess

;######################################################################################

;---------- the window procedure

windowproc proc hwnd:dword,message:dword,wparam:dword,lparam:dword

      cmp message,1           ; WM_CREATE
      je initialiseopengl
      cmp message,16          ; WM_CLOSE
      je closeprogram
   ; default processing
      push lparam
      push wparam
      push message
      push hwnd
      call DefWindowProcA
      ret
   initialiseopengl:
      push winhandle
      call GetDC
      mov dchandle,eax
      push offset pfd
      push dchandle
      call wglChoosePixelFormat
      push offset pfd
      push eax
      push dchandle
      call wglSetPixelFormat
      push dchandle
      call wglCreateContext
      mov rchandle,eax
      push rchandle
      push dchandle
      call wglMakeCurrent
      push 5889
      call glMatrixMode     ; projection matrix stack
      push 300              ; height
      push 300              ; width
      push 10               ; y
      push 10               ; x
      call glViewport
      push dword ptr myortho[44]   ; myortho real8 1.0,1.0,-1.0,1.3,0.5,1.5
      push dword ptr myortho[40]
      push dword ptr myortho[36]
      push dword ptr myortho[32]
      push dword ptr myortho[28]
      push dword ptr myortho[24]
      push dword ptr myortho[20]
      push dword ptr myortho[16]
      push dword ptr myortho[12]
      push dword ptr myortho[8]
      push dword ptr myortho[4]
      push dword ptr myortho
      call glOrtho
      push 5888
      call glMatrixMode     ; modelview matrix stack
      push mybgcolour[12]   ; mybgcolour real4 0.0,0.0,0.0,1.0   ; black
      push mybgcolour[8]
      push mybgcolour[4]
      push mybgcolour
      call glClearColor
      ret
   closeprogram:
      push 0
      call PostQuitMessage
      ret

windowproc endp

;---------- the rendering procedure

rendernextframe proc

      push 16384
      call glClear                 ; clear window to background colour
      call glPushMatrix            ; push the matrix stack
      inc myrotsdw                 ; perform any translations, scales, rotations etc.
      cmp myrotsdw,360
      jne carryon
      mov myrotsdw,0
   carryon:
      finit
      fild myrotsdw
      fst myrot
      push myrot[12]
      push myrot[8]
      push myrot[4]
      push myrot
      call glRotatef
      push 4
      call glBegin                 ; draw objects anew
      push offset mycolours
      call glColor3fv
      push offset myvertices
      call glVertex3fv
      push offset mycolours[12]
      call glColor3fv
      push offset myvertices[12]
      call glVertex3fv
      push offset mycolours[24]
      call glColor3fv
      push offset myvertices[24]
      call glVertex3fv
      call glEnd
      call glFlush
      call glPopMatrix             ; pop the matrix stack
      push dchandle
      call wglSwapBuffers          ; swap buffers
      ret

rendernextframe endp

;--------------------------------------------------------------------------------------

end start


Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: jj2007 on November 13, 2013, 08:49:43 AM
hi hamper,

Your frustration is understandable, this has happened to all of us before ;-)

There is one obvious problem:
   initialiseopengl:
      push winhandle
      call GetDC

You are pushing zero here - and you do get a handle, strangely enough. But it's not the right one...
This triggers the following errors:

DC
eax             956367609
$Err$()         Operazione completata.

wglChoosePixelFormat
eax             4
$Err$()         Can't find the specified procedure

wglSetPixelFormat
eax             1
$Err$()         Can't find the specified file

wglCreateContext
hwnd            393264
dchandle        956367609
eax             65536
$Err$()         Can't find the specified file


If instead you use the valid hwnd:
      push hwnd
      call GetDC


... then you get less errors:
DC
eax             503384091
$Err$()         Operazione completata.

wglChoosePixelFormat
eax             4
$Err$()         Can't find the specified procedure <<< this is the remaining problem <<<

wglSetPixelFormat
eax             1
$Err$()         Operazione completata.

wglCreateContext
hwnd            592362
dchandle        503384091
eax             65536
$Err$()         Operazione completata.

wglMakeCurrent
eax             1
$Err$()         Operazione completata.

glMatrixMode
eax             1704576
$Err$()         Operazione completata.

glViewport
eax             1096356113
$Err$()         Operazione completata.

glOrtho
eax             1281
$Err$()         Operazione completata.

glClearColor
eax             255
$Err$()         Operazione completata.


By the way, after two BSODs and complete reboots (Win XP SP3), I decided to ExitProcess directly after call wglCreateContext ;-)

In the meantime, however, it seems that pushing a valid handle for GetDC solves the BSOD problem (I had not seen one for several years, wow...).

Hope this helps you continue your fight :icon14:

P.S.: The result looks cute - see attachment.
P.P.S.: Your message handling is unorthodox. To allow exiting the program with less acrobatics, I would suggest this hack (tested, it works):

messageretrieved:
   cmp msg.message,18         ; WM_QUIT
   je msgloopend

      invoke GetKeyState, VK_SHIFT
      test ah, ah
      js msgloopend

   push offset msg
   call DispatchMessageA
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: qWord on November 13, 2013, 09:12:42 AM
When applying drizz's and jj's hints, the latest code does work. However, I strongly suggest to use a timer for drawing  :t
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: jj2007 on November 13, 2013, 09:15:48 AM
Quote from: qWord on November 13, 2013, 09:12:42 AMI strongly suggest to use a timer for drawing  :t

Yes, the PeekMessage hack blocks normal message processing. On the other hand, a timer will slow it down. Perhaps a GetMessage (and WM_TIMER) per every 100 PeekMessage?

Quote from: drizz on November 12, 2013, 09:04:55 AM
You need to use functions from gdi32.dll ChoosePixelformat() SetPixelformat() instead of wgl prefixed ones.

The wql versions work, see attachment to my previous post.
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: qWord on November 13, 2013, 09:19:40 AM
I would simply use WM_TIMER and use a common message loop.

EDIT:
Quote from: jj2007 on November 13, 2013, 09:15:48 AMThe wql versions work, see attachment to my previous post.
It doesn't work on Win7, x64. (probably depends on the GC driver) EDIT2: it does work
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: jj2007 on November 13, 2013, 09:24:23 AM
OK, if the plain GDI versions work on 7-64, then I stand corrected :icon14:
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: qWord on November 13, 2013, 09:38:25 AM
Quote from: jj2007 on November 13, 2013, 09:24:23 AM
OK, if the plain GDI versions work on 7-64, then I stand corrected :icon14:
sorry, I've execute it in the AV's Sandbox - wgl version also runs here.

A version with timer:
;--------------------------------------------------------------------------------------
; An OpenGL example                                                      opengltest.asm
;--------------------------------------------------------------------------------------

.686
.model flat,stdcall
option casemap:none

includelib user32
includelib kernel32
includelib opengl32
includelib gdi32
includelib winmm

;--------------------------------------------------------------------------------------

CreateWindowExA      proto :dword,:dword,:dword,:dword,:dword,:dword,
                           :dword,:dword,:dword,:dword,:dword,:dword
DefWindowProcA       proto :dword,:dword,:dword,:dword
DispatchMessageA     proto :dword
ExitProcess          proto :dword
GetModuleHandleA     proto :dword
LoadCursorA          proto :dword,:dword
LoadIconA            proto :dword,:dword
PeekMessageA         proto :dword,:dword,:dword,:dword,:dword
PostQuitMessage      proto :dword
RegisterClassExA     proto :dword
windowproc           proto :dword,:dword,:dword,:dword
GetDC                proto :dword
ChoosePixelFormat    proto :dword,:dword
SetPixelFormat       proto :dword,:sdword,:dword
wglCreateContext     proto :dword
wglMakeCurrent       proto :dword,:dword
wglDeleteContext     proto :dword
ReleaseDC            proto :dword,:dword
glViewport           proto :sdword,:sdword,:sdword,:sdword
glMatrixMode         proto :dword
glOrtho              proto :real8,:real8,:real8,:real8,:real8,:real8
glClearColor         proto :real4,:real4,:real4,:real4
glClear              proto :dword
glPushMatrix         proto
glPopMatrix          proto
glRotatef            proto :real4,:real4,:real4,:real4
glBegin              proto :dword
glEnd                proto
glColor3fv           proto :dword
glVertex3fv          proto :dword
glFlush              proto
wglSwapBuffers       proto :dword
rendernextframe      proto
SetTimer proto :DWORD,:DWORD,:DWORD,:DWORD
timeBeginPeriod proto :DWORD
GetMessageA proto :DWORD,:DWORD,:DWORD,:DWORD
timeEndPeriod proto :DWORD

point struct
   x dword ?
   y dword ?
point ends

msgst struct
   hwnd    dword ?
   message dword ?
   wparam  dword ?
   lparam  dword ?
   time    dword ?
   pt      point <>
msgst ends

windowclasstype struct
   wcsize        dword ?
   style         dword ?
   addrwp        dword ?
   classeb       dword ?
   windoweb      dword ?
   proghandle    dword ?
   liconhandle   dword ?
   cursorhandle  dword ?
   colour        dword ?
   menuhandle    dword ?
   addrclassname dword ?
   siconhandle   dword ?
windowclasstype ends

pfdtype struct
   nsize           word  40
   nversion        word  1
   dwflags         dword 4133
   ipixeltype      byte  0
   ccolorbits      byte  32
   credbits        byte  0
   credshift       byte  0
   cgreenbits      byte  0
   cgreenshift     byte  0
   cbluebits       byte  0
   cblueshift      byte  0
   calphabits      byte  0
   calphashift     byte  0
   caccumbits      byte  0
   caccumredbits   byte  0
   caccumgreenbits byte  0
   caccumbluebits  byte  0
   caccumalphabits byte  0
   cdepthbits      byte  32
   cstencilbits    byte  0
   cauxbuffers     byte  0
   ilayertype      byte  0
   breserved       byte  0
   dwlayermask     dword 0
   dwvisiblemask   dword 0
   dwdamagemask    dword 0
pfdtype ends

;--------------------------------------------------------------------------------------

.const
classname   byte "SimpleWinClass",0
windowtitle byte "The window title",0

.data?
msg        msgst <>
mywc       windowclasstype <>
winhandle  dword ?
dchandle   dword ?
rchandle   dword ?

.data
pfd        pfdtype <>
myortho    real8 1.0,1.0,-1.0,1.3,0.5,1.5
mybgcolour real4 0.0,0.0,0.0,1.0
myrot      real4 0.0,0.0,0.0,1.0
myrotsdw   sdword 0
myvertices real4 0.0,1.0,1.0,0.87,-0.5,1.0,-0.87,-0.5,1.0
mycolours  real4 1.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0

.code
start:

;######################################################################################

;---------- fill up the window class structure variable and get the program handle etc.

mov mywc.wcsize,48
mov mywc.style,35
mov mywc.addrwp,offset windowproc
mov mywc.classeb,0
mov mywc.windoweb,0
push 0
call GetModuleHandleA
mov mywc.proghandle,eax
push 32515
push 0
call LoadIconA
mov mywc.liconhandle,eax
mov mywc.siconhandle,eax
push 32515
push 0
call LoadCursorA
mov mywc.cursorhandle,eax
mov mywc.colour,2
mov mywc.menuhandle,0
mov mywc.addrclassname,offset classname

;---------- register the window class

push offset mywc
call RegisterClassExA

;---------- create and display the window

push 0
push mywc.proghandle
push 0
push 0
push 340         ; window height
push 320         ; window width
push 230         ; window top position
push 480         ; window left position
push 269418496
push offset windowtitle
push mywc.addrclassname
push 0
call CreateWindowExA
mov winhandle,eax

;---------- the message loop

msgloopstart:
   invoke GetMessageA,OFFSET msg,0,0,0
   test eax,eax
   jz msgloopend
   push offset msg
   call DispatchMessageA
   jmp msgloopstart
msgloopend:
   push rchandle
   call wglDeleteContext
   push dchandle
   push winhandle
   call ReleaseDC
   push 0
   call ExitProcess

;######################################################################################

;---------- the window procedure

windowproc proc hwnd:dword,message:dword,wparam:dword,lparam:dword

      cmp message,1           ; WM_CREATE
      je initialiseopengl
      cmp message,16          ; WM_CLOSE
      je closeprogram
      cmp message,113h ; WM_TIMER
      je WM_TIMER
     
   ; default processing
      push lparam
      push wparam
      push message
      push hwnd
      call DefWindowProcA
      ret
   initialiseopengl:
      push hwnd
      call GetDC
      mov dchandle,eax
      push offset pfd
      push dchandle
      call ChoosePixelFormat
      push offset pfd
      push eax
      push dchandle
      call SetPixelFormat
      push dchandle
      call wglCreateContext
      mov rchandle,eax
      push rchandle
      push dchandle
      call wglMakeCurrent
      push 5889
      call glMatrixMode     ; projection matrix stack
      push 300              ; height
      push 300              ; width
      push 10               ; y
      push 10               ; x
      call glViewport
      push dword ptr myortho[44]   ; myortho real8 1.0,1.0,-1.0,1.3,0.5,1.5
      push dword ptr myortho[40]
      push dword ptr myortho[36]
      push dword ptr myortho[32]
      push dword ptr myortho[28]
      push dword ptr myortho[24]
      push dword ptr myortho[20]
      push dword ptr myortho[16]
      push dword ptr myortho[12]
      push dword ptr myortho[8]
      push dword ptr myortho[4]
      push dword ptr myortho
      call glOrtho
      push 5888
      call glMatrixMode     ; modelview matrix stack
      push mybgcolour[12]   ; mybgcolour real4 0.0,0.0,0.0,1.0   ; black
      push mybgcolour[8]
      push mybgcolour[4]
      push mybgcolour
      call glClearColor
      invoke timeBeginPeriod,1
      invoke SetTimer,hwnd,100,10,0
      ret
   closeprogram:
     
      invoke timeEndPeriod,1
      push 0
      call PostQuitMessage
      ret
WM_TIMER:
call rendernextframe
  ret

windowproc endp

;---------- the rendering procedure

rendernextframe proc

      push 16384
      call glClear                 ; clear window to background colour
      call glPushMatrix            ; push the matrix stack
      inc myrotsdw                 ; perform any translations, scales, rotations etc.
      cmp myrotsdw,360
      jne carryon
      mov myrotsdw,0
   carryon:
      finit
      fild myrotsdw
      fst myrot
      push myrot[12]
      push myrot[8]
      push myrot[4]
      push myrot
      call glRotatef
      push 4
      call glBegin                 ; draw objects anew
      push offset mycolours
      call glColor3fv
      push offset myvertices
      call glVertex3fv
      push offset mycolours[12]
      call glColor3fv
      push offset myvertices[12]
      call glVertex3fv
      push offset mycolours[24]
      call glColor3fv
      push offset myvertices[24]
      call glVertex3fv
      call glEnd
      call glFlush
      call glPopMatrix             ; pop the matrix stack
      push dchandle
      call wglSwapBuffers          ; swap buffers
      ret

rendernextframe endp

;--------------------------------------------------------------------------------------

end start
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: jj2007 on November 13, 2013, 09:52:42 AM
Quote from: qWord on November 13, 2013, 09:38:25 AM
A version with timer

Looks fine but seems ca. 20..50 times slower. If you choose 1ms instead of 10, does it become as fast as the PeekMessage version?
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: qWord on November 13, 2013, 10:00:29 AM
Quote from: jj2007 on November 13, 2013, 09:52:42 AM
Quote from: qWord on November 13, 2013, 09:38:25 AM
A version with timer

Looks fine but seems ca. 20..50 times slower. If you choose 1ms instead of 10, does it become as fast as the PeekMessage version?
for what does we need so much FPS?
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: dedndave on November 13, 2013, 10:04:12 AM
the system timer resolution is typically 10 to 16 ms
but, that should be fast enough

when i try hitchhikr's example in the masm32 package, it runs like a kitten on crack - lol
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: dedndave on November 13, 2013, 10:17:27 AM
Quote from: hamper on November 13, 2013, 07:59:30 AM
....But here is my latest version, just in case anyone is actually interested in trying to help me find out where the problem is, as opposed to just berating my programming style, trying to be slick and funny, or promoting software that's nothing to do with the subject of this thread. But I'm not holding my breath. I'll give it a couple of days to see if this forum is actually capable of helping solve my problem. If not, then my assembly notes, C notes, API notes and OpenGL notes are all going on the fire, condemned to the "what a complete waste of time all that was" tray.

if you don't want to proceed at the pace we are moving, don't let the door hit you in the ass
you talk as though we are on your payroll or something
if you don't like assembly language, it's not our problem

on the other hand, we all like to "learn as we go"
have some patience, and you'll probably be pleased with the results
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: qWord on November 13, 2013, 10:18:31 AM
Quote from: dedndave on November 13, 2013, 10:04:12 AM
the system timer resolution is typically 10 to 16 ms
but, that should be fast enough
if someone is not happy with that, timeBegin/EndPeriod() allows resolution up to 1ms (as used above).
Quote from: dedndave on November 13, 2013, 10:04:12 AMwhen i try hitchhikr's example in the masm32 package, it runs like a kitten on crack - lol
that is a misconstruction you can fined in many 3D examples. The animation speed should be bound with the time and not the CPU/GPU speed.
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: dedndave on November 13, 2013, 10:22:25 AM
well - as i browsed through that code, i saw the call in the message loop
and - i wasn't pleased with that - something i would do differently, if i were to use that code

but, the program does function - so Franck has that much going on   :P
something else i didn't care for.....
he uses GetDC in WM_CREATE, then in WM_CLOSE he finally releases it
i doubt that's a requirement for OpenGL
the wglCreateContext likely uses that DC as a reference to create a compatible DC
after that, the original DC can be released
also - it could just as well be the desktop DC
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: dedndave on November 13, 2013, 11:00:09 AM
qWord's "foo" version works nicely, here   :t

at least, it works with my current build:

(http://img203.imageshack.us/img203/5783/vzd2.png)
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: jj2007 on November 13, 2013, 05:45:32 PM
I'm also not happy with the PeekMessage approach, but if the OP wants hi speed, it's so far the only one that does the job. The way to go is probably WM_TIMER with a proc as last para, where the proc performs 100 or so renderings. Up to hamper to decide.

One remark regarding the code attached in reply 44 (http://masm32.com/board/index.php?topic=2582.msg27228#msg27228): wglChoosePixelFormat throws error "can't find the specified procedure"; that must be an internal error, because the returned value (4) works perfectly.

P.S.: Just noticed that on Win7-32, it runs much, much slower than on WinXP. It's a factor 20...50, and the Win7 machine is faster than my XP machine, so it must be something OS-related ::)

Besides, the wglChoosePixelFormat internal error is no longer present on Win7; it returns 7 (instead of 4; ChoosePixelFormat returns 1), and GetLastError returns zero.
However, if you use
      push offset pfd
      push 4   ; eax
      push dchandle
      call SetPixelFormat

i.e. the value that ChoosePixelFormat returns on XP, then suddenly the rendering becomes as fast as on XP. So it seems that the "internal" error is responsible for the difference in speed. I'd call that a bug in OpenGL, unless somebody else spots a feature in this, of course :icon_mrgreen:

Quote from: dedndave on November 13, 2013, 10:22:25 AM
the wglCreateContext likely uses that DC as a reference to create a compatible DC
after that, the original DC can be released

You would pass a released handle to wglMakeCurrent. It works, but still, better to place the release after wglMakeCurrent (tested OK).
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: dedndave on November 13, 2013, 08:58:08 PM
well - that's essentially what i meant - you caught me mis-speaking - lol
if you look at my first posted code...
the ReleaseDC is at the end of the WM_CREATE handler code, after wglMakeCurrent
in some of the example code i have looked at, it's released in WM_CLOSE   :P
hamper's code releases it after the message loop, before ExitProcess - a bit strange
but, the init code was originally before the message loop in the main proc

i prefer to do creation in WM_CREATE, and clean-up in WM_DESTROY
in the case of that DC, though, it need not be retained for the life of the process

a while back, drizz pointed us to:
http://www.opengl.org/archives/resources/faq/technical/mswindows.htm (http://www.opengl.org/archives/resources/faq/technical/mswindows.htm)
sections 5.190 to 5.210

it explains the difference between the wgl and GDI versions of these 5 functions:
ChoosePixelformat, DescribePixelformat, GetPixelformat, SetPixelformat, SwapBuffers
however, the document is a bit old - so things may have changed, over time
still, it's interesting to note the history
i am going to do as drizz and the document suggest, and use the GDI versions   :P
at least, until i see a reason for doing otherwise

it's a bit odd that qWord sets the timer resolution to 1 mS, then uses a 10 mS elapse time
but, he's pretty sharp - let's see how it goes without altering the resolution
i try to avoid changing the resolution unless i have to, because it affects other things
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: GoneFishing on November 13, 2013, 09:35:40 PM
I've found glGetError  function , it takes no parameter and returns one of these:
from gl.h
Quote
/* ErrorCode */
#define GL_NO_ERROR                        0
#define GL_INVALID_ENUM                  0x0500
#define GL_INVALID_VALUE                 0x0501
#define GL_INVALID_OPERATION         0x0502
#define GL_STACK_OVERFLOW            0x0503
#define GL_STACK_UNDERFLOW          0x0504
#define GL_OUT_OF_MEMORY              0x0505
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: dedndave on November 13, 2013, 09:41:16 PM
interesting   :t

i see where i may have a problem....
i am just getting to "translating" the NextFrame code
it seems they use the global HDC for SwapBuffers
so, maybe it should be retained for the life of the process
although, GetDC is pretty fast - i guess you could get/release each time
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: GoneFishing on November 13, 2013, 09:52:04 PM
Quote from: dedndave on November 13, 2013, 06:21:24 AM
...
i learned that i can use glGetString(GL_VERSION) to get my version level
on my old XP machine, i get 1.4.0, a far cry from the 3+ or whatever is current
...

Seems like  version 4.4
In the DirectX SDK  there's an example listing the device capabilities ...
... thinking of doing it for OpenGL
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: dedndave on November 13, 2013, 09:55:19 PM
Quote from: vertograd on November 13, 2013, 09:52:04 PM
Seems like  version 4.4

is that under windows 7 ?
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: GoneFishing on November 13, 2013, 09:58:43 PM
Quote from: dedndave on November 13, 2013, 09:55:19 PM
Quote from: vertograd on November 13, 2013, 09:52:04 PM
Seems like  version 4.4

is that under windows 7 ?

under Windows 8, Dave

EDIT: Just called glGetString with GL_EXTENSIONS parameter - the message box didn't fit the screen! Then I saved the output to file
GL_EXTENSIONS.TXT
Quote
GL_AMD_multi_draw_indirect GL_AMD_seamless_cubemap_per_texture GL_ARB_arrays_of_arrays GL_ARB_base_instance GL_ARB_bindless_texture GL_ARB_blend_func_extended GL_ARB_buffer_storage GL_ARB_clear_buffer_object GL_ARB_clear_texture GL_ARB_color_buffer_float GL_ARB_compatibility GL_ARB_compressed_texture_pixel_storage GL_ARB_conservative_depth GL_ARB_compute_shader GL_ARB_compute_variable_group_size GL_ARB_copy_buffer GL_ARB_copy_image GL_ARB_debug_output GL_ARB_depth_buffer_float GL_ARB_depth_clamp GL_ARB_depth_texture GL_ARB_draw_buffers GL_ARB_draw_buffers_blend GL_ARB_draw_indirect GL_ARB_draw_elements_base_vertex GL_ARB_draw_instanced GL_ARB_enhanced_layouts GL_ARB_ES2_compatibility GL_ARB_ES3_compatibility GL_ARB_explicit_attrib_location GL_ARB_explicit_uniform_location GL_ARB_fragment_coord_conventions GL_ARB_fragment_layer_viewport GL_ARB_fragment_program GL_ARB_fragment_program_shadow GL_ARB_fragment_shader GL_ARB_framebuffer_no_attachments GL_ARB_framebuffer_object GL_ARB_framebuffer_sRGB GL_ARB_geometry_shader4 GL_ARB_get_program_binary GL_ARB_gpu_shader5 GL_ARB_gpu_shader_fp64 GL_ARB_half_float_pixel GL_ARB_half_float_vertex GL_ARB_imaging GL_ARB_indirect_parameters GL_ARB_instanced_arrays GL_ARB_internalformat_query GL_ARB_internalformat_query2 GL_ARB_invalidate_subdata GL_ARB_map_buffer_alignment GL_ARB_map_buffer_range GL_ARB_multi_bind GL_ARB_multi_draw_indirect GL_ARB_multisample GL_ARB_multitexture GL_ARB_occlusion_query GL_ARB_occlusion_query2 GL_ARB_pixel_buffer_object GL_ARB_point_parameters GL_ARB_point_sprite GL_ARB_program_interface_query GL_ARB_provoking_vertex GL_ARB_robust_buffer_access_behavior GL_ARB_robustness GL_ARB_sample_shading GL_ARB_sampler_objects GL_ARB_seamless_cube_map GL_ARB_seamless_cubemap_per_texture GL_ARB_separate_shader_objects GL_ARB_shader_atomic_counters GL_ARB_shader_bit_encoding GL_ARB_shader_draw_parameters GL_ARB_shader_group_vote GL_ARB_shader_image_load_store GL_ARB_shader_image_size GL_ARB_shader_objects GL_ARB_shader_precision GL_ARB_query_buffer_object GL_ARB_shader_storage_buffer_object GL_ARB_shader_subroutine GL_ARB_shader_texture_lod GL_ARB_shading_language_100 GL_ARB_shading_language_420pack GL_ARB_shading_language_include GL_ARB_shading_language_packing GL_ARB_shadow GL_ARB_stencil_texturing GL_ARB_sync GL_ARB_tessellation_shader GL_ARB_texture_border_clamp GL_ARB_texture_buffer_object GL_ARB_texture_buffer_object_rgb32 GL_ARB_texture_buffer_range GL_ARB_texture_compression GL_ARB_texture_compression_bptc GL_ARB_texture_compression_rgtc GL_ARB_texture_cube_map GL_ARB_texture_cube_map_array GL_ARB_texture_env_add GL_ARB_texture_env_combine GL_ARB_texture_env_crossbar GL_ARB_texture_env_dot3 GL_ARB_texture_float GL_ARB_texture_gather GL_ARB_texture_mirror_clamp_to_edge GL_ARB_texture_mirrored_repeat GL_ARB_texture_multisample GL_ARB_texture_non_power_of_two GL_ARB_texture_query_levels GL_ARB_texture_query_lod GL_ARB_texture_rectangle GL_ARB_texture_rg GL_ARB_texture_rgb10_a2ui GL_ARB_texture_stencil8 GL_ARB_texture_storage GL_ARB_texture_storage_multisample GL_ARB_texture_swizzle GL_ARB_texture_view GL_ARB_timer_query GL_ARB_transform_feedback2 GL_ARB_transform_feedback3 GL_ARB_transform_feedback_instanced GL_ARB_transpose_matrix GL_ARB_uniform_buffer_object GL_ARB_vertex_array_bgra GL_ARB_vertex_array_object GL_ARB_vertex_attrib_64bit GL_ARB_vertex_attrib_binding GL_ARB_vertex_buffer_object GL_ARB_vertex_program GL_ARB_vertex_shader GL_ARB_vertex_type_10f_11f_11f_rev GL_ARB_vertex_type_2_10_10_10_rev GL_ARB_viewport_array GL_ARB_window_pos GL_ATI_draw_buffers GL_ATI_texture_float GL_ATI_texture_mirror_once GL_S3_s3tc GL_EXT_texture_env_add GL_EXT_abgr GL_EXT_bgra GL_EXT_bindable_uniform GL_EXT_blend_color GL_EXT_blend_equation_separate GL_EXT_blend_func_separate GL_EXT_blend_minmax GL_EXT_blend_subtract GL_EXT_compiled_vertex_array GL_EXT_Cg_shader GL_EXT_depth_bounds_test GL_EXT_direct_state_access GL_EXT_draw_buffers2 GL_EXT_draw_instanced GL_EXT_draw_range_elements GL_EXT_fog_coord GL_EXT_framebuffer_blit GL_EXT_framebuffer_multisample GL_EXTX_framebuffer_mixed_formats GL_EXT_framebuffer_multisample_blit_scaled GL_EXT_framebuffer_object GL_EXT_framebuffer_sRGB GL_EXT_geometry_shader4 GL_EXT_gpu_program_parameters GL_EXT_gpu_shader4 GL_EXT_multi_draw_arrays GL_EXT_packed_depth_stencil GL_EXT_packed_float GL_EXT_packed_pixels GL_EXT_pixel_buffer_object GL_EXT_point_parameters GL_EXT_provoking_vertex GL_EXT_rescale_normal GL_EXT_secondary_color GL_EXT_separate_shader_objects GL_EXT_separate_specular_color GL_EXT_shader_image_load_store GL_EXT_shadow_funcs GL_EXT_stencil_two_side GL_EXT_stencil_wrap GL_EXT_texture3D GL_EXT_texture_array GL_EXT_texture_buffer_object GL_EXT_texture_compression_dxt1 GL_EXT_texture_compression_latc GL_EXT_texture_compression_rgtc GL_EXT_texture_compression_s3tc GL_EXT_texture_cube_map GL_EXT_texture_edge_clamp GL_EXT_texture_env_combine GL_EXT_texture_env_dot3 GL_EXT_texture_filter_anisotropic GL_EXT_texture_integer GL_EXT_texture_lod GL_EXT_texture_lod_bias GL_EXT_texture_mirror_clamp GL_EXT_texture_object GL_EXT_texture_shared_exponent GL_EXT_texture_sRGB GL_EXT_texture_sRGB_decode GL_EXT_texture_storage GL_EXT_texture_swizzle GL_EXT_timer_query GL_EXT_transform_feedback2 GL_EXT_vertex_array GL_EXT_vertex_array_bgra GL_EXT_vertex_attrib_64bit GL_EXT_import_sync_object GL_IBM_rasterpos_clip GL_IBM_texture_mirrored_repeat GL_KHR_debug GL_KTX_buffer_region GL_NV_bindless_multi_draw_indirect GL_NV_bindless_texture GL_NV_blend_equation_advanced GL_NV_blend_square GL_NV_compute_program5 GL_NV_conditional_render GL_NV_copy_depth_to_color GL_NV_copy_image GL_NV_depth_buffer_float GL_NV_depth_clamp GL_NV_draw_texture GL_NV_ES1_1_compatibility GL_NV_explicit_multisample GL_NV_fence GL_NV_float_buffer GL_NV_fog_distance GL_NV_fragment_program GL_NV_fragment_program_option GL_NV_fragment_program2 GL_NV_framebuffer_multisample_coverage GL_NV_geometry_shader4 GL_NV_gpu_program4 GL_NV_gpu_program4_1 GL_NV_gpu_program5 GL_NV_gpu_program5_mem_extended GL_NV_gpu_program_fp64 GL_NV_gpu_shader5 GL_NV_half_float GL_NV_light_max_exponent GL_NV_multisample_coverage GL_NV_multisample_filter_hint GL_NV_occlusion_query GL_NV_packed_depth_stencil GL_NV_parameter_buffer_object GL_NV_parameter_buffer_object2 GL_NV_path_rendering GL_NV_pixel_data_range GL_NV_point_sprite GL_NV_primitive_restart GL_NV_register_combiners GL_NV_register_combiners2 GL_NV_shader_atomic_counters GL_NV_shader_atomic_float GL_NV_shader_buffer_load GL_NV_shader_storage_buffer_object GL_ARB_sparse_texture GL_NV_texgen_reflection GL_NV_texture_barrier GL_NV_texture_compression_vtc GL_NV_texture_env_combine4 GL_NV_texture_expand_normal GL_NV_texture_multisample GL_NV_texture_rectangle GL_NV_texture_shader GL_NV_texture_shader2 GL_NV_texture_shader3 GL_NV_transform_feedback GL_NV_transform_feedback2 GL_NV_vertex_array_range GL_NV_vertex_array_range2 GL_NV_vertex_attrib_integer_64bit GL_NV_vertex_buffer_unified_memory GL_NV_vertex_program GL_NV_vertex_program1_1 GL_NV_vertex_program2 GL_NV_vertex_program2_option GL_NV_vertex_program3 GL_NVX_conditional_render GL_NVX_gpu_memory_info GL_NVX_nvenc_interop GL_OES_compressed_ETC1_RGB8_texture GL_SGIS_generate_mipmap GL_SGIS_texture_lod GL_SGIX_depth_texture GL_SGIX_shadow GL_SUN_slice_accum GL_WIN_swap_hint WGL_EXT_swap_control

I think each of those extensions has a description ... I'll go and think about that
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: dedndave on November 13, 2013, 11:44:20 PM
mine fits - lol

XP mce2005 sp3, opengl v 1.4.0

(http://img842.imageshack.us/img842/5556/6apo.png)
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: hamper on November 14, 2013, 01:40:33 AM
Now things are getting VERY WIERD INDEED!
I added some printf statements into the program, to output to a console window the values for the window handle, device context and rendering context at various points in the program (the amended program and the output is attached).
It has to be a console build, but it still displays the (empty) window when it runs.

THERE ARE TWO VERY WIERD THINGS GOING ON:

1. At the start, all the values are 0. But after the window is up, I suddenly, automatically get a device context -- even though nothing in the code in between has altered in any way the value of my global variable dchandle.

2. For some reason, my global variable winhandle suddenly reverts back to 0, even though nothing that I can see has changed its value in my code. I had always thought that global variables still had scope within a procedure anyway.

Title: EUREKA!
Post by: GoneFishing on November 14, 2013, 01:53:36 AM
Finally I found reading I'd have started with first!
Open it , Read it , Enjoy it ! :biggrin:
Platform specifics: Windows (http://www.opengl.org/wiki/Platform_specifics:_Windows)

EDIT: here's info about OpenGL Extensions (http://www.opengl.org/registry/#arbextspecs)
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: hamper on November 14, 2013, 03:35:40 AM
Re. my previous post, I also noticed that the sequence I was expecting...

      "Start...
      "After window up...

isn't the sequence that actually happens.

The actual sequence is...

      "Start...
      "Before initialisation...
      "After initialisation...
      "After window up...

So the window procedure must get called automatically, with a WM_CREATE message, before the message loop even starts.
That explains where my "phantom" device context is coming from, but it still doesn't explain (as far as I can see) why my global variable 'winhandle' suddenly gets reset to zero.
(And I still can't get a rendering context)
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: hamper on November 14, 2013, 03:49:49 AM
IT'S FINALLY ALL DROPPED INTO PLACE!
LIKE A EUREKA MOMENT ARCHIE,

The window procedure gets called automatically with a WM_CREATE message even before CreateWindowExA returns! So the initialisation sequence doesn't even have a window handle yet, because CreateWindowExA hasn't yet returned with one. So I can't even push a window handle yet, and that's why nothing works.

Now that I know what the actual sequence of operations is behind the scenes, it should be a simple matter to finally organise the code into the correct sequence for getting everything up and running.

TTFN
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: dedndave on November 14, 2013, 04:04:51 AM
that's right
the earliest moment that your program knows the window handle is during WM_CREATE
when you call CreateWindowEx, the WM_CREATE message is sent to the WndProc
if WM_CREATE returns a value of -1 in EAX, window creation fails, and CreateWindowEx returns 0
if WM_CREATE returns any other value (should be 0) in EAX, window creation is successful and CreateWindowEx returns a handle
of course, this is only true if all the CreateWindowEx parameters are valid

the point is, the WM_CREATE code executes before CreateWindowEx returns to the caller
i often initialize the global hwndMain variable in the first few lines of WM_CREATE code, rather than after the CreateWindowEx call
    .if uMsg==WM_CREATE
        mov     edx,hWnd          ;from the WndProc parameter
        mov     hwndMain,edx

; rest of init code

        xor     eax,eax           ;WndProc returns 0 in EAX
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: jj2007 on November 14, 2013, 04:08:30 AM
Quote from: hamper on November 14, 2013, 03:49:49 AMSo the initialisation sequence doesn't even have a window handle yet, because CreateWindowExA hasn't yet returned with one.

Congrats, you are on the right track now :t

Quote from: jj2007 on November 13, 2013, 08:49:43 AM
There is one obvious problem:
   initialiseopengl:
      push winhandle
      call GetDC

You are pushing zero here
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: dedndave on November 14, 2013, 04:08:53 AM
also....
when you call GetDC with hWnd=0, you get the desktop DC
HWND_DESKTOP is a windows constant, and has a value of 0
so - you still get an HDC - just not the one you are looking for

after making a few changes, i got your code to run
and, the triangle spins like a bat out of hell - lol
you may want to move the update call out of the message loop, now
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: hamper on November 14, 2013, 06:44:02 AM
Well dedndave, perhaps you could post your program so that I can see how it should be done, because I've tried just about every permutation I can possibly think of, and all I EVER get is (sometimes) a very brief flash of black, then the same little window again, and again, and again, .......... No matter what I try, it just doesn't work.

Maybe you could also zip up the .exe version as well. At least I'll be able to see FOR THE FIRST TIME what it's supposed to look like when it runs.
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: GoneFishing on November 14, 2013, 06:54:47 AM
BTW could you tell us which IDE you use ,
also which version of ML ?
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: jj2007 on November 14, 2013, 06:56:34 AM
Quote from: hamper on November 14, 2013, 06:44:02 AMAt least I'll be able to see FOR THE FIRST TIME what it's supposed to look like when it runs.

A working version is available since reply #44 - just run the attached exe.
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: dedndave on November 14, 2013, 07:03:48 AM
i didn't comment my changes, so here is a list
1) i changed the "preamble" so that it would assemble correctly with my setup
include \masm32\include\kernel32.inc
include \masm32\include\user32.inc
include \masm32\include\msvcrt.inc
include \masm32\include\masm32.inc
include \masm32\macros\macros.asm

includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\user32.lib
includelib \masm32\lib\opengl32.lib
includelib \masm32\lib\msvcrt.lib
includelib \masm32\lib\masm32.lib

2) because the kernel32 (et al) include files define some of the PROTO'types, i commented some of yours out
;CreateWindowExA      proto :dword,:dword,:dword,:dword,:dword,:dword,
;                           :dword,:dword,:dword,:dword,:dword,:dword
;DefWindowProcA       proto :dword,:dword,:dword,:dword
;DispatchMessageA     proto :dword
;ExitProcess          proto :dword
;GetModuleHandleA     proto :dword
;LoadCursorA          proto :dword,:dword
;LoadIconA            proto :dword,:dword
;PeekMessageA         proto :dword,:dword,:dword,:dword,:dword
;PostQuitMessage      proto :dword
;RegisterClassExA     proto :dword
;windowproc           proto :dword,:dword,:dword,:dword
;GetDC                proto :dword
wglChoosePixelFormat proto :dword,:dword
wglSetPixelFormat    proto :dword,:sdword,:dword
wglCreateContext     proto :dword
wglMakeCurrent       proto :dword,:dword
wglDeleteContext     proto :dword
;ReleaseDC            proto :dword,:dword
glViewport           proto :sdword,:sdword,:sdword,:sdword
glMatrixMode         proto :dword
glOrtho              proto :real8,:real8,:real8,:real8,:real8,:real8
glClearColor         proto :real4,:real4,:real4,:real4
glClear              proto :dword
glPushMatrix         proto
glPopMatrix          proto
glRotatef            proto :real4,:real4,:real4,:real4
glBegin              proto :dword
glEnd                proto
glColor3fv           proto :dword
glVertex3fv          proto :dword
glFlush              proto
wglSwapBuffers       proto :dword
rendernextframe      proto
;ShowWindow           proto :dword,:dword
;UpdateWindow         proto :dword

3) i added "invoke AllocConsole" - now, you assemble as a windows program, and a console also comes up
4) i had problems with printf, so i replaced those lines with print macro calls - no biggy, there
5) i initialize "winhandle" in WM_CREATE, as mentioned above
i also use that handle for GetDC
      mov edx,hwnd
      mov winhandle,edx
      push edx
      call GetDC

6) i return 0 in EAX for both WM_CREATE and WM_CLOSE
    xor     eax,eax
    ret


(http://img854.imageshack.us/img854/3121/heq2.png)
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: hamper on November 14, 2013, 07:10:00 AM
Sure,

I don't use an IDE as such. I just use Crimson text editor, and have set up a build batch file. For a windows program it's set up thus:

@echo off
if exist %1.exe del %1.exe
ml /nologo /coff %1.asm /link /nologo /subsystem:windows
if exist %1.obj del %1.obj
exit

I use ML.EXE version 6.15.8803
and LINK.EXE version 5.12.8078

Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: dedndave on November 14, 2013, 07:10:23 AM
if that doesn't work on your machine, let me know - tell me what OS you are using
there are a few possibilities
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: GoneFishing on November 14, 2013, 07:10:52 AM
oops  :(
nither your version ,Dave, nor Jochen's works here
but qWord's one  really does (I guess he knows magic words)
don't know why
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: Gunther on November 14, 2013, 07:17:44 AM
Dave,

your EXE works, but the child window has a blue background, no triangle is shown.

Gunther
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: dedndave on November 14, 2013, 07:20:39 AM
well - i have the microsoft PSDK installed on my machine
Jochen may also
that includes the OpenGl libraries
in other words, the wgl version of 5 functions we talked about earlier may work on our machine - but not others

could also be a version issue, but i think the previous issue is more likely

you should be able to make that work by using the GDI version of
ChoosePixelformat, DescribePixelformat, GetPixelformat, SetPixelformat, SwapBuffers
(just remove the "wgl" prefixes and reassemble)
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: hamper on November 14, 2013, 07:21:17 AM
Well, dave, I ran your opengltest2.exe file and all I got was the attached image.
Just the same little static window again - no triangle, no nothing.
That's a bit strange isn't it? What could possibly cause your .exe file not to run properly?
I'm on Windows XP SP2, running on an Acer Laptop with an Intel cpu, so my system's pretty bog standard I think.
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: GoneFishing on November 14, 2013, 07:23:02 AM
for me it has black background
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: dedndave on November 14, 2013, 07:28:21 AM
ok - i switched to the GDI calls
and, added gdi32.lib to the preamble

see if that makes a difference
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: GoneFishing on November 14, 2013, 07:30:16 AM
Dave,
Now it's OK  :t
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: dedndave on November 14, 2013, 07:34:11 AM
so - that's the problem
Jochen and i have the development stuff installed, per the document that drizz gave us
the wgl calls work for us, but we need to use the GDI calls in code
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: hamper on November 14, 2013, 07:40:31 AM
Yes dave,

B I N G O !!!!

I changed my ORIGINAL program to use ChoosePixelFormat, SetPixelFormat and SwapBuffers instead of the "wgl" versions, added
includelib gdi32

and now I get the spinning triangle on a black background .......... at last!

Many, many thanks.

As you say, it goes like a bat out of hell. An awful lot faster than the C version (which revolves around quite slowly).

You won't believe what a relief it is. I was on the verge of packing it all in, in the belief that my programming sucked. But now I now that it works, it's like having a cup of tea.

Right, DOOM VII here I come.


Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: dedndave on November 14, 2013, 07:42:12 AM
speaking of tea.....

you have to have patience - or develop some - lol
if not, asm is not your cup of tea   :t
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: Gunther on November 14, 2013, 07:59:44 AM
Dave,

works fine now under XP (VM), but not under 64 bit Windows 7.

Gunther
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: jj2007 on November 14, 2013, 08:09:51 AM
Quote from: dedndave on November 14, 2013, 07:34:11 AM
Jochen and i have the development stuff installed, per the document that drizz gave us
the wgl calls work for us, but we need to use the GDI calls in code

I have nothing particular installed, certainly nothing related specifically to OpenGL (I have never used it before). However, the standard Masm32 installation has \Masm32\include\opengl32.inc and the matching library. I have no clue why the exe I posted in #44 shouldn't work - it runs just fine on XP SP2, on Win7-32 and on Win7-64. By the way, both with the standard GDI and with their wgl.... equivalents.

Attached a version that works with plain Masm32 (no MasmBasic required). Tested OK on XP SP2, on Win7-32 and on Win7-64.
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: GoneFishing on November 14, 2013, 08:22:23 AM
Hi Jochen,
These problems with OpenGL on different machines seem never stop if not been stopped
it's just like beer which is never enough ...
but I must go and buy some more now  ;)
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: dedndave on November 14, 2013, 11:36:49 AM
ok Jochen
i figured you might have the PSDK or maybe VS installed

we need to figure out what's up with Gunther's machine so we can avoid it in the future
maybe it has to do with the message loop calls

let me finish my "cleaned-up" version
in the mean time, Gunther can test Jochen's latest post and qWord's "foo" on his win7-64 machine   :biggrin:
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: hamper on November 14, 2013, 11:39:37 AM
Well, for what it's worth here's my final, finished, complete, working program!
It's taken a long time and much heartache, but it diplays a multi-coloured revolving triangle inside a little window.
Thanks to everyone (esp. dave) for all your help, and my sincere apologies for throwing a bit of a wobbly here and there (just frustration -- as it turns out it was the library files not performing as they should).
Enjoy!
After all, we all need a good spinning triangle now and then.
Regards,
Phil

;--------------------------------------------------------------------------------------
; A simple OpenGL example                                                    opengl.asm
;--------------------------------------------------------------------------------------

.686
.model flat,stdcall
option casemap:none

includelib gdi32
includelib kernel32
includelib opengl32
includelib user32

;--------------------------------------------------------------------------------------

CreateWindowExA   proto :dword,:dword,:dword,:dword,:dword,:dword,
                        :dword,:dword,:dword,:dword,:dword,:dword
DefWindowProcA    proto :dword,:dword,:dword,:dword
DispatchMessageA  proto :dword
ExitProcess       proto :dword
GetModuleHandleA  proto :dword
LoadCursorA       proto :dword,:dword
LoadIconA         proto :dword,:dword
PostQuitMessage   proto :dword
RegisterClassExA  proto :dword
windowproc        proto :dword,:dword,:dword,:dword

ChoosePixelFormat proto :dword,:dword
GetDC             proto :dword
glBegin           proto :dword
glClear           proto :dword
glClearColor      proto :real4,:real4,:real4,:real4
glColor3fv        proto :dword
glEnd             proto
glMatrixMode      proto :dword
glOrtho           proto :real8,:real8,:real8,:real8,:real8,:real8
glPopMatrix       proto
glPushMatrix      proto
glRotatef         proto :real4,:real4,:real4,:real4
glVertex3fv       proto :dword
glViewport        proto :sdword,:sdword,:sdword,:sdword
PeekMessageA      proto :dword,:dword,:dword,:dword,:dword
ReleaseDC         proto :dword,:dword
rendernextframe   proto
SetPixelFormat    proto :dword,:sdword,:dword
SwapBuffers       proto :dword
wglCreateContext  proto :dword
wglDeleteContext  proto :dword
wglMakeCurrent    proto :dword,:dword

point struct
   x dword ?
   y dword ?
point ends

msgst struct
   hwnd    dword ?
   message dword ?
   wparam  dword ?
   lparam  dword ?
   time    dword ?
   pt      point <>
msgst ends

windowclasstype struct
   wcsize        dword ?
   style         dword ?
   addrwp        dword ?
   classeb       dword ?
   windoweb      dword ?
   proghandle    dword ?
   liconhandle   dword ?
   cursorhandle  dword ?
   colour        dword ?
   menuhandle    dword ?
   addrclassname dword ?
   siconhandle   dword ?
windowclasstype ends

pfdtype struct
   nsize           word  40
   nversion        word  1
   dwflags         dword 4133
   ipixeltype      byte  0
   ccolorbits      byte  32
   credbits        byte  0
   credshift       byte  0
   cgreenbits      byte  0
   cgreenshift     byte  0
   cbluebits       byte  0
   cblueshift      byte  0
   calphabits      byte  0
   calphashift     byte  0
   caccumbits      byte  0
   caccumredbits   byte  0
   caccumgreenbits byte  0
   caccumbluebits  byte  0
   caccumalphabits byte  0
   cdepthbits      byte  32
   cstencilbits    byte  0
   cauxbuffers     byte  0
   ilayertype      byte  0
   breserved       byte  0
   dwlayermask     dword 0
   dwvisiblemask   dword 0
   dwdamagemask    dword 0
pfdtype ends

;--------------------------------------------------------------------------------------

.const
classname   byte "SimpleWinClass",0
windowtitle byte "The window title",0

.data?
msg         msgst <>
mywc        windowclasstype <>
winhandle   dword ?
dchandle    dword ?
rchandle    dword ?

.data
mybgcolour  real4 0.0,0.0,0.0,1.0   ; black
mycolours   real4 1.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0
myortho     real8 1.0,1.0,-1.0,1.3,0.5,1.5
myrot       real4 0.0,0.0,0.0,1.0
myrotsdw    sdword 0
pfd         pfdtype <>
myvertices  real4 0.0,1.0,1.0,0.87,-0.5,1.0,-0.87,-0.5,1.0

.code
start:

;######################################################################################

;---------- fill up the window class structure variable and get the program handle etc.

mov mywc.wcsize,48
mov mywc.style,35
mov mywc.addrwp,offset windowproc
mov mywc.classeb,0
mov mywc.windoweb,0
push 0
call GetModuleHandleA
mov mywc.proghandle,eax
push 32515
push 0
call LoadIconA
mov mywc.liconhandle,eax
mov mywc.siconhandle,eax
push 32515
push 0
call LoadCursorA
mov mywc.cursorhandle,eax
mov mywc.colour,2
mov mywc.menuhandle,0
mov mywc.addrclassname,offset classname

;---------- register the window class

push offset mywc
call RegisterClassExA

;---------- create and display the window

push 0
push mywc.proghandle
push 0
push 0
push 340         ; window height
push 320         ; window width
push 230         ; window top position
push 480         ; window left position
push 269418496
push offset windowtitle
push mywc.addrclassname
push 0
call CreateWindowExA
mov winhandle,eax

;---------- initialise OpenGL

push winhandle
call GetDC
mov  dchandle,eax
push offset pfd
push dchandle
call ChoosePixelFormat
push offset pfd
push eax
push dchandle
call SetPixelFormat
push dchandle
call wglCreateContext
mov  rchandle,eax
push rchandle
push dchandle
call wglMakeCurrent
push 5889
call glMatrixMode            ; projection matrix stack
push 300                     ; height
push 300                     ; width
push 10                      ; y
push 10                      ; x
call glViewport              ; set viewport
push dword ptr myortho[44]
push dword ptr myortho[40]
push dword ptr myortho[36]
push dword ptr myortho[32]
push dword ptr myortho[28]
push dword ptr myortho[24]
push dword ptr myortho[20]
push dword ptr myortho[16]
push dword ptr myortho[12]
push dword ptr myortho[8]
push dword ptr myortho[4]
push dword ptr myortho       ; orthographic projection
call glOrtho
push 5888
call glMatrixMode            ; modelview matrix stack
push mybgcolour[12]
push mybgcolour[8]
push mybgcolour[4]
push mybgcolour
call glClearColor            ; background colour to clear to

;---------- the message loop

msgloopstart:
   push 1                 ; messages will be retrieved
   push 0
   push 0
   push winhandle
   push offset msg
   call PeekMessageA
   cmp  eax,0
   jne  messageretrieved
   call rendernextframe   ; no message pending, so render next frame
   jmp  msgloopstart
messageretrieved:
   cmp  msg.message,18    ; WM_QUIT
   je   msgloopend
   push offset msg
   call DispatchMessageA
   jmp  msgloopstart
msgloopend:
   push rchandle
   call wglDeleteContext
   push dchandle
   push winhandle
   call ReleaseDC
   push 0
   call ExitProcess

;######################################################################################

;---------- the window procedure

windowproc proc hwnd:dword,message:dword,wparam:dword,lparam:dword

cmp message,16 ; WM_CLOSE
je its16

; default processing
push lparam
push wparam
push message
push hwnd
call DefWindowProcA
ret

its16:
push 0
call PostQuitMessage
ret

windowproc endp


;---------- rendering the next frame

rendernextframe proc

   push 16384
   call glClear                 ; clear window to background colour
   call glPushMatrix            ; push the matrix stack
   inc  myrotsdw                ; perform any translations, scales, rotations etc.
   cmp  myrotsdw,360
   jne  carryon
   mov  myrotsdw,0
carryon:
   finit
   fild myrotsdw
   fst  myrot
   push myrot[12]
   push myrot[8]
   push myrot[4]
   push myrot
   call glRotatef
   push 4
   call glBegin                 ; draw objects
   push offset mycolours
   call glColor3fv
   push offset myvertices
   call glVertex3fv
   push offset mycolours[12]
   call glColor3fv
   push offset myvertices[12]
   call glVertex3fv
   push offset mycolours[24]
   call glColor3fv
   push offset myvertices[24]
   call glVertex3fv
   call glEnd
   call glPopMatrix             ; pop the matrix stack
   push dchandle
   call SwapBuffers             ; swap buffers (with automatic flush)
ret

rendernextframe endp

;######################################################################################

end start

Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: dedndave on November 14, 2013, 11:45:34 AM
are you Australian ?
not the only one on board, in fact the guy that runs the place (Hutch) is an Aussie   :P
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: hamper on November 14, 2013, 11:51:29 AM
No mate, English. Up in the Yorkshire Dales actually. Not rich enough to be an Aussie. But well versed enough on bloody sheep to be one.
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: dedndave on November 14, 2013, 12:02:54 PM
ok - i just noticed some words, is all - lol
wifee is a Brummy   :P
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: dedndave on November 14, 2013, 02:52:20 PM
well - it works
there are a few things i don't understand, yet
part of the learning curve

i am interested to see if it works on Gunther's win7-64 machine   :P
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: Gunther on November 14, 2013, 08:43:16 PM
Hi Dave,

Quote from: dedndave on November 14, 2013, 02:52:20 PM
i am interested to see if it works on Gunther's win7-64 machine   :P

I'm interested, too. But at the moment I've to do some lessons (only a short break). I'll download the appropriate archive this evening and test it.

Gunther
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: FORTRANS on November 15, 2013, 01:00:22 AM
Hi,

   In Reply #49, qWord's foo works on XP and just shows a black
window on Win2k.  In Reply #96, Dave's SmallOgl3 shows a black
window on Win2k.  At first it seemed to just show a black window
on XP, but if I grabbed the title bar and moved the window around,
the triangle shows up.

Cheers,

Steve
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: dedndave on November 15, 2013, 02:04:02 AM
thanks for the report, Steve
that's a little odd   :P

this one does things a little differently, maybe it will fix the problems you mentioned
i use the multi-media timer so that it updates once every mS
thing about that is, the mm timer runs in it's own thread
OpenGL seems to want everything in one thread
i cheated a little and used PostMessage to send a WM_TIMER message
i guess i could register a user message to be more correct   ;)

but - i also handle the WM_PAINT messages so that the updates are "windows-happy"

EDIT: small RC file change to make the icon appear in the title bar
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: GoneFishing on November 15, 2013, 02:52:38 AM
nice  :t
runs fine here
with such a speed that I can see much more than just a simple triangle  :biggrin:
one minor problem  - the triangle seems to enjoy itself and doesn't want to stop unless  persuaded with Task Manager
EDIT: one more thing - "Busy" cursor
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: jj2007 on November 15, 2013, 03:00:38 AM
Quote from: vertograd on November 15, 2013, 02:52:38 AM
nice  :t
runs fine here
with such a speed that I can see much more than just a simple triangle  :biggrin:
one minor problem  - the triangle seems to enjoy itself and doesn't want to stop unless  persuaded with Task Manager

See this post (http://masm32.com/board/index.php?topic=2582.msg27244#msg27244). Try pushing 1 or 7 instead of eax=4 before SetPixelFormat.

You don't need Task Manager to stop it. In reply #44 I posted one that ends smoothly by pressing Shift, but all other versions posted here also stop when clicking Close in the system menu. They do not stop when clicking the x in the upper right corner, though.
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: GoneFishing on November 15, 2013, 03:04:19 AM
Quote from: jj2007 on November 15, 2013, 03:00:38 AM
Quote from: vertograd on November 15, 2013, 02:52:38 AM
nice  :t
runs fine here
with such a speed that I can see much more than just a simple triangle  :biggrin:
one minor problem  - the triangle seems to enjoy itself and doesn't want to stop unless  persuaded with Task Manager

See this post (http://masm32.com/board/index.php?topic=2582.msg27244#msg27244). Try pushing 1 or 7 instead of eax=4 before SetPixelFormat.

You don't need Task Manager to stop it. In reply #44 I posted one that ends smoothly by pressing Shift, but all other versions posted here also stop when clicking Close in the system menu. They do not stop when clicking the x in the upper right corner, though.

Task Manager is the only way to stop it
no system menu , no ALT-F4, no Shift
Just ran your OGL_Test from Reply #44 . It doesn't respond on pressing Shift here
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: FORTRANS on November 15, 2013, 03:48:38 AM
Hi Dave,

   Tried SmallOgl4a from Reply #99.  Win2k, quite fast triangle so
looks ragged, 100% CPU, and needs task manager to kill it.  On XP
blank window until wiggled, then some rough triangle stuff, can be
closed normally.  When not wiggling, erratic CPU usage, mostly low,
a few percent, but blips of ~30% or ~70%, and can hit 100% right
after a wiggle session.  While moving around CPU seems to mostly
alternate between ~35% and ~65%.  Definitely different behavior.
Numbers are very approximate.

Regards,

Steve N.
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: jj2007 on November 15, 2013, 04:57:25 AM
Quote from: vertograd on November 15, 2013, 03:04:19 AM
Just ran your OGL_Test from Reply #44 . It doesn't respond on pressing Shift here

Oops, that was a version without GetKeyState. This one (http://masm32.com/board/index.php?topic=2582.msg27308#msg27308) is better... plain Masm32, 3k exe.
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: GoneFishing on November 15, 2013, 05:06:18 AM
Quote from: jj2007 on November 15, 2013, 04:57:25 AM
This one (http://masm32.com/board/index.php?topic=2582.msg27308#msg27308) is better... plain Masm32, 3k exe.
that one works fine
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: Gunther on November 15, 2013, 06:07:59 AM
Dave,

version 3 and 4 work fine under XP with VirtualPC, but not under Windows 7 (empty black window, no triangle).

Gunther
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: dedndave on November 15, 2013, 08:42:21 AM
many thanks for all the reports   :t

maybe the flags have something to do with it
i am working on a new version that may also address the close button problems   :P

there are a few other flags - they appear to be device and/or version dependant
unless we want to get into writing seperate code for different platforms, we can more or less ignore them
(at least while we're in the learning phase - lol)
;-----------------------------------------
;
;PIXELFORMATDESCRIPTOR structure members:
;
;nSize           dw ? ;structure size
;nVersion        dw ? ;always set to 1
;dwFlags         dd ? ;various combinations of pixel buffer property flags                            (see notes below)
;iPixelType      db ? ;one of the following: PFD_TYPE_RGBA, PFD_TYPE_COLORINDEX
;cColorBits      db ? ;number of color bitplanes in each color buffer
;cRedBits        db ? ;number of red bitplanes in each RGBA buffer                    (only used with PFD_NEED_PALETTE)
;cRedShift       db ? ;shift count for red bitplanes in each RGBA buffer              (only used with PFD_NEED_PALETTE)
;cGreenBits      db ? ;number of green bitplanes in each RGBA buffer                  (only used with PFD_NEED_PALETTE)
;cGreenShift     db ? ;shift count for green bitplanes in each RGBA buffer            (only used with PFD_NEED_PALETTE)
;cBlueBits       db ? ;number of blue bitplanes in each RGBA buffer                   (only used with PFD_NEED_PALETTE)
;cBlueShift      db ? ;shift count for blue bitplanes in each RGBA buffer             (only used with PFD_NEED_PALETTE)
;cAlphaBits      db ? ;number of alpha bitplanes in each RGBA buffer                                    (not supported)
;cAlphaShift     db ? ;shift count for alpha bitplanes in each RGBA buffer                              (not supported)
;cAccumBits      db ? ;number of bitplanes in the accumulation buffer                                   (not supported)
;cAccumRedBits   db ? ;number of red bitplanes in the accumulation buffer                               (not supported)
;cAccumGreenBits db ? ;number of green bitplanes in the accumulation buffer                             (not supported)
;cAccumBlueBits  db ? ;number of blue bitplanes in the accumulation buffer                              (not supported)
;cAccumAlphaBits db ? ;number of alpha bitplanes in the accumulation buffer                             (not supported)
;cDepthBits      db ? ;bit depth of z-buffer
;cStencilBits    db ? ;bit depth of stencil buffer
;cAuxBuffers     db ? ;number of auxiliary buffers                                                      (not supported)
;iLayerType      db ? ;one of the following: PFD_MAIN_PLANE, PFD_OVERLAY_PLANE, PFD_UNDERLAY_PLANE     (no longer used)
;bReserved       db ? ;low 4 bits = overlay planes, high 4 bits = underlay planes
;dwLayerMask     dd ? ;                                                                                (no longer used)
;dwVisibleMask   dd ? ;transparent underlay plane color (PFD_TYPE_RGBA) or index (PFD_TYPE_COLORINDEX)
;dwDamageMask    dd ? ;                                                                                (no longer used)
;
;-----------------------------------------
;
;dwFlags bits:
;
;PFD_DOUBLEBUFFER          00000001h The buffer is double-buffered. This flag and PFD_SUPPORT_GDI
;                                    are mutually exclusive in the current generic implementation.
;
;PFD_STEREO                00000002h The buffer is stereoscopic. This flag is not
;                                    supported in the current generic implementation.
;
;PFD_DRAW_TO_WINDOW        00000004h The buffer can draw to a window or device surface.
;
;PFD_DRAW_TO_BITMAP        00000008h The buffer can draw to a memory bitmap.
;
;PFD_SUPPORT_GDI           00000010h The buffer supports GDI drawing. This flag and PFD_DOUBLEBUFFER
;                                    are mutually exclusive in the current generic implementation.
;
;PFD_SUPPORT_OPENGL        00000020h The buffer supports OpenGL drawing.
;
;PFD_GENERIC_FORMAT        00000040h The pixel format is supported by the GDI software implementation,
;                                    which is also known as the generic implementation. If this bit is
;                                    clear, the pixel format is supported by a device driver or hardware.
;
;PFD_NEED_PALETTE          00000080h The buffer uses RGBA pixels on a palette-managed device. A logical
;                                    palette is required to achieve the best results for this pixel type.
;                                    Colors in the palette should be specified according to the values
;                                    of the cRedBits, cRedShift, cGreenBits, cGreenShift, cBluebits, and
;                                    cBlueShift members. The palette should be created and realized in
;                                    the device context before calling wglMakeCurrent.
;
;PFD_NEED_SYSTEM_PALETTE   00000100h Defined in the pixel format descriptors of hardware that supports one
;                                    hardware palette in 256-color mode only. For such systems to use
;                                    hardware acceleration, the hardware palette must be in a fixed order
;                                    (for example, 3-3-2) when in RGBA mode or must match the logical
;                                    palette when in color-index mode. When this flag is set, you must call
;                                    SetSystemPaletteUse in your program to force a one-to-one mapping of
;                                    the logical palette and the system palette. If your OpenGL hardware
;                                    supports multiple hardware palettes and the device driver can allocate
;                                    spare hardware palettes for OpenGL, this flag is typically clear.
;                                    This flag is not set in the generic pixel formats.
;
;PFD_SWAP_LAYER_BUFFERS    00000800h Indicates whether a device can swap individual layer planes with pixel
;                                    formats that include double-buffered overlay or underlay planes.
;                                    Otherwise all layer planes are swapped together as a group. When this
;                                    flag is set, wglSwapLayerBuffers is supported.
;
;PFD_GENERIC_ACCELERATED   00001000h The pixel format is supported by a device driver that accelerates
;                                    the generic implementation. If this flag is clear and the
;                                    PFD_GENERIC_FORMAT flag is set, the pixel format is supported by
;                                    the generic implementation only.
;
;Additional flags for use with ChoosePixelFormat only:
;
;PFD_DEPTH_DONTCARE        20000000h The requested pixel format can either have or not have a depth buffer.
;                                    To select a pixel format without a depth buffer, you must specify this
;                                    flag. The requested pixel format can be with or without a depth buffer.
;                                    Otherwise, only pixel formats with a depth buffer are considered.
;
;PFD_DOUBLEBUFFER_DONTCARE 40000000h The requested pixel format can be either single- or double-buffered.
;
;PFD_STEREO_DONTCARE       80000000h The requested pixel format can be either monoscopic or stereoscopic.
;
;-----------------------------------------

by the way, the example code on MSDN for ChoosePixelFormat violates some of the rules   ::)
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: dedndave on November 15, 2013, 10:06:33 AM
ok - fingers crossed   :redface:

i can open 6 instances and they all run pretty fast   :P
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: GoneFishing on November 15, 2013, 11:33:05 PM
runs perfectly here  :t
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: dedndave on November 15, 2013, 11:36:01 PM
good to hear
so - the close button issue seems to be related to an over-flowing message queue
hopefully, the pfd flag changes make it work on Gunther's win7-64 machine
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: FORTRANS on November 16, 2013, 12:48:33 AM
Hi Dave,

   SmallOgl5 from Reply #108.  Back to a blank, black window
with Windows 2000, but it closes normally.  On XP it is similar to
last time, blank window until wiggled, then some rough triangle
stuff, can be closed normally.  CPU usage seems to be smaller,
~20% to ~50% when wiggled.

Regards,

Steve
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: dedndave on November 16, 2013, 01:00:54 AM
thanks Steve
i guess i can understand the win 2000 issue - but let's see if we can fix it
the xp issue, i don't understand - lol

i am going to make a special version for you to try on both machines.....

maybe you could get a screen shot of "rough triangle stuff" ?
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: FORTRANS on November 16, 2013, 01:56:36 AM
Hi Dave,

   Okay, tried to get a screen capture, using the Print Screen key.
Got only blank windows or a perfect triangle.  What it looks like is
pieces, horizontal slices, of multiple triangles spaced a little bit apart.
They appear dimmer than when a "good" version ran.  But as this
is a laptop, that could be the speed of the LCD.  That because the
grabbed triangle flashed to normal brightness.  A piece of a triangle,
or triangles, can also show up occasionally when there is mouse
movement around the window or other activity such as switching
between programs.

   At a rough guess, it looks kind of like it would if it is trying to draw
triangles way, way too fast, and pieces show up when the computer
tries to update the screen and gets busy enough to pause long enough
to have something drawn to the screen.  (Hope that makes sense.)

   A bit later I will try my other XP laptop.  It might provide another
data point.  (?)

Regards,

Steve N.
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: FORTRANS on November 16, 2013, 02:23:41 AM
Hi Dave,

   Oh, you are going to love this.  I reran the various versions
on my Win2k machine, and get different results.  The program's
behavior depends on whether it is started from the CLI in a window,
(blank) or from a CLI from a full screen session (various triangle
displays).  I knew this machine was a bit strange, but still...  Ick,
more tests to schedule.

Regards,

Steve N.
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: dedndave on November 16, 2013, 02:32:35 AM
on the one, it sounds like the LCD may be "submarined"
an effect caused on some older LCD's where updates are too fast (happened with mouse pointers a lot)

i slowed this version down to 10 mS per degree - see if that helps

also, this version creates a text file with complete OS and OpenGL versions and extensions
much appreciated if you can post the results or zip/attach   :P
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: dedndave on November 16, 2013, 02:35:37 AM
this is what mine looks like:
            Windows Version: 5.1.2600
                Platform ID: 2
Service Pack Version String: Service Pack 3
Service Pack Version Number: 3.0
                 Suite Mask: 00000100
               Product Type: 1
              Reserved Byte: 0

             OpenGL Version: 1.4.0 - Build 7.14.10.4764

          OpenGL Extensions:
GL_ARB_depth_texture GL_ARB_fragment_program GL_ARB_multitexture GL_ARB_point_parameters GL_ARB_shadow GL_ARB_texture_border_clamp GL_ARB_texture_compression
GL_ARB_texture_cube_map GL_ARB_texture_env_add GL_ARB_texture_env_combine GL_ARB_texture_env_dot3 GL_ARB_texture_env_crossbar GL_ARB_transpose_matrix
GL_ARB_vertex_buffer_object GL_ARB_vertex_program GL_ARB_window_pos GL_EXT_abgr GL_EXT_bgra GL_EXT_blend_color GL_EXT_blend_func_separate GL_EXT_blend_minmax
GL_EXT_blend_subtract GL_EXT_clip_volume_hint GL_EXT_compiled_vertex_array GL_EXT_cull_vertex GL_EXT_draw_range_elements GL_EXT_fog_coord GL_EXT_multi_draw_arrays
GL_EXT_packed_pixels GL_EXT_rescale_normal GL_EXT_secondary_color GL_EXT_separate_specular_color GL_EXT_shadow_funcs GL_EXT_stencil_two_side GL_EXT_stencil_wrap
GL_EXT_texture_compression_s3tc GL_EXT_texture_env_add GL_EXT_texture_env_combine GL_EXT_texture_filter_anisotropic GL_EXT_texture3D
GL_3DFX_texture_compression_FXT1 GL_IBM_texture_mirrored_repeat GL_NV_blend_square GL_NV_texgen_reflection GL_SGIS_generate_mipmap GL_WIN_swap_hint


the GL_EXTENSIONS call returns one big string with no Cr/Lf's - lol
i added some in the post to make it read a little better
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: FORTRANS on November 16, 2013, 04:33:23 AM
Quote from: dedndave on November 16, 2013, 02:32:35 AM
also, this version creates a text file with complete OS and OpenGL versions and extensions
much appreciated if you can post the results or zip/attach   :P

Hi Dave,

   Well, I hope you can appreciate the results I am attaching.  Four
computers, three tested as CLI in a window, CLI full screen, and
GUI double clicked.  One with just both CLI invocations.  Does not
make much sense to me.

Regards,

Steve
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: Siekmanski on November 16, 2013, 06:12:34 AM
Hi Dave,


            Windows Version: 6.2.9200
                Platform ID: 2
Service Pack Version String:
Service Pack Version Number: 0.0
                 Suite Mask: 00000300
               Product Type: 1
              Reserved Byte: 0

             OpenGL Version: 4.4.0

          OpenGL Extensions:
GL_AMD_multi_draw_indirect GL_AMD_seamless_cubemap_per_texture GL_ARB_arrays_of_arrays GL_ARB_base_instance
GL_ARB_bindless_texture GL_ARB_blend_func_extended GL_ARB_buffer_storage GL_ARB_clear_buffer_object GL_ARB_clear_texture
GL_ARB_color_buffer_float GL_ARB_compatibility GL_ARB_compressed_texture_pixel_storage GL_ARB_conservative_depth
GL_ARB_compute_shader GL_ARB_compute_variable_group_size GL_ARB_copy_buffer GL_ARB_copy_image GL_ARB_debug_output
GL_ARB_depth_buffer_float GL_ARB_depth_clamp GL_ARB_depth_texture GL_ARB_draw_buffers GL_ARB_draw_buffers_blend
GL_ARB_draw_indirect GL_ARB_draw_elements_base_vertex GL_ARB_draw_instanced GL_ARB_enhanced_layouts GL_ARB_ES2_compatibility
GL_ARB_ES3_compatibility GL_ARB_explicit_attrib_location GL_ARB_explicit_uniform_location GL_ARB_fragment_coord_conventions
GL_ARB_fragment_layer_viewport GL_ARB_fragment_program GL_ARB_fragment_program_shadow GL_ARB_fragment_shader
GL_ARB_framebuffer_no_attachments GL_ARB_framebuffer_object GL_ARB_framebuffer_sRGB GL_ARB_geometry_shader4
GL_ARB_get_program_binary GL_ARB_gpu_shader5 GL_ARB_gpu_shader_fp64 GL_ARB_half_float_pixel GL_ARB_half_float_vertex
GL_ARB_imaging GL_ARB_indirect_parameters GL_ARB_instanced_arrays GL_ARB_internalformat_query GL_ARB_internalformat_query2
GL_ARB_invalidate_subdata GL_ARB_map_buffer_alignment GL_ARB_map_buffer_range GL_ARB_multi_bind GL_ARB_multi_draw_indirect
GL_ARB_multisample GL_ARB_multitexture GL_ARB_occlusion_query GL_ARB_occlusion_query2 GL_ARB_pixel_buffer_object
GL_ARB_point_parameters GL_ARB_point_sprite GL_ARB_program_interface_query GL_ARB_provoking_vertex GL_ARB_robust_buffer_access_behavior
GL_ARB_robustness GL_ARB_sample_shading GL_ARB_sampler_objects GL_ARB_seamless_cube_map GL_ARB_seamless_cubemap_per_texture
GL_ARB_separate_shader_objects GL_ARB_shader_atomic_counters GL_ARB_shader_bit_encoding GL_ARB_shader_draw_parameters
GL_ARB_shader_group_vote GL_ARB_shader_image_load_store GL_ARB_shader_image_size GL_ARB_shader_objects GL_ARB_shader_precision
GL_ARB_query_buffer_object GL_ARB_shader_storage_buffer_object GL_ARB_shader_subroutine GL_ARB_shader_texture_lod
GL_ARB_shading_language_100 GL_ARB_shading_language_420pack GL_ARB_shading_language_include GL_ARB_shading_language_packing
GL_ARB_shadow GL_ARB_stencil_texturing GL_ARB_sync GL_ARB_tessellation_shader GL_ARB_texture_border_clamp
GL_ARB_texture_buffer_object GL_ARB_texture_buffer_object_rgb32 GL_ARB_texture_buffer_range GL_ARB_texture_compression
GL_ARB_texture_compression_bptc GL_ARB_texture_compression_rgtc GL_ARB_texture_cube_map GL_ARB_texture_cube_map_array
GL_ARB_texture_env_add GL_ARB_texture_env_combine GL_ARB_texture_env_crossbar GL_ARB_texture_env_dot3 GL_ARB_texture_float
GL_ARB_texture_gather GL_ARB_texture_mirror_clamp_to_edge GL_ARB_texture_mirrored_repeat GL_ARB_texture_multisample
GL_ARB_texture_non_power_of_two GL_ARB_texture_query_levels GL_ARB_texture_query_lod GL_ARB_texture_rectangle GL_ARB_texture_rg
GL_ARB_texture_rgb10_a2ui GL_ARB_texture_stencil8 GL_ARB_texture_storage GL_ARB_texture_storage_multisample GL_ARB_texture_swizzle
GL_ARB_texture_view GL_ARB_timer_query GL_ARB_transform_feedback2 GL_ARB_transform_feedback3 GL_ARB_transform_feedback_instanced
GL_ARB_transpose_matrix GL_ARB_uniform_buffer_object GL_ARB_vertex_array_bgra GL_ARB_vertex_array_object GL_ARB_vertex_attrib_64bit
GL_ARB_vertex_attrib_binding GL_ARB_vertex_buffer_object GL_ARB_vertex_program GL_ARB_vertex_shader
GL_ARB_vertex_type_10f_11f_11f_rev GL_ARB_vertex_type_2_10_10_10_rev GL_ARB_viewport_array GL_ARB_window_pos
GL_ATI_draw_buffers GL_ATI_texture_float GL_ATI_texture_mirror_once GL_S3_s3tc GL_EXT_texture_env_add GL_EXT_abgr GL_EXT_bgra
GL_EXT_bindable_uniform GL_EXT_blend_color GL_EXT_blend_equation_separate GL_EXT_blend_func_separate GL_EXT_blend_minmax
GL_EXT_blend_subtract GL_EXT_compiled_vertex_array GL_EXT_Cg_shader GL_EXT_depth_bounds_test GL_EXT_direct_state_access
GL_EXT_draw_buffers2 GL_EXT_draw_instanced GL_EXT_draw_range_elements GL_EXT_fog_coord GL_EXT_framebuffer_blit
GL_EXT_framebuffer_multisample GL_EXTX_framebuffer_mixed_formats GL_EXT_framebuffer_multisample_blit_scaled
GL_EXT_framebuffer_object GL_EXT_framebuffer_sRGB GL_EXT_geometry_shader4 GL_EXT_gpu_program_parameters
GL_EXT_gpu_shader4 GL_EXT_multi_draw_arrays GL_EXT_packed_depth_stencil GL_EXT_packed_float GL_EXT_packed_pixels
GL_EXT_pixel_buffer_object GL_EXT_point_parameters GL_EXT_provoking_vertex GL_EXT_rescale_normal GL_EXT_secondary_color
GL_EXT_separate_shader_objects GL_EXT_separate_specular_color GL_EXT_shader_image_load_store GL_EXT_shadow_funcs
GL_EXT_stencil_two_side GL_EXT_stencil_wrap GL_EXT_texture3D GL_EXT_texture_array GL_EXT_texture_buffer_object
GL_EXT_texture_compression_dxt1 GL_EXT_texture_compression_latc GL_EXT_texture_compression_rgtc
GL_EXT_texture_compression_s3tc GL_EXT_texture_cube_map GL_EXT_texture_edge_clamp GL_EXT_texture_env_combine
GL_EXT_texture_env_dot3 GL_EXT_texture_filter_anisotropic GL_EXT_texture_integer GL_EXT_texture_lod GL_EXT_texture_lod_bias
GL_EXT_texture_mirror_clamp GL_EXT_texture_object GL_EXT_texture_shared_exponent GL_EXT_texture_sRGB GL_EXT_texture_sRGB_decode
GL_EXT_texture_storage GL_EXT_texture_swizzle GL_EXT_timer_query GL_EXT_transform_feedback2 GL_EXT_vertex_array
GL_EXT_vertex_array_bgra GL_EXT_vertex_attrib_64bit GL_EXT_import_sync_object GL_IBM_rasterpos_clip GL_IBM_texture_mirrored_repeat
GL_KHR_debug GL_KTX_buffer_region GL_NV_bindless_multi_draw_indirect GL_NV_bindless_texture GL_NV_blend_equation_advanced
GL_NV_blend_square GL_NV_compute_program5 GL_NV_conditional_render GL_NV_copy_depth_to_color GL_NV_copy_image
GL_NV_depth_buffer_float GL_NV_depth_clamp GL_NV_draw_texture GL_NV_ES1_1_compatibility GL_NV_explicit_multisample GL_NV_fence
GL_NV_float_buffer GL_NV_fog_distance GL_NV_fragment_program GL_NV_fragment_program_option GL_NV_fragment_program2
GL_NV_framebuffer_multisample_coverage GL_NV_geometry_shader4 GL_NV_gpu_program4 GL_NV_gpu_program4_1 GL_NV_gpu_program5
GL_NV_gpu_program5_mem_extended GL_NV_gpu_program_fp64 GL_NV_gpu_shader5 GL_NV_half_float GL_NV_light_max_exponent
GL_NV_multisample_coverage GL_NV_multisample_filter_hint GL_NV_occlusion_query GL_NV_packed_depth_stencil GL_NV_parameter_buffer_object
GL_NV_parameter_buffer_object2 GL_NV_path_rendering GL_NV_pixel_data_range GL_NV_point_sprite GL_NV_primitive_restart
GL_NV_register_combiners GL_NV_register_combiners2 GL_NV_shader_atomic_counters GL_NV_shader_atomic_float GL_NV_shader_buffer_load
GL_NV_shader_storage_buffer_object GL_ARB_sparse_texture GL_NV_texgen_reflection GL_NV_texture_barrier GL_NV_texture_compression_vtc
GL_NV_texture_env_combine4 GL_NV_texture_expand_normal GL_NV_texture_multisample GL_NV_texture_rectangle GL_NV_texture_shader
GL_NV_texture_shader2 GL_NV_texture_shader3 GL_NV_transform_feedback GL_NV_transform_feedback2 GL_NV_vertex_array_range
GL_NV_vertex_array_range2 GL_NV_vertex_attrib_integer_64bit GL_NV_vertex_buffer_unified_memory GL_NV_vertex_program
GL_NV_vertex_program1_1 GL_NV_vertex_program2 GL_NV_vertex_program2_option GL_NV_vertex_program3 GL_NVX_conditional_render
GL_NVX_gpu_memory_info GL_NVX_nvenc_interop GL_OES_compressed_ETC1_RGB8_texture GL_SGIS_generate_mipmap
GL_SGIS_texture_lod GL_SGIX_depth_texture GL_SGIX_shadow GL_SUN_slice_accum GL_WIN_swap_hint WGL_EXT_swap_control
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: jj2007 on November 16, 2013, 07:00:42 AM
One more...


            Windows Version: 5.1.2600
                Platform ID: 2
Service Pack Version String: Service Pack 3
Service Pack Version Number: 3.0
                 Suite Mask: 00000300
               Product Type: 1
              Reserved Byte: 0

             OpenGL Version: 1.4.0 - Build 4.14.10.4497

          OpenGL Extensions:
GL_ARB_depth_texture
GL_ARB_fragment_program
GL_ARB_multitexture
GL_ARB_point_parameters
GL_ARB_shadow
GL_ARB_texture_border_clamp
GL_ARB_texture_compression
GL_ARB_texture_cube_map
GL_ARB_texture_env_add
GL_ARB_texture_env_combine
GL_ARB_texture_env_dot3
GL_ARB_texture_env_crossbar
GL_ARB_transpose_matrix
GL_ARB_vertex_buffer_object
GL_ARB_vertex_program
GL_ARB_window_pos
GL_EXT_abgr
GL_EXT_bgra
GL_EXT_blend_color
GL_EXT_blend_func_separate
GL_EXT_blend_minmax
GL_EXT_blend_subtract
GL_EXT_clip_volume_hint
GL_EXT_compiled_vertex_array
GL_EXT_cull_vertex
GL_EXT_draw_range_elements
GL_EXT_fog_coord
GL_EXT_multi_draw_arrays
GL_EXT_packed_pixels
GL_EXT_rescale_normal
GL_EXT_secondary_color
GL_EXT_separate_specular_color
GL_EXT_shadow_funcs
GL_EXT_stencil_two_side
GL_EXT_stencil_wrap
GL_EXT_texture_compression_s3tc
GL_EXT_texture_env_add
GL_EXT_texture_env_combine
GL_EXT_texture_filter_anisotropic
GL_EXT_texture3D
GL_3DFX_texture_compression_FXT1
GL_IBM_texture_mirrored_repeat
GL_NV_blend_square
GL_NV_texgen_reflection
GL_SGIS_generate_mipmap
GL_WIN_swap_hint
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: dedndave on November 16, 2013, 07:29:21 AM
Thanks Marinus, Steve, and Jochen   :t

Marinus and Jochen - i take it the program works and closes correctly ?

Steve - great info
although, i'm having a little trouble matching text files to machines

well - 2 of them, i figured out easy enough   :P
OPENGLPM.TXT, Windows 98, P-MMX
OPENGLP3.TXT, Windows 2000, P-III

not sure which is which, here
OPENGLP5.TXT, OpenGL Version: 1.3.5014 WinXP Release
OPENGLCM.TXT, OpenGL Version: 1.3.3413 WinXP Release
Windows XP, IBM Laptop
Windows XP, Sony Laptop

taking a guess... OPENGLCM.TXT goes with the IBM laptop

so, to try a little "process of elimination"....
in this one, i have disabled the init common controls code and removed the manifest from the RC file
i also disabled the multi-media timer and made a single call to render the triangle

that should tell us if it's an OpenGL problem, or something else
of course, it could be more than one issue - lol

by the way....
i opened a console window and hit Alt-Enter to get full-screen
(probably the first time i have done that on this machine - lol)
when i run the SmallOgl5 program from the command line,
the full-screen console minimizes and the GUI app runs (no problems)
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: FORTRANS on November 16, 2013, 08:43:49 AM
Hi,

Quote from: dedndave on November 16, 2013, 07:29:21 AM
Steve - great info
although, i'm having a little trouble matching text files to machines

well - 2 of them, i figured out easy enough   :P
OPENGLPM.TXT, Windows 98, P-MMX
OPENGLP3.TXT, Windows 2000, P-III

   You got it.

Quote
not sure which is which, here
OPENGLP5.TXT, OpenGL Version: 1.3.5014 WinXP Release
OPENGLCM.TXT, OpenGL Version: 1.3.3413 WinXP Release
Windows XP, IBM Laptop
Windows XP, Sony Laptop

taking a guess... OPENGLCM.TXT goes with the IBM laptop

   No, it was for the Mobile Celeron in the Sony Vaio.  P5 is the
Pentium M in the IBM ThinkPad.

Quote
by the way....
i opened a console window and hit Alt-Enter to get full-screen
(probably the first time i have done that on this machine - lol)
when i run the SmallOgl5 program from the command line,
the full-screen console minimizes and the GUI app runs (no problems)

   Yes, you drop (rise?) back to the desktop GUI.  Rather consistent
on all four here.

Regards,

Steve N.
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: FORTRANS on November 16, 2013, 09:55:41 AM
Hi Dave,

   Results from OglSteve1.zip.

Windows 2000, P-III

Window CLI       Blank
Full Screen CLI  Static Triangle
Desktop GUI      Blank

Windows 98, HP Laptop

All three        Triangle flashes for a fraction
                 of a second, then blank.

Windows XP, IBM Laptop

Window CLI       Static Triangle
Full Screen CLI  Blank
Desktop GUI      Static Triangle

Windows XP, Sony Laptop

Window CLI       Static Triangle
Full Screen CLI  Program Exception
Desktop GUI      Static Triangle


   Hope that helps.

Cheers,

Steve N.
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: dedndave on November 16, 2013, 10:33:27 AM
that is a little confusing, Steve   :redface:
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: Siekmanski on November 16, 2013, 06:20:15 PM
Results from OglSteve1.zip.

Microsoft Windows 8.1 [Version 6.3.9600]

Window CLI       Static Triangle   program works and closes correctly    
Full Screen CLI  Static Triangle   program works and closes correctly
Desktop GUI      Static Triangle   program works and closes correctly
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: Gunther on November 16, 2013, 09:01:03 PM
Hi Dave,

SmallOgl.exe works on both (Windows XP (VM) and Windows 7 64 bit), but nothing rotates. The triangle is static.

Gunther
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: jj2007 on November 16, 2013, 09:54:48 PM
Quote from: Gunther on November 16, 2013, 09:01:03 PMSmallOgl.exe works on both (Windows XP (VM) and Windows 7 64 bit), but nothing rotates. The triangle is static.

Slowly rotating triangle on my XP SP3... in contrast to the one I posted in reply #89, which rotates very fast on XP and slowly on W7-32. OpenGL seems to be a mess...
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: Gunther on November 16, 2013, 10:11:04 PM
Jochen,

Quote from: jj2007 on November 16, 2013, 09:54:48 PM
Slowly rotating triangle on my XP SP3... in contrast to the one I posted in reply #89, which rotates very fast on XP and slowly on W7-32. OpenGL seems to be a mess...

That's probably depending on the implementation in different operating systems. I've no other explanation.

Gunther
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: dedndave on November 16, 2013, 10:37:19 PM
Jochen, Gunther, thanks again for testing
but, the one i am hoping works correctly on newer operating systems is SmallOgl5 in Reply #108
the triangle should rotate at 1 degree per mS, and the close button should work correctly

now, Steve (FORTRANS) has some older machines
one of them is even a win 98 machine, one is a win 2000 machine, and 2 older XP laptops
i am trying some different things to see why things are different, there
i am a little surprised that we have had any success at all on the win 98 machine - lol

at any rate, some of these are intended just for Steve, really, as we try to sort out the differences
the current "i hope this works" version is SmallOgl5 in Reply #108, here...
http://masm32.com/board/index.php?topic=2582.msg27362#msg27362 (http://masm32.com/board/index.php?topic=2582.msg27362#msg27362)
it seems to have passed most of the tests, except Gunther's win7-64 test
and, of course, Steve's older machine tests
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: Gunther on November 16, 2013, 10:49:34 PM
Dave,

Quote from: dedndave on November 16, 2013, 10:37:19 PM
but, the one i am hoping works correctly on newer operating systems is SmallOgl5 in Reply #108
the triangle should rotate at 1 degree per mS, and the close button should work correctly

it works fine under XP but leaves an empty screen under Win 7. It's tricky.

Gunther
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: dedndave on November 16, 2013, 10:53:49 PM
ok Gunther - thanks again for testing   :t
i was hoping that one would work correctly for you   :(

it seems to work on other win7-64 machines
perhaps the issue is InitCommonControlsEx, manifest, and a non-English win7-64
i seem to recall Hutch experienced similar results on one of his tests
i'll have a look at his stuff to see what i can learn from it
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: Gunther on November 16, 2013, 10:58:48 PM
Dave,

Quote from: dedndave on November 16, 2013, 10:53:49 PM
it seems to work on other win7-64 machines
perhaps the issue is InitCommonControlsEx, manifest, and a non-English win7-64

That would make sense.

Gunther
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: dedndave on November 16, 2013, 11:07:28 PM
another possibility....

http://devgurus.amd.com/thread/143385 (http://devgurus.amd.com/thread/143385)

maybe the problem will go away by making 2 calls to ChoosePixelFormat   :P
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: dedndave on November 16, 2013, 11:16:29 PM
what CPU does your win7-64 machine have, Gunther ?
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: GoneFishing on November 16, 2013, 11:54:47 PM
Quote from: dedndave on November 16, 2013, 11:16:29 PM
what CPU does your win7-64 machine have, Gunther ?
I'm afraid Gunther has i7 Ivy Bridge CPU with on-chip graphics
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: Gunther on November 17, 2013, 12:06:39 AM
Hi Dave and vertograd,

I've an i7 (Ivy Bridge) with on-chip graphics adaptor, but that's inactive. My card is an AMD Radeon 7570. But I think this isn't important, because the XP emulation under VirtualPC uses the same card, and that works fine.

Gunther
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: FORTRANS on November 17, 2013, 12:28:14 AM
Quote from: dedndave on November 16, 2013, 10:33:27 AM
that is a little confusing, Steve   :redface:

Hi,

   Completely.  I can't see why starting from a full screen would
matter at all, ever.  And, up till now, I thought the two XP laptops
behaved the same, except for AV, keyboard, and speed.  And
the AV on the Sony is usually turned off (speed, lack of), which
makes that moot .

   I guess that the video chip needs some reprogramming to leave
a full screen session.  But really, how would a program know about
that?

Regards,

Steve N.
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: Gunther on November 17, 2013, 01:12:46 AM
Hi Steve,

Quote from: FORTRANS on November 17, 2013, 12:28:14 AM
   I guess that the video chip needs some reprogramming to leave
a full screen session.  But really, how would a program know about
that?

right. It seems impossible for the program.

Gunther
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: dedndave on November 17, 2013, 03:38:53 AM
it may make a difference if you create a shortcut to the exe and run the shortcut
may be something in the startup settings
and, with a shortcut, you can alter some settings in the properties tab

at any rate, if we can make it run from an "explorer icon click", i am happy   :P
it's a GUI app - and the console window is known to be buggish in other ways
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: TWell on November 17, 2013, 04:57:05 AM
This function works in WinXP, but not in Win7-x64.model flat,stdcall
WIN32_LEAN_AND_MEAN equ <>
INCLUDE    Windows.inc
INCLUDE    GL\GL.inc
INCLUDELIB OpenGL32.lib

.DATA
ALIGN   4
r4Rotation      REAL4 0.0,0.0,0.0,1.0
r4Vertices      REAL4 0.0,1.0,1.0,0.87,-0.5,1.0,-0.87,-0.5,1.0
r4Colours       REAL4 1.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0

.CODE
ALIGN   16

RenderTriangleASM PROC hWnd:HWND, dwAngle:DWORD
    INVOKE  glClear,GL_COLOR_BUFFER_BIT
    INVOKE  glPushMatrix
    mov     edx,offset r4Rotation
    fild    dwAngle
    fst real4 ptr [edx]
    INVOKE  glRotatef,[edx],[edx+4],[edx+8],[edx+12]
    INVOKE  glBegin,GL_TRIANGLES
        INVOKE  glColor3fv, offset r4Colours
        INVOKE  glVertex3fv,offset r4Vertices
        INVOKE  glColor3fv, offset r4Colours[12]
        INVOKE  glVertex3fv,offset r4Vertices[12]
        INVOKE  glColor3fv, offset r4Colours[24]
        INVOKE  glVertex3fv,offset r4Vertices[24]
    INVOKE  glEnd
    INVOKE  glFlush
    INVOKE  glPopMatrix
    INVOKE  GetDC,hWnd
    mov     edx, eax
    INVOKE  SwapBuffers,edx
    INVOKE  ReleaseDC,hWnd,edx
    ret
RenderTriangleASM ENDP
but this similar C function works in Win7-x64
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <gl/gl.h>

void __stdcall RenderTriangleC(HWND hwnd, int nAngle)
{
static GLfloat r4Vertices[] = {0.0,1.0,1.0,0.87,-0.5,1.0,-0.87,-0.5,1.0};
static GLfloat r4Colours[] = {1.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0};
static GLdouble r4Rotation[] = {0.0,0.0,0.0,1.0};

glClear(GL_COLOR_BUFFER_BIT);
glPushMatrix();
r4Rotation[0] = nAngle;
glRotatef(r4Rotation[0], r4Rotation[1], r4Rotation[2], r4Rotation[3]);
glBegin(GL_TRIANGLES);
glColor3fv(r4Colours);
glVertex3fv(r4Vertices);
glColor3fv(&r4Colours[3]);
glVertex3fv(&r4Vertices[3]);
glColor3fv(&r4Colours[6]);
glVertex3fv(&r4Vertices[6]);
glEnd();
glFlush();
glPopMatrix();
HDC hdc = GetDC(hwnd);
SwapBuffers(hdc);
ReleaseDC(hwnd, hdc);
}
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: dedndave on November 17, 2013, 05:36:25 AM
it seems to me that those should create the same code - lol
so - maybe it's the testbed that is different ?

are you building those as OBJ modules, then linking to the same program ?
i.e., how are we to determine what changes between one that works and one that doesn't ?

EDIT: ok - i see a potential issue:
    INVOKE  GetDC,hWnd
    mov     edx, eax
    INVOKE  SwapBuffers,edx
    INVOKE  ReleaseDC,hWnd,edx

the contents of EDX are destroyed across the SwapBuffers call
try this...
    INVOKE  GetDC,hWnd
    push    eax
    INVOKE  SwapBuffers,eax
    pop     eax
    INVOKE  ReleaseDC,hWnd,eax

it seems like that problem would it cause to:
work, for a little while, then hose up the system - lol
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: dedndave on November 17, 2013, 05:49:02 AM
this one is aimed at resolving the win7-64 issue
give it a try, guys   :P
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: jj2007 on November 17, 2013, 05:57:55 AM
Win XP: Rapidly rotating triangle.
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: Gunther on November 17, 2013, 06:11:01 AM
Dave,

Quote from: dedndave on November 17, 2013, 05:49:02 AM
this one is aimed at resolving the win7-64 issue
give it a try, guys   :P

not solved. Black screen under Win 7, fast rotating triangle under XP.

Gunther
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: TWell on November 17, 2013, 06:26:37 AM
Here is POAsm project for Gunther.
C version function used.
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: Gunther on November 17, 2013, 06:34:42 AM
TWell,

slow rotation under XP and Windows 7 (same machine).  :t

Gunther
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: jj2007 on November 17, 2013, 06:42:33 AM
TWell,
slow rotation under XP
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: dedndave on November 17, 2013, 06:56:36 AM
very interesting TWell   :t

let's see what i can learn from it   :biggrin:
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: dedndave on November 17, 2013, 07:16:43 AM
question - does Franck's (hitchhikr) example work under win7-64 ?

\Masm32\Examples\exampl04\opengl
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: Gunther on November 17, 2013, 07:41:30 AM
Dave,

Quote from: dedndave on November 17, 2013, 07:16:43 AM
question - does Franck's (hitchhikr) example work under win7-64 ?

\Masm32\Examples\exampl04\opengl

excellent idea.  :t Works on both (XP - fast, Win 7 - very fast).

Gunther
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: dedndave on November 17, 2013, 12:03:21 PM
thanks Gunther - we'll try again tomorrow   :P
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: Gunther on November 17, 2013, 12:05:03 PM
Dave,

okay. Always step by step.

Gunther
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: jj2007 on November 17, 2013, 06:28:35 PM
Quote from: dedndave on November 17, 2013, 07:16:43 AM
question - does Franck's (hitchhikr) example work under win7-64 ?

\Masm32\Examples\exampl04\opengl

Works fine under my XP, but again, much too fast. Once you add ...

NoMsg:         ; No pending messages: draw the scene
         invoke Sleep, 1
         invoke   DrawScene

... it's a really beautiful demo. Strange that Franck's demo uses the same unorthodox message handling as the OP's code ::)

I wonder why it's by default slow in Win-7. Either they added a Sleep(1) in later OpenGL, or the OS handles the message loop differently.

I attach a minimalistic (plain Masm32) example showing how fast non-messages are handled:
  .While 1
invoke PeekMessage, ADDR msg, 0, 0, 0, PM_NOREMOVE
.if eax
invoke GetMessage, ADDR msg, NULL, 0, 0
.Break .if !eax
invoke TranslateMessage, ADDR msg
invoke DispatchMessage, ADDR msg
.else
inc ct
test ct, 65536*16-1
.if Zero?
movzx eax, word ptr ct+2
print str$(eax), " " ; XP: ca. 1s/line
.endif
.endif
  .Endw

Under my XP, about one line per second fills the screen. If the OS hypothesis holds, it should be very, very slow on Win-7.

P.S.: Just tested on Win7-64 - it's as fast as on XP, so the OS has not changed behaviour. Unless Win7-32 is different, of course.
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: Gunther on November 17, 2013, 08:49:41 PM
Jochen,

under Windows 7 it fills the screen. Windows XP nothing happens.

Gunther
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: jj2007 on November 17, 2013, 08:57:46 PM
Quote from: Gunther on November 17, 2013, 08:49:41 PMWindows XP nothing happens.

Gunther,

Now that is really strange. This is just a naked GUI, plain Masm32, no MasmBasic whatsoever... and it just prints a number (occasionally) when PeekMessage returns zero.

What happens if you increase the granularity, e.g. test ct, 256-1?
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: Gunther on November 17, 2013, 09:35:21 PM
Jochen,

could you please post the command line options for assembling with ml.exe (version 6.14.8444 installed) and linking with link.exe (5.12.8078 installed).

Gunther
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: jj2007 on November 17, 2013, 10:01:59 PM
Gunther,
Just open the asm file in qEditor and use Console build all.
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: dedndave on November 17, 2013, 10:08:46 PM
i would venture a guess that it's OpenGL
after version 1.x, it underwent a lot of changes
by the time they get to windows 7, they are at version 4.x
that means a lot + a lot + a lot of changes - lol

personally, i can't see writing code that will not run under XP
there are still way too many XP users out there
so - you can take the multiple version approach - or use OpenGL 1.2 code   :P
it may be that some things that work under 1.2 do not work under 4.x
that's what i am trying to figure out

it's also possible that running code that was intended for 1.x runs slow under 4.x
because updated code would not use the same approach
i.e., if i wrote the code with version 3/4 style techniques, it may run faster

one of the nicer tutorials i saw mentioned OpenGL version 3.3 or better
something really big must have happened at that level

i think, if i want to use OpenGL and get good performance, i have to use at least a 2-version approach
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: Gunther on November 17, 2013, 10:45:44 PM
Jochen,

Quote from: jj2007 on November 17, 2013, 10:01:59 PM
Just open the asm file in qEditor and use Console build all.

that doesn't work.


Microsoft (R) Macro Assembler Version 6.14.8444
Copyright (C) Microsoft Corp 1981-1997.  All rights reserved.

Assembling: C:\masm32\Work\MsgLoopTest.asm

***********
ASCII build
***********

Microsoft (R) Incremental Linker Version 5.12.8078
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.

LINK : fatal error LNK1181: cannot open input file "C:\masm32\Work\MsgLoopTest.o
bj"
_
Link error


Please post the command lines.

Gunther
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: GoneFishing on November 17, 2013, 10:47:18 PM
This thread is already #5 in Top 10 Topics (by Replies)  (http://masm32.com/board/index.php?action=stats)
#3 and #4 both have 161 replies
So the bronze medal is guarantied in next few hours  ;)
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: Gunther on November 17, 2013, 10:53:50 PM
Hi vertograd,

that's true, but not the question. I would like to assemble and link Jochens version successfully and that doesn't work. So, any help is welcome.

Gunther
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: GoneFishing on November 17, 2013, 10:54:17 PM
Quote from: Gunther on November 17, 2013, 10:45:44 PM
...
Please post the command lines.

Hi Gunther,
QEDITOR likes to have the asm file being assembled on the same drive ( even better in one of MASM32 subdirectories)

EDIT: Hmm, sorry, I'd have read your post better . It's on the same drive and in MASM32 subfolder ...
:redface:       
Just tried to compile it with Console Build All here  -  all worked well
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: dedndave on November 17, 2013, 11:02:24 PM
try this Gunther
ml /c /coff MsgLoopTest.asm
link /SUBSYSTEM:WINDOWS /OPT:NOREF MsgLoopTest.obj


if it can't open the OBJ - there is a good reason
maybe it didn't get assembled

EDIT: oops - should be /SUBSYSTEM:CONSOLE
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: jj2007 on November 17, 2013, 11:09:41 PM
Quote from: Gunther on November 17, 2013, 10:45:44 PM

that doesn't work.

Please post the command lines.

Very strange....

@echo off
\Masm32\bin\ml.exe /c /coff MsgLoopTest.asm
\Masm32\bin\link.exe /SubSystem:Console MsgLoopTest.obj
dir MsgLoopTest.*
MsgLoopTest.exe
pause


P.S.: Just saw that Dave posted an (almost) identical set of commandlines. This must work without any environment variables set but, as vertograd rightly wrote, \Masm32\bin must be on the same drive as the asm file.
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: Gunther on November 17, 2013, 11:16:23 PM
Dave and Jochen,

thank you for the command line. Assembling and linking was successful. I've changed:


test        ct, 256-1


in line 41 of Jochen's code and it fills the screen with numbers very fast under both environments. Should I post the changed code?

Gunther
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: jj2007 on November 17, 2013, 11:19:48 PM
Quote from: Gunther on November 17, 2013, 11:16:23 PMShould I post the changed code?

Thanks, no need for that. So for test ct, 65536*16-1 you see nothing, for test ct, 256-1 the screen feels rapidly? That would mean your message loop is a lot slower than ours ::)

Attached a version that allows modifying the speed via the menu.
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: dedndave on November 17, 2013, 11:26:48 PM
i can see a few immediate possibilities..
1) the multi-media timer isn't working as expected on Gunther's machine
2) the OpenGL init must be performed when the window is visible
3) OpenGL ver 1.x code isn't happy on a 4.4 machine

in this one, i moved the init code to the main proc
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: jj2007 on November 17, 2013, 11:28:38 PM
Quote from: dedndave on November 17, 2013, 11:26:48 PM
in this one, i moved the init code to the main proc

Rapidly rotating triangle - but I'd like to clarify that message loop thing, see attachment to my post above.
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: dedndave on November 17, 2013, 11:29:46 PM
that one works as expected on my machine, Jochen
about one line of numbers per second (same as the previous one)
is that what you wanted ?
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: jj2007 on November 17, 2013, 11:32:28 PM
Quote from: dedndave on November 17, 2013, 11:29:46 PM
that one works as expected on my machine, Jochen

I believe you, Dave. I'd like to see what Gunther's machine does when choosing the menu options :icon_mrgreen:
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: dedndave on November 17, 2013, 11:34:13 PM
didn't even notice the menu - rofl
they work here - let's see what happens on Gunther's

i need more coffee   :(
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: dedndave on November 18, 2013, 12:17:04 AM
hopefully, TWell will show up today
it would be nice if he would attach an EXE made with the C-version render module
i am having trouble building it, here
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: TWell on November 18, 2013, 12:38:38 AM
In Reply #144 (http://masm32.com/board/index.php?PHPSESSID=c5a712b310220a2ea9b484420493b149&topic=2582.msg27422#msg27422) look output folder for obj
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: dedndave on November 18, 2013, 12:42:43 AM
now, i am a little lost.....

on TWell's code...
he posted a ZIP file named SmallOgl_ASM_C, supposedly using the C render module
and - that seems to work on Gunther's machine
and he says that the C version works, but the ASM version does not on his own machine
however, when i disassemble the EXE, it is clearly using the render code that i wrote in ASM
it would be great if he would attach both EXE's for a side-by-side comparison
i am having trouble building the C version, as i am not set up the same with Pelle's

it may also be helpful if both Gunther and TWell would post results from the version test i posted here

http://masm32.com/board/index.php?topic=2582.msg27374#msg27374 (http://masm32.com/board/index.php?topic=2582.msg27374#msg27374)

it generates a text file with version info   :t
please post or attach the text - thanks
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: TWell on November 18, 2013, 12:52:54 AM
Quote from: dedndave on November 18, 2013, 12:42:43 AM
now, i am a little lost.....

on TWell's code...
he posted a ZIP file named SmallOgl_ASM_C, supposedly using the C render module
and - that seems to work on Gunther's machine
and he says that the C version works, but the ASM version does not on his own machine
however, when i disassemble the EXE, it is clearly using the render code that i wrote in ASM
it would be great if he would attach both EXE's for a side-by-side comparison
i am having trouble building the C version, as i am not set up the same with Pelle's
But it is using that C version to rendering.
Quote from: dedndave on November 18, 2013, 12:42:43 AM
it may also be helpful if both Gunther and TWell would post results from the version test i posted here

http://masm32.com/board/index.php?topic=2582.msg27374#msg27374 (http://masm32.com/board/index.php?topic=2582.msg27374#msg27374)

it generates a text file with version info   :t
please post or attach the text - thanks

            Windows Version: 6.1.7601
                Platform ID: 2
Service Pack Version String: Service Pack 1
Service Pack Version Number: 1.0
                 Suite Mask: 00000300
               Product Type: 1
              Reserved Byte: 0

             OpenGL Version: 3.3.9836 Compatibility Profile Context

          OpenGL Extensions:
GL_AMDX_debug_output GL_AMD_conservative_depth GL_AMD_draw_buffers_blend GL_AMD_name_gen_delete GL_AMD_performance_monitor GL_AMD_shader_stencil_export GL_ARB_blend_func_extended GL_ARB_color_buffer_float GL_ARB_copy_buffer GL_ARB_depth_buffer_float GL_ARB_depth_clamp GL_ARB_depth_texture GL_ARB_draw_buffers GL_ARB_draw_buffers_blend GL_ARB_draw_elements_base_vertex GL_ARB_draw_instanced GL_ARB_explicit_attrib_location GL_ARB_fragment_coord_conventions GL_ARB_fragment_program GL_ARB_fragment_program_shadow GL_ARB_fragment_shader GL_ARB_framebuffer_object GL_ARB_framebuffer_sRGB GL_ARB_geometry_shader4 GL_ARB_half_float_pixel GL_ARB_half_float_vertex GL_ARB_imaging GL_ARB_instanced_arrays GL_ARB_map_buffer_range GL_ARB_multisample GL_ARB_multitexture GL_ARB_occlusion_query GL_ARB_occlusion_query2 GL_ARB_pixel_buffer_object GL_ARB_point_parameters GL_ARB_point_sprite GL_ARB_provoking_vertex GL_ARB_sampler_objects GL_ARB_seamless_cube_map GL_ARB_shader_bit_encoding GL_ARB_shader_objects GL_ARB_shader_texture_lod GL_ARB_shading_language_100 GL_ARB_shadow GL_ARB_shadow_ambient GL_ARB_sync GL_ARB_texture_border_clamp GL_ARB_texture_buffer_object GL_ARB_texture_compression GL_ARB_texture_compression_rgtc GL_ARB_texture_cube_map GL_ARB_texture_env_add GL_ARB_texture_env_combine GL_ARB_texture_env_crossbar GL_ARB_texture_env_dot3 GL_ARB_texture_float GL_ARB_texture_mirrored_repeat GL_ARB_texture_multisample GL_ARB_texture_non_power_of_two GL_ARB_texture_rectangle GL_ARB_texture_rg GL_ARB_texture_rgb10_a2ui GL_ARB_texture_snorm GL_ARB_timer_query GL_ARB_transform_feedback2 GL_ARB_transform_feedback3 GL_ARB_transpose_matrix GL_ARB_uniform_buffer_object GL_ARB_vertex_array_bgra GL_ARB_vertex_array_object GL_ARB_vertex_buffer_object GL_ARB_vertex_program GL_ARB_vertex_shader GL_ARB_vertex_type_2_10_10_10_rev GL_ARB_window_pos GL_ATI_draw_buffers GL_ATI_envmap_bumpmap GL_ATI_fragment_shader GL_ATI_meminfo GL_ATI_separate_stencil GL_ATI_texture_compression_3dc GL_ATI_texture_env_combine3 GL_ATI_texture_float GL_ATI_texture_mirror_once GL_EXT_abgr GL_EXT_bgra GL_EXT_bindable_uniform GL_EXT_blend_color GL_EXT_blend_equation_separate GL_EXT_blend_func_separate GL_EXT_blend_minmax GL_EXT_blend_subtract GL_EXT_compiled_vertex_array GL_EXT_copy_buffer GL_EXT_copy_texture GL_EXT_draw_buffers2 GL_EXT_draw_instanced GL_EXT_draw_range_elements GL_EXT_fog_coord GL_EXT_framebuffer_blit GL_EXT_framebuffer_multisample GL_EXT_framebuffer_object GL_EXT_framebuffer_sRGB GL_EXT_geometry_shader4 GL_EXT_gpu_program_parameters GL_EXT_gpu_shader4 GL_EXT_histogram GL_EXT_multi_draw_arrays GL_EXT_packed_depth_stencil GL_EXT_packed_float GL_EXT_packed_pixels GL_EXT_pixel_buffer_object GL_EXT_point_parameters GL_EXT_provoking_vertex GL_EXT_rescale_normal GL_EXT_secondary_color GL_EXT_separate_specular_color GL_EXT_shadow_funcs GL_EXT_stencil_wrap GL_EXT_subtexture GL_EXT_texgen_reflection GL_EXT_texture3D GL_EXT_texture_array GL_EXT_texture_buffer_object GL_EXT_texture_buffer_object_rgb32 GL_EXT_texture_compression_latc GL_EXT_texture_compression_rgtc GL_EXT_texture_compression_s3tc GL_EXT_texture_cube_map GL_EXT_texture_edge_clamp GL_EXT_texture_env_add GL_EXT_texture_env_combine GL_EXT_texture_env_dot3 GL_EXT_texture_filter_anisotropic GL_EXT_texture_integer GL_EXT_texture_lod GL_EXT_texture_lod_bias GL_EXT_texture_mirror_clamp GL_EXT_texture_object GL_EXT_texture_rectangle GL_EXT_texture_sRGB GL_EXT_texture_shared_exponent GL_EXT_texture_snorm GL_EXT_texture_swizzle GL_EXT_timer_query GL_EXT_transform_feedback GL_EXT_vertex_array GL_EXT_vertex_array_bgra GL_IBM_texture_mirrored_repeat GL_KTX_buffer_region GL_NV_blend_square GL_NV_conditional_render GL_NV_copy_depth_to_color GL_NV_explicit_multisample GL_NV_float_buffer GL_NV_half_float GL_NV_primitive_restart GL_NV_texgen_reflection GL_SGIS_generate_mipmap GL_SGIS_texture_edge_clamp GL_SGIS_texture_lod GL_SUN_multi_draw_arrays GL_WIN_swap_hint WGL_EXT_swap_control
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: dedndave on November 18, 2013, 01:46:28 AM
many thanks, TWell   :t

i see, now - the EXE actually contains both modules
and - i spotted an error in my code
i used FST, when i should use FSTP (i thought the POP was implied)

but, this is interesting
here is the C version code for that part of the render routine
:004012E7 DB450C                  fild dword[ebp+0C]
:004012EA DD1D88214000            fstp 64real[00402188]
:004012F0 DD05A0214000            fld 64real[004021A0]
:004012F6 83EC04                  sub esp, 004
:004012F9 D91C24                  fstp 32real[esp+esp]
:004012FC D90424                  fld 32real[esp+esp]
:004012FF 83C404                  add esp, 004
:00401302 83EC04                  sub esp, 004
:00401305 D91C24                  fstp 32real[esp+esp]
:00401308 DD0598214000            fld 64real[00402198]
:0040130E 83EC04                  sub esp, 004
:00401311 D91C24                  fstp 32real[esp+esp]
:00401314 D90424                  fld 32real[esp+esp]
:00401317 83C404                  add esp, 004
:0040131A 83EC04                  sub esp, 004
:0040131D D91C24                  fstp 32real[esp+esp]
:00401320 DD0590214000            fld 64real[00402190]
:00401326 83EC04                  sub esp, 004
:00401329 D91C24                  fstp 32real[esp+esp]
:0040132C D90424                  fld 32real[esp+esp]
:0040132F 83C404                  add esp, 004
:00401332 83EC04                  sub esp, 004
:00401335 D91C24                  fstp 32real[esp+esp]
:00401338 DD0588214000            fld 64real[00402188]
:0040133E 83EC04                  sub esp, 004
:00401341 D91C24                  fstp 32real[esp+esp]
:00401344 D90424                  fld 32real[esp+esp]
:00401347 83C404                  add esp, 004
:0040134A 83EC04                  sub esp, 004
:0040134D D91C24                  fstp 32real[esp+esp]


:biggrin:

it would seem it converts doubles to singles each time render is called
the only one that changes is the first value in the array
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: dedndave on November 18, 2013, 01:53:11 AM
let's see....
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: TWell on November 18, 2013, 01:57:04 AM
how it's spinning...
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: dedndave on November 18, 2013, 02:04:43 AM
great !   :biggrin:
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: FORTRANS on November 18, 2013, 02:50:06 AM
Hi Dave,

   Just for jollies I will mention that yesterday I went to my Mother's
house and ran some of your older SmallOgl program and foo.exe.
The GUI and windowed CLI went as expected.  But when run from
a full screen session, they all ran in the background as processes.
Her machine had been infected (a while back), and then cleaned.
When infected, the command prompts were more or less disabled.
Meaningless data point I suppose.

   Back to today.  Results from SmallOgl_ASM_C.zip in Reply #144.
Results from SmallOgl6Fstp.zip in Reply #176.

                 SmallOgl_ASM_C              SmallOgl6Fstp
Windows 2000, P-III

Window CLI       Slow Triangle               Fast Triangle
Full Screen CLI  Blank                       Fast Triangle
Desktop GUI      Slow Triangle               Fast Triangle

Windows 98, HP Laptop

Window CLI       Locks up, reset to reboot.  Fast Triangle
Full Screen CLI  Locks up, reset to reboot.  Fast Triangle
Desktop GUI      Error message, locks up,    Fast Triangle
                 reset to reboot.

Windows XP, IBM Laptop

Window CLI       Slow Triangle               Fast Triangle
Full Screen CLI  Blank                       Blank
Desktop GUI      Slow Triangle               Fast Triangle

Windows XP, Sony Laptop

Window CLI       Slow Triangle               Fast Triangle
Full Screen CLI  Program Exception           Program exception
Desktop GUI      Slow Triangle               Fast Triangle


   I hope you find this interesting, and perhaps useful.  At least
it is a bit different.

Cheers,

Steve N.
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: jj2007 on November 18, 2013, 03:13:08 AM
Quote from: dedndave on November 18, 2013, 01:46:28 AM
fstp 32real[esp+esp]
:dazzled:
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: Gunther on November 18, 2013, 03:24:46 AM
Jochen,

your menu version (slow, medium, fast) runs fine under both environments. But that's not a real surprise. The test environment wasn't a native installed XP; it's only an emulation with VirtualPC and XP mode as guest and Windows 7 as host.

Gunther 
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: dedndave on November 18, 2013, 03:37:03 AM
thanks Steve - guys

it looks like we've cleared up most of the issues, at least
i am not sure we'll ever get the full-screen CLI mode to work right
although FINIT might fix it - not sure
could make it worse, if the full-screen console uses the FPU

:004012F9 D91C24                  fstp 32real[esp+esp]
that appears to be incorrect disassembly by my disasm program
dumpbin yields...
  0040131D: D9 1C 24           fstp        dword ptr [esp]
Title: Re: Can't get a rendering context, wglCreateContext fails
Post by: TWell on November 18, 2013, 03:44:38 AM
Quote from: dedndave on November 18, 2013, 01:46:28 AM
it would seem it converts doubles to singles each time render is called
the only one that changes is the first value in the array
My fault, i use GLdouble instead GLfloat in r4Rotation[].