Hello, I have simple program in C that draws triangle using openGL. I tried to create analogue in masm32. But all I see is black-colored window created. Idk what's the problem, all functions work correctly as it seems. I didnt download any other libraries except official(?) masm32 from masm32 dot com.
main.asm:
include main.inc
.code
start:
invoke GetModuleHandle, NULL
mov hInstance, eax
invoke WinMain, hInstance, NULL, NULL, SW_SHOWDEFAULT
invoke ExitProcess, eax
WinMain proc hInst:HINSTANCE, hPrevInst:HINSTANCE, CmdLine:LPSTR, CmdShow:DWORD
LOCAL wc:WNDCLASSEX
LOCAL msg:MSG
mov wc.cbSize, SIZEOF WNDCLASSEX
mov wc.style, CS_OWNDC
mov wc.lpfnWndProc, OFFSET WndProc
mov wc.cbClsExtra, NULL
mov wc.cbWndExtra, NULL
push hInst
pop wc.hInstance
mov wc.hbrBackground, COLOR_WINDOW + 1
mov wc.lpszMenuName, NULL
mov wc.lpszClassName, offset szClassName
invoke LoadIcon, NULL, IDI_APPLICATION
mov wc.hIcon, eax
mov wc.hIconSm, eax
invoke LoadCursor, NULL, IDC_ARROW
mov wc.hCursor, eax
invoke RegisterClassEx, addr wc
invoke CreateWindowEx, NULL, offset szClassName, offset szAppName, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, wndWidth, wndHeight, NULL, NULL, hInst, NULL
mov hWnd, eax
invoke ShowWindow, hWnd, CmdShow
;invoke UpdateWindow, hWnd
invoke EnableOpenGL
.WHILE TRUE
invoke PeekMessage, ADDR msg, NULL, 0, 0, PM_REMOVE
.if eax != 0
.if msg.message == WM_QUIT
.break
.else
invoke TranslateMessage, ADDR msg
invoke DispatchMessage, ADDR msg
.endif
.else
invoke glClearColor, 0,0,0,0
invoke glClear, GL_COLOR_BUFFER_BIT
invoke glPushMatrix
invoke glBegin, GL_TRIANGLES
invoke glColor3f, 1,0,0
invoke glVertex2f, 0, 1
invoke glVertex2f, 1, 0
invoke glVertex2f, 0, -1
invoke glEnd
invoke glPopMatrix
invoke SwapBuffers, hDC
invoke Sleep, 1
.endif
.ENDW
invoke DisableOpenGL
invoke DestroyWindow, hWnd
mov eax, msg.wParam
ret
WinMain endp
WndProc proc hwnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
.IF uMsg == WM_DESTROY
invoke PostQuitMessage, 0
.ELSE
invoke DefWindowProc, hwnd, uMsg, wParam, lParam
ret
.ENDIF
xor eax, eax
ret
WndProc endp
EnableOpenGL proc
LOCAL pfd:PIXELFORMATDESCRIPTOR
LOCAL iFormat: DWORD
invoke GetDC, hWnd
mov hDC, eax
mov pfd.nSize, SIZEOF PIXELFORMATDESCRIPTOR
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, 0
mov pfd.cDepthBits, 16
mov pfd.cAlphaBits, 0
mov pfd.cAccumBits, 0
mov pfd.cStencilBits, 0
mov pfd.cAuxBuffers, 0
mov pfd.iLayerType, PFD_MAIN_PLANE
invoke ChoosePixelFormat, hDC, addr pfd
mov iFormat, eax
invoke SetPixelFormat, hDC, iFormat, addr pfd
invoke wglCreateContext, hDC
mov hRC, eax
invoke wglMakeCurrent, hDC, hRC
invoke glMatrixMode, GL_MODELVIEW
invoke glLoadIdentity
ret
EnableOpenGL endp
DisableOpenGL proc
invoke wglMakeCurrent, NULL, NULL
invoke wglDeleteContext, hRC
invoke ReleaseDC, hWnd, hDC
Ret
DisableOpenGL endp
end start
main.inc:
.386
.model flat, stdcall
option casemap :none
include \masm32\include\windows.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc
include \masm32\include\gdi32.inc
include \masm32\include\opengl32.inc
include \masm32\include\glu32.inc
includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\gdi32.lib
includelib \masm32\lib\opengl32.lib
includelib \masm32\lib\glu32.lib
WinMain proto :HINSTANCE, :HINSTANCE, :LPSTR, :DWORD
WndProc proto :HWND, :UINT, :WPARAM, :LPARAM
EnableOpenGL proto
DisableOpenGL proto
.data
szClassName db "SimpleWinClass", 0
szAppName db "OpenGL in MASM", 0
wndWidth dd 500
wndHeight dd 500
hInstance HINSTANCE ?
hWnd HWND ?
hDC HDC ?
hRC DWORD ?
invoke glColor3f,FP4(1.0),FP4(0.0),FP4(1.0)
invoke glVertex2f, FP4(0.0), FP4(1.0)
invoke glVertex2f, FP4(1.0),FP4(0.0)
invoke glVertex2f, FP4(0.0),FP4(-1.0)
(https://i.postimg.cc/FdVChV8c/Untitled.png) (https://postimg.cc/FdVChV8c)
Thanks for your reply, mabdelouahab. What a coincidence I've ran 5km, had a rest and then this idea just came to my mind: float variables differs from integer in binary. I rapidly tested it, creating two variables REAL4 1.0 and it worked!
Hi
Mishanya00 Look here
- OpenGL in masm64 (https://masm32.com/board/index.php?topic=8514.0)
- NeHe Tutorial in masm64 (https://masm32.com/board/index.php?topic=8722.0)
- Lessons are not published on the NeHe site (https://masm32.com/board/index.php?topic=9357.0)