You are on page 1of 18

td_win32asm_410.

asm
;==============================================================================
;
Test Department's WINDOWS 32 BIT x86 ASSEMBLY example
410
;==============================================================================
;==============================================================================
; ==> Part 410 : OpenGL example
;-----------------------------------------------------------------------------; Cheers,
; here is my OpenGL example with a Windows 9x HIGH RESOLUTION TIMER.
; YOU NEED A PI 233 MHZ / WINDOWS 95B (!) OR GREATER (OPENGL32.DLL,GLU32.DLL).
; You also need the Opengl.hlp / Mmedia.hlp reference, a link is on my website.
; The first idea here is to obtain more time for our thread, I hope it works.
; I call API = "GetCurrentThread" to get a pseudo handle.
; Ready to call API = "SetThreadPriority" with THREAD_PRIORITY_HIGHEST = 2h.
; The next idea here is to use a HIGH RESOLUTION TIMER from the multimedia
; library. This timer runs in its own thread !
; API "timeSetEvent" / "timeKillEvent" (Mmedia.hlp) is the function call.
; This timer is much more exact than a standard windows timer.
; This timer could only beat by multimedia applications using MCI services.
; Do you ever try using a standard windows timer with OpenGL, forget it.
; Using this TIMER allows me to program an exact (not realy) OpenGL animation.
; In the window procedure (WP1) reacting to a WM_CREATE message I setup the
; OpenGL window (OpenGL.hlp) and the discussed timer (Mmedia.hlp).
; This timer calls a timer procedure (TP1) on the specified delay time.
; The timer procedure post a WM_PAINT message into the message queue of the
; main window message loop, so in the end to the main window procedure (WP1).
; With a FLAG I ensure to only post a new message if the last was proceed !
; If the main window procedure (WP1) receives a WM_PAINT message I draw the
; OpenGL stuff.
; Here I also use some simple FPU instructions to add two real values.
; Do not forget to init the FPU, only once (perhaps you did it before ?).
; I set the FLAG to indicate the timer procedure (TP1) that WM_PAINT is proceed
; But after all, it is only a demo ..., where is the next whisky bar ?
; Yeaps
;==============================================================================
; Assembler directives
;-----------------------------------------------------------------------------.386
; specifies the processor our program want run on
.Model Flat ,StdCall
; Flat for Win9x (32 Bit), Calling Convention
option casemap:none
; case sensitive !!!
;==============================================================================
; Include all files where API functins resist you want use, set correct path
;-----------------------------------------------------------------------------include D:\Masm32\include\windows.inc
includelib kernel32.lib
includelib user32.lib
includelib opengl32.lib
;openGL library
includelib gdi32.lib
includelib winmm.lib
;==============================================================================
Page 1

td_win32asm_410.asm
; Declaration of used API functions,take a look into WIN32.HLP and *.inc files
;-----------------------------------------------------------------------------GetModuleHandleA
PROTO :DWORD
LoadIconA
PROTO :DWORD,:DWORD
LoadCursorA
PROTO :DWORD,:DWORD
RegisterClassExA
PROTO :DWORD
CreateWindowExA
PROTO :DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD,
:DWORD,:DWORD,:DWORD,:DWORD,:DWORD
ShowWindow
PROTO :DWORD,:DWORD
UpdateWindow
PROTO :DWORD
GetMessageA
PROTO :DWORD,:DWORD,:DWORD,:DWORD
TranslateMessage
PROTO :DWORD
DispatchMessageA
PROTO :DWORD
PostQuitMessage
PROTO :DWORD
DefWindowProcA
PROTO :DWORD,:DWORD,:DWORD,:DWORD
ExitProcess
PROTO :DWORD
MessageBoxA
PROTO :DWORD,:DWORD,:DWORD,:DWORD
DestroyWindow
PROTO :DWORD
GetDC
PROTO :DWORD
ChoosePixelFormat
PROTO :DWORD,:DWORD
SetPixelFormat
PROTO :DWORD,:DWORD,:DWORD
wglCreateContext
PROTO :DWORD
wglMakeCurrent
PROTO :DWORD,:DWORD
glMatrixMode
PROTO :DWORD
glFrustum
PROTO :DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD,
:DWORD,:DWORD,:DWORD,:DWORD,:DWORD
glTranslatef
PROTO :DWORD,:DWORD,:DWORD
glScalef
PROTO :DWORD,:DWORD,:DWORD
glShadeModel
PROTO :DWORD
glEnable
PROTO :DWORD
GetClientRect
PROTO :DWORD,:DWORD
glViewport
PROTO :DWORD,:DWORD,:DWORD,:DWORD
wglDeleteContext
PROTO :DWORD
ReleaseDC
PROTO :DWORD,:DWORD
glPushMatrix
PROTO
glRotatef
PROTO :DWORD,:DWORD,:DWORD,:DWORD
glClear
PROTO :DWORD
glDisable
PROTO :DWORD
glBegin
PROTO :DWORD
glNormal3f
PROTO :DWORD,:DWORD,:DWORD
glColor3f
PROTO :DWORD,:DWORD,:DWORD
glVertex3f
PROTO :DWORD,:DWORD,:DWORD
glEnd
PROTO
glPopMatrix
PROTO
glFinish
PROTO
SwapBuffers
PROTO :DWORD
PostMessageA
PROTO :DWORD,:DWORD,:DWORD,:DWORD
timeGetDevCaps
PROTO :DWORD,:DWORD
timeSetEvent
PROTO :DWORD,:DWORD,:DWORD,:DWORD,:DWORD
timeKillEvent
PROTO :DWORD
GetCurrentThread
PROTO
SetThreadPriority
PROTO :DWORD,:DWORD
Page 2

