Win32 App
DlgOpenGL
OpenGL in a box
-
Pegasus, 2oo4
e-mail: pegasus@anticrack.de
web: http://www.anticrack.de
[*BEGINPRO*]
[*BEGINTXT*]
DlgOpenGL.asm

include DlgOpenGL.inc                                    ; needed header

.code
start:                                                   ; entry point
  invoke  GetModuleHandle,NULL                           ; get a module handle
  mov     hInstance,eax                                  ; and store it
  invoke  InitCommonControls                             ; init treeview usage
  invoke  DialogBoxParam,hInstance,IDD_DIALOG,NULL,offset DlgProc,NULL
  invoke  ExitProcess,NULL                               ; cleanup and kill process
DlgProc      proc hWin:HWND,uMsg:UINT,wParam:WPARAM,lParam:LPARAM
  .if     uMsg==WM_INITDIALOG                            ; WM_INITDIALOG
    invoke  ShowWindow,hWin,SW_MINIMIZE                  ; pop up effect
    invoke  LoadIcon,hInstance,IDI_ICON                  ; set application icon
    mov     hIcon,eax                                    ; and store it's handle
    invoke  SendMessage,hWin,WM_SETICON,1,hIcon          ; show the icon
    invoke  SendMessage,hWin,WM_SETTEXT,0,offset szAppName ; show application name
    invoke  ShowWindow,hWin,SW_SHOWNORMAL                ; show the final dialog 
    invoke  myOGL_InitGL,hWin
    invoke  SetTimer,hWin,1,10,NULL                      ; setup a timer

  .elseif uMsg==WM_TIMER                                 ; WM_TIMER
    invoke  myOGL_DrawScene                              ; redraw openGL scene

  .elseif uMsg==WM_CLOSE                                 ; WM_CLOSE
    invoke  ShowWindow,hWin,SW_MINIMIZE                  ; minimize the window to taskbar
    invoke  KillTimer,hWin,1                             ; delete timer
    invoke  myOGL_KillGL                                 ; delete openGL crap
    invoke  ReleaseDC,hWin,hDC                           ; release device context
    invoke  EndDialog,hWin,0                             ; end the dialog

  .elseif uMsg==WM_COMMAND                               ; WM_COMMAND
    nop                                                  ; do nothing

  .else
    mov     eax,FALSE                                    ; delete unhandeled message
    ret                                                  ; and continue
  .endif
  mov    eax,TRUE                                        ; message handled with success
  ret                                                    ; and continue
DlgProc      endp			

myOGL_InitGL proc theWindowHandle:DWORD
  LOCAL    pfd:PIXELFORMATDESCRIPTOR                     ; ...
  LOCAL    PixelFormat:DWORD                             ; correct pixelformat for static window
  pushad                                                 ; store all registers
  mov     pfd.nSize,sizeof PIXELFORMATDESCRIPTOR         ; setup pixelformatdescriptor struct
  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.dwLayerMask, PFD_MAIN_PLANE
  invoke  GetDlgItem,theWindowHandle,IDI_OPENGL          ; the static item which shows openGL
  mov     hOGLWindow,eax                                 ; store it's handle
  invoke  GetDC,hOGLWindow                               ; get the device context
  mov     hDC,eax                                        ; and store it
  invoke  GetClientRect,hOGLWindow,addr staticRect       ; we need the dimensions of the static
  invoke  ChoosePixelFormat, hDC, ADDR pfd               ; and the correct pixelformat
  mov     PixelFormat,eax                                ; thats the correct one
  invoke  SetPixelFormat, hDC, PixelFormat, ADDR pfd     ; so set it!
  invoke  wglCreateContext, hDC                          ; create rendering context
  mov     hRC, eax                                       ; store the handle
  invoke  wglMakeCurrent, hDC, hRC                       ; it's our OpenGL context
  invoke  glViewport, 0, 0, staticRect.right, staticRect.bottom  ;reset viewport
  invoke  glMatrixMode, GL_PROJECTION                    ; select projection matrix
  invoke  glLoadIdentity                                 ; reset it
  push    40590000h                                      ; 100.0f
  push    0                                              ; double
  push    3FB99999h                                      ; 0.1f
  push    9999999Ah                                      ; double
  fild    staticRect.right
  fidiv   staticRect.bottom                              ; dividing width by height and
  sub     esp,8                                          ; pushing it on the
  fstp    qword ptr [esp]                                ; stack as a double
  push    40468000h                                      ; 45.0f
  push    0                                              ; double
  call    gluPerspective
  invoke  glMatrixMode, GL_MODELVIEW                     ; select modelview matrix
  invoke  glLoadIdentity                                 ; reset it
  invoke  glShadeModel,GL_SMOOTH                         ; Enable Smooth Shading
  invoke  glClearColor,0,0,0,0                           ; Black Background
  invoke  glClearDepth,0,3FF00000h                       ; 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; Really Nice Perspective Calculations
  popad                                                  ; retore all registers
  ret                                                    ; return to caller
