News:

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

Main Menu

OpenGL in masm64

Started by Mikl__, May 02, 2020, 05:08:37 PM

Previous topic - Next topic

Mikl__

example of the standard FASM, there are Opengl32.inc, Glu32.inc, Glut32.inc, asm-file, cursor and exe-file in attachemnt.
;                        Y-axis
;    4-th vertex violet  |   3-rd vertex blue
;           -0.6,0.6     |      0.6,0.6
;               +--------+--------+
;               |        |        |
;               |        |        |
;               |        |0.0,0.0 |
;           ----+--------+--------+-----X-axis
;               |        |        |
;               |        |        |
;               +--------+--------+
;           -0.6,-0.6    |     0.6,-0.6
;    1-st vertex red     |   2-nd vertex dark

Mikl__

OpenGl asm blank text; GUI #
include win64a . inc
; ---------------
WINDOWWIDTH = 440
WINDOWHEIGHT = 400
. code
Winmain proc
msg local : by MSG
xor ebx , ebx
        mov edi , offset szClassName
        mov esi , IMAGE_BASE
        mov ecx , offset FileName
invoke LoadCursorFromFile
        push rax ; hIconSm
push rdi ; lpszClassName
push rbx ; lpszMenuName
push COLOR_WINDOWTEXT + 1 ; hbrBackground
push rax ; hCursor
push rax        ; hIcon
push rsi ; hInstance
push rbx        ; cbClsExtra & cbWndExtra
pushaddr WndProc ; lpfnWndProc
push sizeof WNDCLASSEX       ; cbSize & style
    invoke RegisterClassEx , esp ; addr WNDCLASSEX
push rbx
push rsi ; rsi = 400000h
shl esi , 9 ; rsi = CW_USEDEFAULT
push rbx
push rbx
push WINDOWHEIGHT
push WINDOWWIDTH
push rsi
push rsi
sub esp , 20h
    invoke CreateWindowEx , 0 , edi , edi , WS_OVERLAPPEDWINDOW or WS_CLIPCHILDREN or WS_CLIPSIBLINGS or WS_VISIBLE
; message loop
    lea edi , msg
@@ : invoke GetMessage , edi , 0 , 0 , 0
cmp msg . wParam , VK_ESCAPE ; user press 'Esc'?
je wmDESTROY
invoke DispatchMessage , edi
jmp @b
Winmain endp
WndProc proc hWin : QWORD , uMsg : QWORD , wParam : QWORD , lParam : QWORD
        mov hWin , rcx
        cmp edx , WM_CREATE
je      wmCREATE
        cmp edx , WM_SIZE
je      wmSIZE
        cmp edx , WM_PAINT
je      wmPAINT
        cmp edx , WM_DESTROY
je      wmDESTROY 
defa ult : leave
jmp NtdllDefWindowProc_
wmDESTROY :: invoke wglMakeCurrent , 0 , 0
invoke wglDeleteContext , hrc
invoke ReleaseDC , hWin , hDC
invoke RtlExitUserProcess , NULL
wmCREATE : invoke GetDC ; get the window context
mov hDC , rax
; initialize the OpenGL pixel format descriptor (support for OpenGL and dual
; buffering) select it
        mov edx , offset PixFrm
invoke ChoosePixelFormat , eax
; and install it
mov r8d , offset PixFrm
invoke SetPixelFormat , hDC , eax
; convert the window context to the OpenGL context
invoke wglCreateContext , hDC
mov hrc , rax
; and make it current
invoke wglMakeCurrent , hDC , eax
; choose the mode of calculating perspective transformations (best)
invoke glHint , GL_PERSPECTIVE_CORRECTION_HINT , GL_NICEST ;
; choose a perspective projection matrix for transformations
invoke glMatrixMode , GL_PROJECTION ; selects the active matrix from the list (stack)
; multiply it by the perspective matrix, i.e. just turn it on (use the glcall macro since parameters are transmitted as 8 bytes)
movq xmm0 , constd90_0
movq xmm1 , ratio
movq xmm2 , constd0_1
movq xmm3 , constd100_0
invoke gluPerspective
; choose the image matrix for transformations
invoke glMatrixMode , GL_MODELVIEW ; selects the active matrix from the list (stack)
        jmp wmBYE
wmSIZE : ; --------------- Resize the scene
movzx r8 , r9w
shr r9 , 16
invoke glViewport , 0 , 0 ; Change the image display window
        jmp wmBYE