td_win32asm_410.asm
;==============================================================================
; .const = the constants area starts here,constants are defined and fixed
;-----------------------------------------------------------------------------.const
; - Parameter MAIN WINDOW CallBack Procedure ( API=RegisterClassExA ) WP1_CallBack
equ [ebp+4]
;return address
WP1_hWnd
equ [ebp+8]
;handle of window who receives message
WP1_uMsg
equ [ebp+12]
;the message number
WP1_wParam
equ [ebp+16]
;extra info about the message
WP1_lParam
equ [ebp+20]
;extra info about the message
;==============================================================================
; .Data = the data area starts here, datas are defined but not fixed
;
MASM converts real4, real8, real10 values into FPU / IEEE standard.
;-----------------------------------------------------------------------------.Data
IconName
db "TDIcon",0
;icon name in rc file
MenuName
db "TDMenu",0
;menu name in rc file
ClassName
db "TDWinClass",0
;name of windows class
WindowName
db "Test Department - http://surf.to/TestD",0;winname
WM_PAINT_proceed
db 0h
;WM_PAINT flag
speed
dd 0Ch
;default animation speed
gl_Mode
dd 7h
;default gl_Mode, cube=7h
pointervertex
dd 0h
;pointer to vertexArea
pointercolor
dd 0h
;pointer to colorArea
Scale_counter
dd 10h
;default/max scale count value
; - coordinates ( API=glFrustum ) _glFrustum_zfar
real8
4.0
_glFrustum_znear
real8
1.0
_glFrustum_top
real8
0.6
_glFrustum_bottom
real8
-0.6
_glFrustum_right
real8
0.6
_glFrustum_left
real8
-0.6

;so what ?, QWORD=8 byte !


;
;
;
;
;

; - normal values ( API=glNormalf ) normalArea1


real4
1.0
normalArea2
real4
-1.0
normalArea3
real4
1.0
normalArea4
real4
-1.0
normalArea5
real4
1.0
normalArea6
real4
-1.0

;normal
;
;
;
;
;

; - rotate values ( API=glRotatef ) rotateAngel


real4
0.0
rotateAdd
real4
2.0
rotate_z1
real4
0.3
rotate_y1
real4
1.0
rotate_x1
real4
0.0
rotate_z2
real4
1.0
rotate_y2
real4
0.0
rotate_x2
real4
0.0

;default rotate angel


;added to rotate angel
;coordinates
;
;
;coordinates
;
;
Page 3

td_win32asm_410.asm
; - translate vector values ( API=glTranslatef ) transVector_z
real4
-2.0
;z
; - scale values ( API=glScalef ) scale_Out
real4
0.9
scale_In
real4
1.1111

;scale multiplicator
;why this ?, you don't know ?

; - ARRAY of 3 vertex coordinates z, y, x ( API=glVertex3f ) ; 4 for each of the 6 areas. 12 parameter for each side of the object.
vertexArea1 real4
0.6,0.4,0.6,0.6,0.4,-0.6,0.6,-0.4,-0.6,0.6,-0.4,0.6
vertexArea2 real4
-0.6,-0.4,-0.6,-0.6,0.4,-0.6,-0.6,0.4,0.6,-0.6,-0.4,0.6
vertexArea3 real4
0.6,0.4,0.6,-0.6,0.4,0.6,-0.6,0.4,-0.6,0.6,0.4,-0.6
vertexArea4 real4
-0.6,-0.4,-0.6,-0.6,-0.4,0.6,0.6,-0.4,0.6,0.6,-0.4,-0.6
vertexArea5 real4
0.6,0.4,0.6,0.6,-0.4,0.6,-0.6,-0.4,0.6,-0.6,0.4,0.6
vertexArea6 real4
-0.6,-0.4,-0.6,0.6,-0.4,-0.6,0.6,0.4,-0.6,-0.6,0.4,-0.6
; - ARRAY of 3 color values B, G, R ( API=glColor3f ) ; 4 for each of the 6 areas. Colors will be associated with the vertex.
colorArea1 real4
0.75,0.2,0.4,-0.5,-0.5,0.5,1.0,0.5,0.0,0.0,-0.5,0.6
colorArea2 real4
1.0,0.0,0.0,1.0,1.0,0.0,1.0,1.0,1.0,0.4,0.5,0.75
colorArea3 real4
1.0,0.0,0.0,-0.5,0.5,0.5,1.0,-1.0,1.0,0.4,0.2,0.75
colorArea4 real4
0.2,0.3,0.1,-0.5,-0.5,0.5,0.5,-0.5,-0.5,0.4,0.2,0.75
colorArea5 real4
0.5,0.0,0.0,-0.5,-0.5,0.5,0.5,-0.5,-0.5,0.4,0.2,0.75
colorArea6 real4
1.0,0.4,0.0,0.5,-0.5,0.5,0.5,-0.5,-0.5,0.4,0.2,0.75
;==============================================================================
; .Data? = the data? area starts here, not defined and not fixed
;-----------------------------------------------------------------------------.data?
handleWindow
hdc
pixfmtindex
hglrc
timerevent1

dd
dd
dd
dd
dd

?
?
?
?
?

;handle, main window


;handle device context
;pixel format index
;handle OpenGL rendering context
;handle high resolution timer