myOGL_InitGL endp

myOGL_DrawScene proc
  pushad                                                 ; store all registers
  invoke  glClear,GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT ; Clear Screen And Depth Buffer
  invoke  glLoadIdentity                                 ; Reset The Current Modelview Matrix

  invoke  SwapBuffers, hDC                               ; show the result
  popad                                                  ; restore all registers
  ret                                                    ; return to caller
myOGL_DrawScene endp

myOGL_KillGL proc
  pushad
  invoke  wglMakeCurrent,NULL,NULL
  invoke  wglDeleteContext,hRC
  popad
  ret
myOGL_KillGL endp
end start                                                ; end of application
[*ENDTXT*]
[*BEGINTXT*]
DlgOpenGL.inc

.386                                                     ; minimum processor
.model flat,stdcall                                      ; win32 application
option casemap:none                                      ; case sensitive

include windows.inc                                      ; win32 structures etc.

incboth macro incl                                       ; macro for lazy coders
  include    incl.inc
  includelib incl.lib
endm

incboth kernel32                                         ; functions from kernel32
incboth user32                                           ; functions from user32
incboth comctl32                                         ; functions from comctl32
incboth gdi32                                            ; functions from gdi32
incboth opengl32                                         ; functions from opengl32
incboth glu32                                            ; functions from glu32


; ** function prototypes
DlgProc           PROTO :HWND,:UINT,:WPARAM,:LPARAM      ; main dialog procedure
myOGL_InitGL      PROTO :DWORD                           ; setup openGL
myOGL_DrawScene   PROTO                                  ; update the openGL scene
myOGL_KillGL      PROTO                                  ; cleanup openGL


; ** uninitialized data
.data?
hInstance            HINSTANCE  ?                        ; application instance
hIcon                HICON      ?                        ; application icon 
hDC                  dd         ?                        ; device context
hRC                  dd         ?                        ; openGL rendering context
hOGLWindow           HWND       ?                        ; openGL window handle
staticRect           RECT       <?>                      ; dimensions of static openGL "window"


; ** initialized data
.data
szAppName            db "OpenGL in a Box - by Pegasus",0 ; dialog caption


; ** constants
.const
IDI_ICON             equ 100                             ; application icon
IDD_DIALOG           equ 1000                            ; dialog resource
IDI_OPENGL           equ 1001                            ; openGL static area
[*ENDTXT*]
[*BEGINTXT*]
DlgOpenGL.rc
#include "Res/mainDlg.rc"
#include "Res/mainIcon.rc"
[*ENDTXT*]
[*BEGINBIN*]
res\main.dlg
6500000001000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
00000000000000004D532053616E732053657269660000000000000000000000
000000000000000008000000F5FFFFFF00000000E90300000000000000000000
0000000000000000BC090A80000000006A040300010000004397410068040900
000000000008CA10000000000A0000000A00000075010000000100004944445F
444C470000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000E8030000494444
5F4449414C4F4700000000000000000000000000000000000000000000000000
00000000006C040300000000009F62E1776A0403000000000000000050000000
0012000000120000004E010000C10000004F70656E474C000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000020000000200000000000000E90300004944495F4F50454E474C00000000
0000000000000000000000000000000000000000000000000000
[*ENDBIN*]
[*ENDPRO*]
[*BEGINTXT*]
res\maindlg.rc
#define IDD_DIALOG 1000
#define IDI_OPENGL 1001
IDD_DIALOG DIALOGEX 6,6,244,142
CAPTION "IDD_DLG"
FONT 8,"MS Sans Serif"
STYLE 0x10CA0800
EXSTYLE 0x00000000
BEGIN
  CONTROL "OpenGL",IDI_OPENGL,"Static",0x50000000,12,11,222,118,0x00000000
END
[*ENDTXT*]
[*BEGINTXT*]
res\mainicon.rc
#define IDI_ICON     100
IDI_ICON             ICON     DISCARDABLE "Res/mainIcon.ico"
[*ENDTXT*]
[*BEGINBIN*]
res\mainicon.ico
[encoded data, 7548 characters]
[*ENDBIN*]
