opengl sample errors assembling cube.asm, when I try to assemble an opengl samp.

Started by Cr8zyNbunny, March 14, 2012, 04:02:55 AM

Previous topic - Next topic

Cr8zyNbunny

 :boohoo:C:\masm32\examples\exampl04\OpenGLExample.asm(82) : error A2008: syntax error :
HGLRC
C:\masm32\examples\exampl04\OpenGLExample.asm(314) : error A2006: undefined symb
ol : hRC
C:\masm32\examples\exampl04\OpenGLExample.asm(314) : error A2114: INVOKE argumen
t type mismatch : argument : 2
C:\masm32\examples\exampl04\OpenGLExample.asm(331) : error A2006: undefined symb
ol : hRC
C:\masm32\examples\exampl04\OpenGLExample.asm(331) : error A2114: INVOKE argumen
t type mismatch : argument : 1
C:\masm32\examples\exampl04\OpenGLExample.asm(313) : error A2006: undefined symb
ol : hRC
Assembly Error
Press any key to continue . . .

the source code is attched there on the bottom so you can assemble it.. I think I have all the default masm32 inc and lib files. maybe it is in the source code.I suck at x86, because I need more time for my family and church.



.486P
.Model Flat,StdCall  ; 32 bit memory model
Option Scoped        ; local labels are enabled, global labels inside
                              ; PROC should be defined with double colons (LABEL::)
Option CaseMap:None  ; case sensitive

Include C:\masm32\include\windows.inc
Include C:\masm32\include\user32.inc
Include C:\masm32\include\kernel32.inc
Include C:\masm32\include\gdi32.inc

Include C:\masm32\include\glu32.inc
Include C:\masm32\include\opengl32.inc

IncludeLib C:\masm32\lib\user32.lib
IncludeLib C:\masm32\lib\kernel32.lib
IncludeLib C:\masm32\lib\opengl32.lib
IncludeLib C:\masm32\lib\glu32.lib
IncludeLib C:\masm32\lib\gdi32.lib

glRed Macro
invoke glColor3f, val1_0d, val0_0d, val0_0d;
EndM

glGreen Macro
invoke glColor3f, val0_0d, val1_0d, val0_0d;
EndM

glBlue Macro
invoke glColor3f, val0_0d, val0_0d, val1_0d;
EndM

glWhite Macro
invoke glColor3f, val1_0d, val1_0d, val1_0d;
EndM

glBlack Macro
invoke glColor3f, val0_0d, val0_0d, val0_0d;
EndM

glGrey Macro
invoke glColor3f, val0_5d, val0_5d, val0_5d;
EndM

; PROTOS ================================================
WinMain Proto :DWORD,:DWORD,:DWORD,:DWORD
WndProc Proto :DWORD,:DWORD,:DWORD,:DWORD
EnableOpenGL Proto :DWORD
DisableOpenGL Proto :DWORD
ResizeGLScene Proto :DWORD,:DWORD

; Read-only data ========================================
.Const

ClassName BYTE "OGLMainWinClass", 0
AppName BYTE "Asm + OpenGL Application", 0

val45_0q QWORD 45.0
val1_0q QWORD 1.0
val0_1q QWORD 0.1
val100_0q QWORD 100.0
val0_0d DWORD 0.0
val0_5d DWORD 0.5
val_8_0d DWORD -8.0
val1_0d DWORD 1.0
val_1_0d DWORD -1.0

; Initialized data ======================================
.Data
widthwnd DWORD 640
heightwnd DWORD 480
angle REAL4 0.0
delta_angle REAL4 0.1
vangle REAL4 30.0


; Non-initialized data ==================================
.data?
     
hInstance HINSTANCE ?
hDC HDC ?
hRC HGLRC ?

.Code
Start:

invoke GetModuleHandle, NULL
mov hInstance, eax
invoke WinMain, hInstance, NULL, NULL, SW_SHOWDEFAULT

push 0h
call ExitProcess

;========================================================
WinMain Proc hInst:HINSTANCE, hPrevInst:HINSTANCE, CmdLine:LPSTR, CmdShow:DWORD

LOCAL wc:WNDCLASSEX
LOCAL msg:MSG
LOCAL hwnd:HWND
LOCAL bQuit:BOOL