align 4
; - WndClassEx Structure ( API=RegisterClassExA ) cbSize
dd ?
;size in bytes of this structure
style
dd ?
;window style
lpfnWndProc
dd ?
;address of user proc function
cbclsExtra
dd ?
;extra bytes to allocate set to 0
cbWndExtra
dd ?
;extra bytes class directive, rc file
hInstance
dd ?
;program handle(API=GetModuleHandleA)
hIcon
dd ?
;handle of icon (API=LoadIconA)
hcursor
dd ?
;handle of cursor (API=LoadCursor)
hbrBackground
dd ?
;background color, 0=transparent
lpszMenuName
dd ?
;name of menu class in resource file
lpszClassName
dd ?
;name of windows this window class
hIconSm
dd ?
;iconhandle 0=search in resource file
align 4
; - Msg Structure ( API=GetMessageA ) - member POINT = POINT structure
Page 4

hWnd
message
wParam
lParam
time
xpt
ypt

dd
dd
dd
dd
dd
dd
dd

?
?
?
?
?
?
?

td_win32asm_410.asm
;handle of window who receives message
;the message number
;extra info about the message
;extra info about the message
;time the message was posted
;cursor x-position, POINT struc
;cursor x-position, POINT struc

align 4
; - PIXELFORMATDESCRIPTOR Structure ( API=ChoosePixelFormat ) pfd_nSize
dw ?
;size of this data structure
pfd_nVersion
dw ?
;version, should be set to 1
pfd_dwFlags
dd ?
;bit flags, properties pixel buffer
pfd_iPixelType
db ?
;specifies the type of pixel data
pfd_cColorBits
db ?
;color bitplanes each color buffer
pfd_cRedBits
db ?
;red bitplanes each RGBA color buffer
pfd_cRedShift
db ?
;shift count for red bitplanes
pfd_cGreenBits
db ?
;green bitplanes each RGBA color buffer
pfd_cGreenShift
db ?
;shift count for green bitplanes
pfd_cBlueBits
db ?
;blue bitplanes each RGBA color buffer
pfd_cBlueShift
db ?
;shift count for blue bitplanes
pfd_cAlphaBits
db ?
;alpha bitplanes are not supported
pfd_cAlphaShift
db ?
;alpha bitplanes are not supported
pfd_cAccumBits
db ?
;bitplanes in the accumulation buffer
pfd_cAccumRedBits
db ?
;red bitplanes in accumulation buffer
pfd_cAccumGreenBits
db ?
;green bitplanes in accumulation buffer
pfd_cAccumBlueBits
db ?
;blue bitplanes in accumulation buffer
pfd_cAccumAlphaBits
db ?
;alpha bitplanes in accumulation buffer
pfd_cDepthBits
db ?
;depth of the depth (z-axis) buffer
pfd_cStencilBits
db ?
;depth of the stencil buffer
pfd_cAuxBuffers
db ?
;auxiliary buffers are not supported
pfd_iLayerType
db ?
;ignored
pfd_bReserved
db ?
;number of overlay and underlay planes
pfd_dwLayerMask
dd ?
;ignored
pfd_dwVisibleMask
dd ?
;transparent color/index underlay plane
pfd_dwDamageMask
dd ?
;ignored
align 4
; - RECT Structure ( API=GetClientRect ) rc_left
dd ?
;x, upper-left corner of the rectangle
rc_top
dd ?
;y, upper-left corner of the rectangle
rc_right
dd ?
;x, lower-right corner of the rectangle
rc_bottom
dd ?
;y, lower-right corner of the rectangle
align 4
; - TIMECAPS Structure ( API=timeGetDevCaps ) wPeriodMin
dd ?
;TIMER minimum supported resolution
wPeriodMax
dd ?
;TIMER maximum supported resolution
;==============================================================================
; .CODE = our code area starts here
Main = label of our program code
;-----------------------------------------------------------------------------.Code
Page 5

td_win32asm_410.asm
Main:
;==============================================================================
; Always get your program ID first (API=GetModuleHandleA)
;-----------------------------------------------------------------------------push
0h
;lpModuleHandle, 0=get program handle
call
GetModuleHandleA
;- API Function mov
hInstance,eax
;return value in eax=handle of program
;==============================================================================
; The GetCurrentThread function returns a pseudohandle for the current thread.
;-----------------------------------------------------------------------------call
GetCurrentThread
;- API Function ;==============================================================================
; SetThreadPriority function sets the priority value for the specified thread.
;-----------------------------------------------------------------------------push
2h
;nPriority, thread priority level
;THREAD_PRIORITY_HIGHEST = 2h
push
eax
;hThread, handle to the thread
call
SetThreadPriority
;- API Function cmp
eax,0h
;ERROR ?
je
ExitPrg
;
;==============================================================================
; Init the Floating Point Unit.
;-----------------------------------------------------------------------------finit
;init FPU
;==============================================================================
; The API function "RegisterClassExA" registers a window class.
; This API needs a "WNDCLASSEX" structure so we fill it with correct values.
;-----------------------------------------------------------------------------mov
cbSize,30h
;size in bytes of WNDCLASSEX structure
mov
style,3h
;window style
mov
lpfnWndProc,OFFSET WP1
;address of user lpfnWndProc function
mov
cbclsExtra,0h
;extra bytes to allocate set to 0
mov
cbWndExtra,0h
;class directive in rc file
mov
hbrBackground,2h
;background,1=background(parameter+1)
mov
lpszMenuName,OFFSET MenuName
;menu name in resource file,0=no menu
mov
lpszClassName,OFFSET ClassName ;name of windows class
mov
hIconSm,0h
;iconhandle 0=search in rc file
;-----------------------------------------------------------------------------; API "LoadIconA" loads an icon defined in the resource file and stores the
; handle in the "WNDCLASSEX" structure
;-----------------------------------------------------------------------------push
OFFSET IconName
;icon-string or icon resource id
push
hInstance
;our program handle
call
LoadIconA
;- API Function mov
hIcon,eax
;store handle of newly loaded icon
;-----------------------------------------------------------------------------; API "LoadCursorA" loads a default system cursor, in this case we must set
; hInstance to 0 and lpCursorName to a default system cursor value, here 32512
Page 6