wmPAINT : ; No pending messages: draw the scene
; --------------- Display the scene
; clear the screen buffer
invoke glClear , GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT
; zero the current matrix (image matrix)
invoke glLoadIdentity
; move objects deep into the screen (z = -5 and left x = -1.5)
movd xmm0 , const_1_5 ; ebx
movd xmm1 , ebx
movd xmm2 , const_5_0
invoke glTranslatef
        invoke glFlush
; display the buffer on the screen
        invoke SwapBuffers , hDC
wmBYE : leave
retn
Wndproc endp
hDC dq ?
hrc dq ?
PixFrm label PIXELFORMATDESCRIPTOR
PixFrm label PIXELFORMATDESCRIPTOR
  nSize             dw sizeof PIXELFORMATDESCRIPTOR ; data structure size
  nVersion           dw 1 ; data structure version
  dwFlags           dd PFD_SUPPORT_OPENGL or PFD_DOUBLEBUFFER or \
PFD_DRAW_TO_WINDOW ; A set of bit flags that specify the properties of the point buffer
  iPixelType         db PFD_TYPE_RGBA ; Requires RGBA format
  cColorBits         db 32 ; Selects a bit of color depth
  cRedBits           db 0
  cRedShift         db 0
  cGreenBits         db 0
  cGreenShift       db 0
  cBlueBits         db 0
  cBlueShift         db 0 ; Ignore color bits
  cAlphaBits         db 0 ; No transparency buffer
  cAlphaShift       db 0 ; Shift bit is ignored
  cAccumBits         db 0 ; No accumulation buffer
  cAccumRedBits     db 0
  cAccumGreenBits   db 0
  cAccumBlueBits     db 0
  cAccumAlphaBits   db 0 ; Accumulation bits are ignored
  cDepthBits         db 32 ; 32 bit Z-buffer (depth buffer)
  cStencilBits       db 0 ; No stencil buffer
  cAuxBuffers       db 0 ; No auxiliary buffers
  iLayerType         db PFD_MAIN_PLANE ; Main drawing layer
  bReserved         db 0 ; Reserved
  dwLayerMask       dd 0
  dwVisibleMask     dd 0
  dwDamageMask       dd 0 ; Layer masks are ignored