mov bQuit, FALSE

mov wc.cbSize, sizeof WNDCLASSEX
mov wc.style, CS_OWNDC
mov wc.lpfnWndProc, offset WndProc
mov wc.cbClsExtra, NULL
mov wc.cbWndExtra, NULL
push hInstance
pop wc.hInstance

invoke GetStockObject, BLACK_BRUSH
mov wc.hbrBackground, eax

mov wc.lpszMenuName, NULL
mov wc.lpszClassName, offset ClassName

invoke LoadIcon, NULL, IDI_WINLOGO
mov wc.hIcon, eax
mov wc.hIconSm, eax

invoke LoadCursor,NULL,IDC_ARROW
mov wc.hCursor,eax

invoke RegisterClassEx, addr wc
invoke CreateWindowEx,NULL, addr ClassName, addr AppName,\
                       WS_OVERLAPPEDWINDOW,\
                       CW_USEDEFAULT, CW_USEDEFAULT,\
                       widthwnd, heightwnd, NULL, NULL,\
                       hInst, NULL
mov hwnd,eax

invoke ShowWindow, eax, SW_SHOWNORMAL
invoke UpdateWindow, hwnd
invoke EnableOpenGL, hwnd

.while !( bQuit )

   invoke PeekMessage, addr msg, NULL, 0, 0, PM_REMOVE
   .if ( eax )

     .if ( msg.message == WM_QUIT )

       mov bQuit, TRUE

     .else

       invoke TranslateMessage, addr msg
       invoke DispatchMessage, addr msg
     
     .endif
   
    .else
   
invoke glClear, GL_COLOR_BUFFER_BIT OR GL_DEPTH_BUFFER_BIT;Clear buffers
invoke glLoadIdentity   ;//Reset The Current Modelview Matrix
invoke glTranslatef, val0_0d, val0_0d, val_8_0d
invoke glRotatef, DWORD PTR vangle, val1_0d, val0_0d, val0_0d
invoke glRotatef, DWORD PTR angle, val0_0d, val1_0d, val0_0d

invoke glBegin, GL_QUADS; //Draw A Quad

glRed
invoke glVertex3f, val1_0d, val1_0d, val_1_0d;     // Top Right Of The Quad (Top)
glGreen
invoke glVertex3f, val_1_0d, val1_0d, val_1_0d;     // Top Left Of The Quad (Top)
glBlue
invoke glVertex3f, val_1_0d, val1_0d, val1_0d;     // Bottom Left Of The Quad (Top)
glWhite
invoke glVertex3f, val1_0d, val1_0d, val1_0d;     // Bottom Right Of The Quad (Top)

glBlack
invoke glVertex3f, val1_0d, val_1_0d, val1_0d;     // Top Right Of The Quad (Bottom)
glGrey
invoke glVertex3f, val_1_0d, val_1_0d, val1_0d;     // Top Left Of The Quad (Bottom)
glRed
invoke glVertex3f, val_1_0d, val_1_0d, val_1_0d;     // Bottom Left Of The Quad (Bottom)
glGreen
invoke glVertex3f, val1_0d, val_1_0d, val_1_0d;     // Bottom Right Of The Quad (Bottom)

glBlue
invoke glVertex3f, val1_0d, val1_0d, val1_0d ; // Top Right Of The Quad (Front)
glWhite
invoke glVertex3f, val_1_0d, val1_0d, val1_0d ; // Top Left Of The Quad (Front)
glBlack
invoke glVertex3f, val_1_0d, val_1_0d, val1_0d ; // Bottom Left Of The Quad (Front)
glGrey
invoke glVertex3f, val1_0d, val_1_0d, val1_0d ; // Bottom Right Of The Quad (Front)

glRed
invoke glVertex3f, val1_0d, val_1_0d, val_1_0d ;     // Top Right Of The Quad (Back)
glGreen
invoke glVertex3f, val_1_0d, val_1_0d, val_1_0d ;     // Top Left Of The Quad (Back)
glBlue
invoke glVertex3f, val_1_0d, val1_0d, val_1_0d ;     // Bottom Left Of The Quad (Back)
glWhite
invoke glVertex3f, val1_0d, val1_0d, val_1_0d ;     // Bottom Right Of The Quad (Back)