td_win32asm_410.asm
; Then we store the cursor handle in the "WNDCLASSEX" structure
;-----------------------------------------------------------------------------push
32512
;lpCursorName, default value in dezimal
push
0h
;hInstance, 0=default system cursor
call
LoadCursorA
;- API Function mov
hcursor,eax
;store handle of the cursor
;-----------------------------------------------------------------------------; Now, after filled the "WNDCLASSEX" structure we call API "RegisterClassEx"
;-----------------------------------------------------------------------------push
OFFSET cbSize
;pointer to WNDCLASSEX structure
call
RegisterClassExA
;- API Function ;==============================================================================
; API "CreateWindowExA" creates an overlapped, pop-up, or child window with an
; extended style. The return value in EAX is the handle of the new window.
; This API sends a WM_CREATE message to the window procedure (WP1).
;-----------------------------------------------------------------------------push
0h
;lpParam, extra pointer data 0=no data
push
hInstance
;hInstance, handle of our program
push
0h
;hMenu, handle window menu 0=class menu
push
0h
;hWndParent, handle parent window 0=no
push
00000158h
;intnHeight, window height pixel
push
00000140h
;intnWidth, window width pixel
push
00000010h
;inty, vertical position window
push
00000010h
;intx, horizontal position window
push
04CA0000h
;dwStyle, look into WIN32.HLP
push
OFFSET WindowName
;lpWindowName, pointer to window name
push
OFFSET ClassName
;lpClassName, pointer to class name
push
0300h
;dwExStyle, extra window style 0=no
call
CreateWindowExA
;- API Function mov
hWnd,eax
;hwnd,return value=handle of window
;==============================================================================
; API "ShowWindow" function sets the specified window's show state.
;-----------------------------------------------------------------------------push
1h
;nCmdShow, show state 1=SW_SHOWNORMAL
push
hWnd
;hwnd, handle of window
call
ShowWindow
;- API Function ;==============================================================================
; API "UpdateWindow" updates the area of the specified window by sending a
; WM_PAINT message to the window if the window's update region is not empty.
;-----------------------------------------------------------------------------push
hWnd
;hwnd, handle of window
call
UpdateWindow
;- API Function LoopGetMessage:
;==============================================================================
; API "GetMessageA" retrieves a message + places it in the specified structure.
;-----------------------------------------------------------------------------push
0h
;wMsgFilterMax, highest message value
push
0h
;wMsgFilterMin, lowest message value
push
0h
;hWnd, handle of window who gets msg.
Page 7

push
call
cmp
je

OFFSET hWnd
GetMessageA
eax,0h
ExitPrg

td_win32asm_410.asm
;lpMsg, pointer to MSG structure
;- API Function ;check if return value=0 (exit)
;if return value is 0 goto LABEL

;==============================================================================
; API "TranslateMessage" translates virtual-key messages in character messages
;-----------------------------------------------------------------------------push
OFFSET hWnd
;lpMSG, pointer to msg structure
call
TranslateMessage
;- API Function - keyboard code
;==============================================================================
; API "DispatchMessageA" function dispatches a message to a window procedure.
;-----------------------------------------------------------------------------push
OFFSET hWnd
;lpMSG, pointer to msg structure
call
DispatchMessageA
;- API Function jmp
LoopGetMessage
;check for message again, goto LABEL
ExitPrg:
;==============================================================================
; Next we terminate our program (API=ExitProcess)
;-----------------------------------------------------------------------------push
hInstance
;push our programm handle to exit
call
ExitProcess
;- API Function ;##############################################################################
; The Window Procedure (API=RegisterClassExA) for this registered window.
;-----------------------------------------------------------------------------WP1:
push
ebp
;create stack frame
mov
ebp,esp
;
pushad
;push all register to the stack
mov
eax,WP1_uMsg
;move the message number to eax
;==============================================================================
; WM_CREATE (value=01h) message received ?
;-----------------------------------------------------------------------------WP1_uMsg_01h:
cmp
eax,1h
;check if WM_CREATE message recieved
jne
WP1_uMsg_02h
;if not goto LABEL
mov
eax,WP1_hWnd
;store main window handle
mov
handleWindow,eax
;
;-----------------------------------------------------------------------------; The GetDC function retrieves a handle of a display device context (DC)
; for the client area of the specified window.
;-----------------------------------------------------------------------------push
WP1_hWnd
;hWnd, handle owner window
call
GetDC
;- API Function mov
hdc,eax
;handle device context
;-----------------------------------------------------------------------------; The ChoosePixelFormat function attempts to match an appropriate pixel format
; supported by a device context to a given pixel format specification.
;-----------------------------------------------------------------------------Page 8

