Win32 App
OpenGLApp
Simple Template for creating OpenGL application
-
Ev!l0iD, 2oo2
e-mail: eviloid@mail.ru
web: http://eviloid.hut.ru
[*BEGINPRO*]
[*BEGINTXT*]
OpenGLApp.Asm
; =========================
; Simple OpenGL Application
; =========================

Include OpenGLApp.Inc

; Implementation ========================================
.Code

; entry point
Start:

  invoke GetModuleHandle, NULL
  mov hInstance, eax

  invoke GetCommandLine
  mov CommandLine, eax

  invoke WinMain, hInstance, NULL, CommandLine, SW_SHOWDEFAULT
  invoke ExitProcess, eax

;========================================================
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
  m2m wc.hInstance, hInstance

  invoke GetStockObject, BLACK_BRUSH
  mov wc.hbrBackground, eax

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

  invoke LoadIcon, hInstance, IDC_ICON1
  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,
                        256, 256, NULL, NULL,
                        hInst, NULL
  mov hwnd,eax

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

  .while !( bQuit )
  ;{
;    invoke GetMessage, addr msg, NULL, 0, 0
    invoke PeekMessage, addr msg, NULL, 0, 0, PM_REMOVE
; handle or dispatch messages
    .if ( eax )
    ;{
      .if ( msg.message == WM_QUIT )
      ;{
        mov bQuit, TRUE
      ;}
      .else
      ;{
        invoke TranslateMessage, addr msg
        invoke DispatchMessage, addr msg
      ;}
      .endif
     ;}
     .else
     ;{

; ...OpenGL animation code goes here...

     ;}
     .endif
  ;}
  .endw

  invoke DisableOpenGL, hwnd

;  mov eax,msg.wParam
;  ret
  return msg.wParam
;}
WinMain EndP

;========================================================
WndProc Proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
;{
  LOCAL Rect:RECT

  .if ( uMsg == WM_DESTROY )
  ;{
  GetOutaHere:
    invoke PostQuitMessage, NULL
  ;}
  .elseif ( uMsg == WM_CREATE )
  ;{

  ;}
  .elseif ( uMsg == WM_SIZE )
  ;{
    invoke  GetClientRect, hWnd, addr Rect
    invoke  glViewport, 0, 0, Rect.right, Rect.bottom
  ;}
  .elseif ( uMsg == WM_KEYDOWN )
  ;{
    .if ( wParam == VK_ESCAPE)
    ;{
      jmp GetOutaHere
    ;}
    .endif
  ;}
  .else
  ;{
    invoke DefWindowProc, hWnd, uMsg, wParam, lParam
    ret
  ;}
  .endif

;  xor eax,eax
;  ret
  return 0
;}
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, 24
  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
  ret
;}
EnableOpenGL EndP

;========================================================
DisableOpenGL Proc hWnd:HWND
;{
  invoke wglMakeCurrent, NULL, NULL
  invoke wglDeleteContext, hRC
  invoke ReleaseDC, hWnd, hDC
  ret
;}
DisableOpenGL EndP

;========================================================
End Start
[*ENDTXT*]
[*BEGINTXT*]
OpenGLApp.Inc
.586
.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 windows.inc
Include user32.inc
Include kernel32.inc
Include gdi32.inc

Include OpenGL\gl.def  ; (C) hardCode 1999-2000
Include OpenGL\glu.def ; http://bizarrecreations.webjump.com

IncludeLib user32.lib
IncludeLib kernel32.lib
IncludeLib opengl32.lib
IncludeLib glu32.lib
IncludeLib gdi32.lib

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

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

ClassName db "OGLMainWinClass", 0
AppName db "OpenGL App", 0

IDC_ICON1 equ 500

; Initialized data ======================================
.Data

; Non-initialized data ==================================
.Data?

hInstance HINSTANCE ?
CommandLine LPSTR ?
hDC HDC ?
hRC HGLRC ?
[*ENDTXT*]
[*BEGINTXT*]
OpenGLApp.Rc
#define IDC_ICON1 500
IDC_ICON1 ICON DISCARDABLE Res\ogl.ico
[*ENDTXT*]
[*ENDPRO*]
[*BEGINBIN*]
Res\ogl.ico
[encoded data, 4476 characters]
[*ENDBIN*]