glBlack
invoke glVertex3f, val_1_0d, val1_0d, val1_0d ;     // Top Right Of The Quad (Left)
glGrey
invoke glVertex3f, val_1_0d, val1_0d, val_1_0d ;     // Top Left Of The Quad (Left)
glRed 
invoke glVertex3f, val_1_0d, val_1_0d, val_1_0d ;     // Bottom Left Of The Quad (Left)
glGreen
invoke glVertex3f, val_1_0d, val_1_0d, val1_0d ;     // Bottom Right Of The Quad (Left)

glBlue
invoke glVertex3f, val1_0d, val1_0d, val_1_0d ;     // Top Right Of The Quad (Right)
glWhite
invoke glVertex3f, val1_0d, val1_0d, val1_0d ;     // Top Left Of The Quad (Right)
glBlack
invoke glVertex3f, val1_0d, val_1_0d, val1_0d ;     // Bottom Left Of The Quad (Right)
glGrey
invoke glVertex3f, val1_0d, val_1_0d, val_1_0d ;     // Bottom Right Of The Quad (Right)

invoke glEnd

invoke SwapBuffers,hDC

    fld angle
    fadd delta_angle
    fstp angle

   
    .endif

.endw

invoke DisableOpenGL, hwnd

mov eax, msg.wParam
ret

WinMain EndP

;========================================================
WndProc Proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM

LOCAL Rect:RECT

.if ( uMsg == WM_DESTROY )

quit_label:
   invoke PostQuitMessage, NULL
   mov eax, 0
   jmp ret_label

.elseif ( uMsg == WM_CREATE )



.elseif ( uMsg == WM_SIZE )

   mov   eax,lParam;LOWORD lParam
               and   eax,0FFFFh;LOWORD lParam
          mov   ebx,lParam;HIWORD lParam
               shr   ebx,16;HIWORD lParam
               and   ebx,0FFFFh;HIWORD lParam
invoke ResizeGLScene, eax, ebx
mov eax, 0
jmp ret_label

.elseif ( uMsg == WM_KEYDOWN )

   .if ( wParam == VK_ESCAPE)

     jmp quit_label
   
   .endif

.else

   invoke DefWindowProc, hWnd, uMsg, wParam, lParam
   jmp ret_label

.endif

ret_label:
ret

WndProc EndP

;========================================================
EnableOpenGL Proc hWnd:HWND

LOCAL iFormat:dword
LOCAL pfd:PIXELFORMATDESCRIPTOR

;  get the device context (DC)
invoke GetDC, hWnd
mov hDC, eax

;  set the pixel format for the DC
lea edi, pfd
xor eax, eax
mov ecx, sizeof pfd / sizeof DWORD
rep stosd                  ; zero pfd structure

mov pfd.nSize, sizeof pfd
mov pfd.nVersion, 1
mov pfd.dwFlags, PFD_DRAW_TO_WINDOW or PFD_SUPPORT_OPENGL or PFD_DOUBLEBUFFER
mov pfd.iPixelType, PFD_TYPE_RGBA
mov pfd.cColorBits, 16
mov pfd.cDepthBits, 16
mov pfd.iLayerType, PFD_MAIN_PLANE
invoke ChoosePixelFormat, hDC, addr pfd
mov iFormat, eax
invoke SetPixelFormat, hDC, iFormat, addr pfd

;  create and enable the render context (RC)
invoke wglCreateContext, hDC
mov hRC, eax
invoke wglMakeCurrent, hDC, hRC
invoke ResizeGLScene, widthwnd, heightwnd
;Init OpenGL
invoke glShadeModel,GL_SMOOTH;// Enable Smooth Shading
invoke glClearColor,DWORD PTR val0_0d,DWORD PTR val0_0d,DWORD PTR val0_0d, DWORD PTR val0_5d  ;// Black Background
invoke glClearDepth,DWORD PTR val1_0q[0],DWORD PTR val1_0q[4];// Depth Buffer Setup
invoke glEnable,GL_DEPTH_TEST;// Enables Depth Testing
invoke glDepthFunc,GL_LEQUAL;// The Type Of Depth Testing To Do
invoke glHint,GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST;//Init OpenGL 
ret