td_win32asm_410.asm
;size of structure
;version of this data structure, set 1
;PFD_SUPPORT_OPENGL = 00000020h
;PFD_DOUBLEBUFFER
= 00000001h
;PFD_DRAW_TO_WINDOW = 00000004h
mov
pfd_iPixelType,0h
;PFD_TYPE_RGBA
=
0h
mov
pfd_dwLayerMask,0h
;PFD_MAIN_PLANE
=
0h
mov
pfd_cColorBits,10h
;# color bitplanes in each colorbuffer
mov
pfd_cDepthBits,10h
;?
mov
pfd_cAlphaBits,0h
;currently not supported
mov
pfd_cAccumBits,0h
;# bitplanes in accumulation buffer
mov
pfd_cStencilBits,0h
;depth of the stencil buffer
mov
pfd_cAuxBuffers,0h
;auxiliary buffers are not supported
push
OFFSET pfd_nSize
;PIXELFORMATDESCRIPTOR structure
push
hdc
;handle device context
call
ChoosePixelFormat
;- API Function mov
pixfmtindex,eax
;return value = pixel format index
;-----------------------------------------------------------------------------; The SetPixelFormat function sets the pixel format of the specified device
; context to the format specified by the iPixelFormat index.
;-----------------------------------------------------------------------------push
OFFSET pfd_nSize
;PIXELFORMATDESCRIPTOR structure
push
pixfmtindex
;pixel format index
push
hdc
;device context whose pixel format set
call
SetPixelFormat
;- API Function ;-----------------------------------------------------------------------------; The wglCreateContext function creates a new OpenGL rendering context, which
; is suitable for drawing on the device referenced by hdc.
; The rendering context has the same pixel format as the device context.
;-----------------------------------------------------------------------------push
hdc
;handle device context
call
wglCreateContext
;- API Function mov
hglrc,eax
;handle OpenGL rendering context
;-----------------------------------------------------------------------------; The wglMakeCurrent function makes a specified OpenGL rendering context the
; calling thread's current rendering context.
;-----------------------------------------------------------------------------push
hglrc
;handle OpenGL rendering context
push
hdc
;handle device context
call
wglMakeCurrent
;- API Function ;-----------------------------------------------------------------------------; The glMatrixMode function specifies which matrix is the current matrix.
;-----------------------------------------------------------------------------push
1701h
;GL_PROJECTION = 00001701h
call
glMatrixMode
;- API Function ;-----------------------------------------------------------------------------; The glFrustum function multiplies the current matrix by a perspective matrix.
;-----------------------------------------------------------------------------mov
ebx,OFFSET _glFrustum_zfar
;distances far depth clipping planes
push
[ebx+4]
push
[ebx]
mov
ebx,OFFSET _glFrustum_znear
;distances near depth clipping planes
push
[ebx+4]
Page 9
mov
mov
mov

pfd_nSize,28h
pfd_nVersion,1h
pfd_dwFlags,25h

td_win32asm_410.asm
push
[ebx]
mov
ebx,OFFSET _glFrustum_top
;coord. top horizontal clipping planes
push
[ebx+4]
push
[ebx]
mov
ebx,OFFSET _glFrustum_bottom
;coord. bottom horiz. clipping planes
push
[ebx+4]
push
[ebx]
mov
ebx,OFFSET _glFrustum_right
;coord. right vertical clipping planes
push
[ebx+4]
push
[ebx]
mov
ebx,OFFSET _glFrustum_left
;coord. left vertical clipping planes
push
[ebx+4]
push
[ebx]
call
glFrustum
;- API Function ;-----------------------------------------------------------------------------; The glMatrixMode function specifies which matrix is the current matrix.
;-----------------------------------------------------------------------------push
1700h
;GL_MODELVIEW = 000001700h
call
glMatrixMode
;- API Function ;-----------------------------------------------------------------------------; The glTranslatef function multiply the current matrix by a translation matrix
;-----------------------------------------------------------------------------push
transVector_z
;z, coordinates translation vector
push
0h
;y, coordinates translation vector
push
0h
;x, coordinates translation vector
call
glTranslatef
;- API Function ;-----------------------------------------------------------------------------; The glShadeModel function selects flat or smooth shading.
;-----------------------------------------------------------------------------push
1D01h
;GL_SMOOTH = 000001d01h
call
glShadeModel
;- API Function ;-----------------------------------------------------------------------------; The glEnable and glDisable functions enable or disable OpenGL capabilities.
;-----------------------------------------------------------------------------push
0B71h
;GL_DEPTH_TEST = 000000b71h
call
glEnable
;- API Function push
0B44h
;GL_CULL_FACE = 000000b44h
call
glEnable
;- API Function ;-----------------------------------------------------------------------------; The GetClientRect function retrieves coordinates of a window's client area.
;-----------------------------------------------------------------------------push
OFFSET rc_left
;lpRect, pointer to RECT structure
push
WP1_hWnd
;hWnd, handle owner window
call
GetClientRect
;- API Function ;-----------------------------------------------------------------------------; The glViewport function sets the viewport.
; If you change the x and y values the object will move on the screen !
;-----------------------------------------------------------------------------push
rc_bottom
;height of the viewport
push
rc_right
;width of the viewport
push
0h
;y, lower-left corner viewport rect.
push
0h
;x, the default in pixel is (0,0)
call
glViewport
;- API Function Page 10

