News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Can't get a rendering context, wglCreateContext fails

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

Previous topic - Next topic

dedndave

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



hamper

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


dedndave

if that doesn't work on your machine, let me know - tell me what OS you are using
there are a few possibilities

GoneFishing

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

Gunther

Dave,

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

Gunther
You have to know the facts before you can distort them.

dedndave

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)

hamper

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.

GoneFishing


dedndave

ok - i switched to the GDI calls
and, added gdi32.lib to the preamble

see if that makes a difference

GoneFishing


dedndave

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

hamper

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.



dedndave

speaking of tea.....

you have to have patience - or develop some - lol
if not, asm is not your cup of tea   :t

Gunther

Dave,

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

Gunther
You have to know the facts before you can distort them.

jj2007

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.