EnableOpenGL EndP

;========================================================
DisableOpenGL Proc hWnd:HWND

invoke wglMakeCurrent, NULL, NULL
invoke wglDeleteContext, hRC
invoke ReleaseDC, hWnd, hDC
ret

DisableOpenGL EndP

;========================================================
ResizeGLScene Proc nwidth:DWORD,nheight:DWORD

LOCAL ratio:REAL8
  invoke glViewport,0,0,nwidth,nheight;      // Reset The Current Viewport

invoke glMatrixMode,GL_PROJECTION;      // Select The Projection Matrix
invoke glLoadIdentity ;         // Reset The Projection Matrix

;// Calculate The Aspect Ratio Of The Window
   fild nwidth
   fild nheight
   fdivp st(1), st(0)
   fstp ratio

invoke gluPerspective,DWORD PTR val45_0q,DWORD PTR val45_0q[4],\
DWORD PTR ratio,DWORD PTR ratio[4],DWORD PTR val0_1q,DWORD PTR val0_1q[4],\
DWORD PTR val100_0q,DWORD PTR val100_0q[4]

invoke glMatrixMode,GL_MODELVIEW; // Select The Modelview Matrix
invoke glLoadIdentity 
ret

ResizeGLScene EndP
End Start


Added code tags

dedndave

the rendering context HGLRC appears to be an undefined type, is all
one way to fix it is to replace this
hRC HGLRC ?
with this
hRC dd ?

MichaelW

HGLRC is not defined anywhere in the MASM32 includes. Suspecting that is was something more complex than a DWORD I searched the PSDK header files for HGLRC and found in windef.h:

DECLARE_HANDLE(HGLRC);          // OpenGL

And a search for DECLARE_HANDLE found in winnt.h:

#ifdef STRICT
typedef void *HANDLE;
#define DECLARE_HANDLE(name) struct name##__ { int unused; }; typedef struct name##__ *name
#else
typedef PVOID HANDLE;
#define DECLARE_HANDLE(name) typedef HANDLE name
#endif
typedef HANDLE *PHANDLE;

So I substituted:

hRC HANDLE ?

And the errors went away and I got an EXE that runs and displays a rotating cube. A DWORD should work just as well.
eschew obfuscation

jj2007

That looks cute. I wonder what would happen to The Empire of C if they limited this nerd Chinese to the handful of occasions where the variables are not a DWORD ::)

Cr8zyNbunny

Ooh thanks alot guys Jesus Christ Bless you all give you health & peace, redemption, salvation, happiness, joy, love, and care! :lol  :cheekygreen:

dedndave

 :bg
it's just a context handle - lol
can't wait for you to have a real bug   :P

Cr8zyNbunny

Ooh thanks alot guys.Yesterday in the afternoon I had tried  hRC dd  ?.But when I hit the project, build all, In qeditor it gave errors. I would have never suspected this LOL, I am lame, just by leaving the question mark clode when defining dword brought me here and to the winasm.net forums to make an account and ask the coding masters. Alot of people I know do not have an idea what assembly language is lol, I wish more schools need to teach this :). My wife was impressed with how fast it assembled. She studided Computer Science but Is up to her neck with bills and debt and the family lol. Jesus Christ Bless you all give you health & peace, redemption, salvation, happiness, joy, love, and care! :lol  :cheekygreen:.

Cr8zyNbunny

*close like this dd? caused the same assembler errors. I am so ashamed lol. But you guys are the absolute best! :thumbu :U :dance: :clap:

abnuque

hDC and hRC are HANDLE
and HANDLE is defined typedef DWORD in \masm32\include\windows.inc

therefore you can compile the above code with either hDC HANDLE ? or hDC DWORD ?
same with hRC it compiles well with hRC DWORD ?

but I am just confused if the HANDLE(s) are received by the invoked functions as PTR or immediate value :green

dedndave

i can't think of any function where you pass a pointer to a handle   :P

invoke wglMakeCurrent, hDC, hRC
if hRC resides at 00403000h and hDC resides at 00403004h, the assembler generates...
        push    [00403000]
        push    [00403004]
        call    wglMakeCurrent

so, while they may be referenced by address, the actual handles are on the stack as parameters