td_win32asm_410.asm
;-----------------------------------------------------------------------------; timeGetDevCaps function queries the timer device to determine its resolution.
; Returned values in the TIMECAPS struc are different from system to system.
;-----------------------------------------------------------------------------push
8h
;cbtc, size in bytes TIMECAPS structure
push
OFFSET wPeriodMin
;ptc, address of a TIMECAPS structure
call
timeGetDevCaps
;- API Function ;-----------------------------------------------------------------------------; The timeSetEvent function starts a specified timer event. After activated, it
; calls the specified callback function. It runs in its own thread !
;-----------------------------------------------------------------------------push
1h
;fuEvent, timer type, TIME_PERIODIC=1h
push
0h
;dwUser, user-supplied callback data
push
OFFSET TP1
;lpTimeProc, address callback function
push
wPeriodMin
;uResolution, resolution in ms
mov
eax,wPeriodMin
add
eax,speed
push
eax
;uDelay, event delay in milliseconds
call
timeSetEvent
;- API Function mov
timerevent1,eax
;
jmp
WP1_return
;
;==============================================================================
; WM_DESTROY (value=02h) message received ?
;-----------------------------------------------------------------------------WP1_uMsg_02h:
cmp
eax,2h
;check if value=2h (WM_DESTROY)
jne
WP1_uMsg_0Fh
;if not 2h go to LABEL
;-----------------------------------------------------------------------------; The timeKillEvent function cancels a specified timer event.
;-----------------------------------------------------------------------------push
timerevent1
;uTimerID, ID of timer event to cancel
call
timeKillEvent
;- API Function ;-----------------------------------------------------------------------------; The wglMakeCurrent function makes a specified OpenGL rendering context the
; calling thread's current rendering context.
;-----------------------------------------------------------------------------push
0h
;hglrc, release = 0h
push
0h
;hdc, ignored if hglrc = 0h
call
wglMakeCurrent
;- API Function ;-----------------------------------------------------------------------------; The wglDeleteContext function deletes a specified OpenGL rendering context.
;-----------------------------------------------------------------------------push
hglrc
;hglrc, handle OpenGL rendering context
call
wglDeleteContext
;- API Function ;-----------------------------------------------------------------------------; The ReleaseDC function releases a device context (DC)
;-----------------------------------------------------------------------------push
hdc
;hdc, handle of device context
push
WP1_hWnd
;hwnd, handle of window
call
ReleaseDC
;- API Function ;-----------------------------------------------------------------------------; API "PostQuitMessage" indicates to Windows a request to terminate
Page 11

td_win32asm_410.asm
;-----------------------------------------------------------------------------push
0h
;nExitCode, exit code=wParam
call
PostQuitMessage
;- API Function popad
;pop all register back from stack
xor
eax,eax
;set eax to 0 to exit our program
mov
esp,ebp
;delete stack frame
pop
ebp
;
ret
10h
;return and clear stack
;==============================================================================
; WM_PAINT (value=0Fh) message, used to repaint the window area
;-----------------------------------------------------------------------------WP1_uMsg_0Fh:
cmp
eax,0Fh
;check if WM_PAINT message recieved
jne
WP1_uMsg_111h
;if not goto label
;-----------------------------------------------------------------------------; The glPushMatrix functions push the current matrix stack.
;-----------------------------------------------------------------------------call
glPushMatrix
;- API Function ;-----------------------------------------------------------------------------; The glMatrixMode function specifies which matrix is the current matrix.
;-----------------------------------------------------------------------------push
1700h
;GL_MODELVIEW = 000001700h
call
glMatrixMode
;- API Function ;-----------------------------------------------------------------------------; The glRotatef functions multiply the current matrix by a rotation matrix.
;-----------------------------------------------------------------------------push
rotate_z1
;z, coordinates of a vector
push
rotate_y1
;y, coordinates of a vector
push
rotate_x1
;x, coordinates of a vector
push
rotateAngel
;angle of rotation in degrees
call
glRotatef
;- API Function fld
rotateAngel
;load real value in TOS
fadd
rotateAdd
;add two real values
fstp
rotateAngel
;store real value and remove from TOS
;-----------------------------------------------------------------------------; The glRotatef functions multiply the current matrix by a rotation matrix.
;-----------------------------------------------------------------------------push
rotate_z2
;z, coordinates of a vector
push
rotate_y2
;y, coordinates of a vector
push
rotate_x2
;x, coordinates of a vector
push
rotateAngel
;angle of rotation in degrees
call
glRotatef
;- API Function ;-----------------------------------------------------------------------------; The glClear function clears buffers within the viewport.
;-----------------------------------------------------------------------------push
4100h
;GL_COLOR_BUFFER_BIT = 00004000h
;GL_DEPTH_BUFFER_BIT = 00000100h
call
glClear
;- API Function ;-----------------------------------------------------------------------------; The glEnable and glDisable functions enable or disable OpenGL capabilities.
;-----------------------------------------------------------------------------push
0B50h
;GL_LIGHTING = 00000B50h
Page 12