szClassName db "Uncle Remus tales: #40 OpenGL" , 0
FileName db "Images\br_Rabbit3.cur" , 0
ratio dq 1.1 ; 440/400
const_1_5 dd - 1.5
const_5_0 dd - 5.0
constd90_0 dq 90.0
constd0_1 dq 0.1
constd100_0 dq 100.0
end
bat-filecls
set masm64_path=\masm43\
set filename=%~n1
if exist errors.txt del errors.txt
call :read_settings %filename%
@echo %kind_of_file%
goto %kind_of_file%
:CONSOLE
if exist %filename%.exe del %filename%.exe
if exist %filename%.obj del %filename%.obj
if exist errors.txt del errors.txt
%masm64_path%bin\ml64 /Cp /c /I"%masm64_path%Include" %filename%.asm >> errors.txt
if errorlevel 1 exit
if exist %1.rc (
%masm64_path%bin\RC /r /i"%masm64_path%\Include" %filename%.rc >> errors.txt
%masm64_path%bin\link /LIBPATH:"%masm64_path%Lib" ^
/LARGEADDRESSAWARE:NO /BASE:0x400000 /STUB:%masm64_path%bin\stubby.exe ^
/SECTION:.text,W /ALIGN:16 /entry:WinMain /MERGE:.rdata=.text ^
/fixed /nocoffgrpinfo %filename%.obj %filename%.res >> errors.txt
if exist %1.res del %1.res
) else (
%masm64_path%bin\link /SUBSYSTEM:CONSOLE /LIBPATH:"%masm64_path%Lib" ^
/entry:WinMain %filename%.obj /LARGEADDRESSAWARE:NO ^
/ALIGN:16 /SECTION:.text,W /BASE:0x400000 /STUB:%masm64_path%\bin\stubby.exe >> errors.txt
)
if errorlevel 1 exit
del %filename%.obj
goto exit1
:GUI
if exist %filename%.exe del %filename%.exe
if exist %filename%.obj del %filename%.obj
if exist errors.txt del errors.txt
%masm64_path%bin\ml64 /Cp /c /I"%masm64_path%Include" %filename%.asm >> errors.txt
if errorlevel 1 exit
if exist %1.rc (
%masm64_path%bin\RC /r /i"%masm64_path%\Include" %filename%.rc >> errors.txt
%masm64_path%bin\link /LIBPATH:"%masm64_path%Lib" ^
/LARGEADDRESSAWARE:NO /BASE:0x400000 /STUB:%masm64_path%bin\stubby.exe ^
/SECTION:.text,W /ALIGN:16 /entry:WinMain ^
/fixed /nocoffgrpinfo %filename%.obj %filename%.res >> errors.txt
if exist %1.res del %1.res
) else (
%masm64_path%bin\link /SUBSYSTEM:WINDOWS /LIBPATH:"%masm64_path%Lib" ^
/LARGEADDRESSAWARE:NO /BASE:0x400000 /STUB:%masm64_path%bin\stubby.exe ^
/SECTION:.text,W /ALIGN:16 /entry:WinMain /MERGE:.rdata=.text ^
/fixed /nocoffgrpinfo %filename%.obj >> errors.txt
)
if errorlevel 1 exit
goto exit1
:DLL
if exist %filename%.dll del %filename%.dll
%masm64_path%bin\ml64 /c /Cp /I %masm64_path%include %filename%.asm >> errors.txt
if errorlevel 1 exit
if exist %1.rc (
%masm64_path%bin\RC /r  %filename%.rc >> errors.txt
if errorlevel 1 exit
%masm64_path%bin\link /SUBSYSTEM:WINDOWS /LIBPATH:%masm64_path%lib ^
/ENTRY:DllMain /DLL /DLL /section:.bss,S /stub:%masm64_path%bin\stubby.exe  ^
%filename%.obj %filename%.res /DEF:%filename%.def >> errors.txt
if exist %1.res del %1.res
) else (
%masm64_path%bin\link /SUBSYSTEM:WINDOWS /LIBPATH:%masm64_path%lib ^
/ENTRY:DllMain /DLL /DLL /section:.bss,S /stub:%masm64_path%bin\stubby.exe  ^
%filename%.obj /DEF:%filename%.def >> errors.txt
)
if errorlevel 1 exit
del %filename%.exp
:exit1
del %filename%.obj
del errors.txt
:: %filename%.exe
exit
:read_settings
for /f "eol=# tokens=2-3" %%A in (%filename%.asm) do (
set kind_of_file=%%A
if %%B == # exit /b )
exit /b

Mikl__

#2
We draw a triangle, there are asm-file, cursor, exe-file and win64a.inc in the attachment.

Mikl__

#3
triangle and rectangle, there are asm-file, cursor and exe-file in the attachment.

Mikl__

#4
Colored triangle and rectangle. There are asm-file, cursor and exe-file in the attachment.

Mikl__

#5
Rotating triangle and the rectangle. There are asm-file, cursor and exe-file in the attachment.

Mikl__

#6
From four triangles we make a rotating tetrahedron (a pyramid in which all faces are equilateral triangles). There are asm-file, cursor and exe-file in the attachment.

Mikl__

#7
This program demonstrates using mipmaps for texture maps. To overtly show the effect of mipmaps, each mipmap reduction level has a solidly colored, contrasting texture image. Thus, the quadrilateral which is drawn is drawn with several different colors. There are asm-file, cursor and exe-file in the attachment. A prototype is model.c from https://www.opengl.org/archives/resources/code/samples/redbook/

Mikl__

#8
This program demonstrates vertex arrays. There are asm-file, cursor and exe-file in the attachment. A prototype is varray.c from https://www.opengl.org/archives/resources/code/samples/redbook/

Mikl__

#9
This program demonstrates using mipmaps for texture maps. To overtly show the effect of mipmaps, each mipmap reduction level has a solidly colored, contrasting texture image. Thus, the quadrilateral which is drawn is drawn with several different colors. A prototype is mipmap.c from https://www.opengl.org/archives/resources/code/samples/redbook/ There are asm-file, cursor and exe-file in the attachment.

Mikl__

#10
Points, lines, triangle, rectangles, pentagon. There are asm-file, cursor and exe-file in the attachment.

Mikl__

#11
A rewrited example from the "FASM OpenGL tutorial from Tyler Durden"
Motion blur - blurring the image when you rotate the camera, play back motion scenes or fast moving objects. Rendering is the process of obtaining an image from a model using a computer program. There are asm-file, cursor and exe-file in the attachment.

Mikl__

#12
Redesigned example from the "FASM OpenGL tutorial from Tyler Durden". Texturing is a stage in the process of creating and visualizing a 3D model, which allows you to give the surface of an object certain parameters and properties in order to obtain maximum realism. There are asm-file, cursor and exe-file in the attachment.

Mikl__

#13
Rewrited example from the "FASM OpenGL tutorial from Tyler Durden"
alpha-blending is a transparency effect. In the attachment, the asm-file, cursor, raw file and exe

Mikl__

Reworked example from the "FASM OpenGL tutorial from Tyler Durden"
The Fog. In the attachment, the asm-file, cursor, raw-file, opengl32.inc and exe-file