td_win32asm_410.asm
call
glDisable
;- API Function ;-----------------------------------------------------------------------------; The glBegin and glEnd functions delimit the vertices of a (group) primitive
;-----------------------------------------------------------------------------push
gl_Mode
;GL_QUADS = 00000007h
call
glBegin
;- API Function ;-----------------------------------------------------------------------------; API "glNormal3f" sets the current normal vector.
;-----------------------------------------------------------------------------push
normalArea1
;z, coordinates new current normal
push
0h
;y, coordinates new current normal
push
0h
;x, coordinates new current normal
call
glNormal3f
;- API Function mov
eax,OFFSET colorArea1
mov
pointercolor,eax
mov
eax,OFFSET vertexArea1
mov
pointervertex,eax
call
My_PaintArea
; - Subroutine ;-----------------------------------------------------------------------------; API "glNormal3f" sets the current normal vector.
;-----------------------------------------------------------------------------push
normalArea2
push
0h
push
0h
call
glNormal3f
;- API Function mov
eax,OFFSET colorArea2
mov
pointercolor,eax
mov
eax,OFFSET vertexArea2
mov
pointervertex,eax
call
My_PaintArea
; - Subroutine ;-----------------------------------------------------------------------------; API "glNormal3f" sets the current normal vector.
;-----------------------------------------------------------------------------push
0h
push
normalArea3
push
0h
call
glNormal3f
;- API Function mov
eax,OFFSET colorArea3
mov
pointercolor,eax
mov
eax,OFFSET vertexArea3
mov
pointervertex,eax
call
My_PaintArea
; - Subroutine ;-----------------------------------------------------------------------------; API "glNormal3f" sets the current normal vector.
;-----------------------------------------------------------------------------push
0h
push
normalArea4
push
0h
call
glNormal3f
;- API Function mov
eax,OFFSET colorArea4
mov
pointercolor,eax
mov
eax,OFFSET vertexArea4
mov
pointervertex,eax
Page 13

td_win32asm_410.asm
call
My_PaintArea
; - Subroutine ;-----------------------------------------------------------------------------; API "glNormal3f" sets the current normal vector.
;-----------------------------------------------------------------------------push
0h
push
0h
push
normalArea5
call
glNormal3f
;- API Function mov
eax,OFFSET colorArea5
mov
pointercolor,eax
mov
eax,OFFSET vertexArea5
mov
pointervertex,eax
call
My_PaintArea
; - Subroutine ;-----------------------------------------------------------------------------; API "glNormal3f" sets the current normal vector.
;-----------------------------------------------------------------------------push
0h
push
0h
push
normalArea6
call
glNormal3f
;- API Function mov
eax,OFFSET colorArea6
mov
pointercolor,eax
mov
eax,OFFSET vertexArea6
mov
pointervertex,eax
call
My_PaintArea
; - Subroutine ;-----------------------------------------------------------------------------; The glEnd functions delimit the vertices of a primitive or a group of like.
;-----------------------------------------------------------------------------call
glEnd
;- API Function ;-----------------------------------------------------------------------------; The glPopMatrix functions pop the current matrix stack.
;-----------------------------------------------------------------------------call
glPopMatrix
;- API Function ;-----------------------------------------------------------------------------; The glFinish function blocks until all OpenGL execution is complete.
;-----------------------------------------------------------------------------call
glFinish
;- API Function ;-----------------------------------------------------------------------------; The SwapBuffers function exchanges the front and back buffers if the current
; pixel format for the window referenced by the specified device context
; includes a back buffer.
;-----------------------------------------------------------------------------push
hdc
;handle device context
call
SwapBuffers
;- API Function mov
WM_PAINT_proceed,1h
;set flag, WM_PAINT is proceed !
jmp
WP1_return
;
;==============================================================================
; WM_COMMAND (value=111h) message recieved ?
;-----------------------------------------------------------------------------WP1_uMsg_111h:
cmp
eax,111h
;check if WM_COMMAND message recieved
jne
WP1_return
;if not goto label
Page 14

td_win32asm_410.asm
WP1_wParam_01h:
;-----------------------------------------------------------------------------; Check extra message info menu control, "01"-"09" item in menu bar clicked
; The menu bar items ID here are also used to set the gl_Mode !!!
;-----------------------------------------------------------------------------mov
eax,WP1_wParam
;extra info about the message in ax
cmp
ax,9h
;
ja
WP1_wParam_20h
;
cwde
;convert word ax into doubleword eax
mov
gl_Mode,eax
;set gl_Mode
jmp
WP1_return
;
;-----------------------------------------------------------------------------; Check extra message menu control, "speed+" item ID 20h in menu bar clicked
;-----------------------------------------------------------------------------WP1_wParam_20h:
cmp
ax,20h
jne
WP1_wParam_21h
cmp
speed,30h
jae
WP1_return
inc
speed
inc
speed
call
My_HighTimer
; - Subroutine jmp
WP1_return
;-----------------------------------------------------------------------------; Check extra message menu control, "speed-" item ID 21h in menu bar clicked
;-----------------------------------------------------------------------------WP1_wParam_21h:
cmp
ax,21h
jne
WP1_wParam_22h
cmp
speed,02h
jbe
WP1_return
dec
speed
dec
speed
call
My_HighTimer
; - Subroutine jmp
WP1_return
;-----------------------------------------------------------------------------; Check extra message menu control, "scale-" item ID 22h in menu bar clicked
;-----------------------------------------------------------------------------WP1_wParam_22h:
cmp
ax,22h
jne
WP1_wParam_23h
cmp
Scale_counter,0h
je
WP1_return
dec
Scale_counter
;-----------------------------------------------------------------------------; The glScalef function multiply the current matrix by a general scaling matrix
;-----------------------------------------------------------------------------push
scale_Out
;z, coordinates translation vector
push
scale_Out
;y, coordinates translation vector
push
scale_Out
;x, coordinates translation vector
call
glScalef
;- API Function Page 15

td_win32asm_410.asm
jmp WP1_return
;-----------------------------------------------------------------------------; Check extra message menu control, "scale+" item ID 23h in menu bar clicked
;-----------------------------------------------------------------------------WP1_wParam_23h:
cmp
ax,23h
jne
WP1_return
cmp
Scale_counter,10h
je
WP1_return
inc
Scale_counter
;-----------------------------------------------------------------------------; The glScalef function multiply the current matrix by a general scaling matrix
;-----------------------------------------------------------------------------push
scale_In
;z, coordinates translation vector
push
scale_In
;y, coordinates translation vector
push
scale_In
;x, coordinates translation vector
call
glScalef
;- API Function jmp
WP1_return
;==============================================================================
; API "DefWindowProcA" calls the window procedure to provide default processing
; for any window messages that an application does not process.
; This function ensures that every message is processed.
; It is called with the same parameters received by the window procedure.
;-----------------------------------------------------------------------------WP1_return:
popad
;pop all register from stack
push
WP1_lParam
;extra info about the message
push
WP1_wParam
;extra info about the message
push
WP1_uMsg
;the message number
push
WP1_hWnd
;handle of window who receives message
call
DefWindowProcA
;- API Function mov
esp,ebp
;delete stack frame
pop
ebp
;
ret
10h
;return and clear stack
;##############################################################################
;##############################################################################
; HIGH RESOLUTION timer procedure, refer to Mmedia.hlp !
;-----------------------------------------------------------------------------TP1:
pushad
;push all register to the stack
cmp
WM_PAINT_proceed,1h
;check if last WM_PAINT msg. is proceed
jne
TP1_return
;if not 1h do not post a message
mov
WM_PAINT_proceed,0h
;reset flag
;-----------------------------------------------------------------------------; API "PostMessageA" post (!) a message to the Window Procedure WP1 !
;-----------------------------------------------------------------------------push
0h
;lParam, second message parameter
push
0h
;wParam, first message parameter
push
0Fh
;uMsg, message to post ( WM_PAINT )
Page 16

push
call

handleWindow
PostMessageA

td_win32asm_410.asm
;hwnd, handle of destination window
;- API Function -

TP1_return:
popad
;pop all register back from stack
ret
14h
;return and clear stack (14h !!!)
;##############################################################################
;******************************************************************************
; My own subroutine(s) for a compacter code resist here ...
;-----------------------------------------------------------------------------My_HighTimer:
;-----------------------------------------------------------------------------; The timeKillEvent function cancels a specified timer event.
;-----------------------------------------------------------------------------push
timerevent1
;uTimerID, ID of timer event to cancel
call
timeKillEvent
;- API Function ;-----------------------------------------------------------------------------; The timeSetEvent function starts a specified timer event. It runs in its own
; thread. After activated, it calls the specified callback function.
;-----------------------------------------------------------------------------push
1h
;fuEvent, timer type, TIME_PERIODIC=1h
push
0h
;dwUser, user-supplied callback data
push
OFFSET TP1
;lpTimeProc, address callback function
push
wPeriodMin
;uResolution, resolution in ms
mov
eax,wPeriodMin
add
eax,speed
push
eax
;uDelay, event delay in milliseconds
call
timeSetEvent
;- API Function mov
timerevent1,eax
;handle timerevent
ret
;
My_PaintArea:
;-----------------------------------------------------------------------------; API "glColor3f" set the current color. You can update the color at any time.
; API "glVertex3f" specify a vertex. Call ONLY inside of a glBegin/glEnd pair !
; Current color, normal and texture coordinates are associated with the vertex.
;-----------------------------------------------------------------------------mov
ebx,pointercolor
;pointer ARRAY, RGB color values (BGR)
push
[ebx]
push
[ebx+4]
push
[ebx+8]
call
glColor3f
;- API Function mov
ebx,pointervertex
;pointer ARRAY, z y x vertex coordinat.
push
[ebx]
push
[ebx+4]
push
[ebx+8]
call
glVertex3f
;- API Function mov
push
push
push

ebx,pointercolor
[ebx+12]
[ebx+16]
[ebx+20]
Page 17

call
mov
push
push
push
call

glColor3f
ebx,pointervertex
[ebx+12]
[ebx+16]
[ebx+20]
glVertex3f

mov
push
push
push
call
mov
push
push
push
call

ebx,pointercolor
[ebx+24]
[ebx+28]
[ebx+32]
glColor3f
ebx,pointervertex
[ebx+24]
[ebx+28]
[ebx+32]
glVertex3f

td_win32asm_410.asm
;- API Function -

;- API Function -

;- API Function -

;- API Function -

mov
ebx,pointercolor
push
[ebx+36]
push
[ebx+40]
push
[ebx+44]
call
glColor3f
;- API Function mov
ebx,pointervertex
push
[ebx+36]
push
[ebx+40]
push
[ebx+44]
call
glVertex3f
;- API Function ret
;go out of here
;******************************************************************************
;==============================================================================
; end Main = end of our program code
;-----------------------------------------------------------------------------end Main
;end of our program code, entry point
;==============================================================================
; To create the exe file use this commands with your Microsoft Assembler/Linker
;-----------------------------------------------------------------------------; ml.exe /c /coff td_win32asm_410.asm
;asm command
; rc.exe /v rsrc.rc
;rc command
; cvtres.exe /machine:ix86 rsrc.res
; link.exe /subsystem:windows td_win32asm_410.obj rsrc.obj
;link command
;==============================================================================

Page 18

You might also like