AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

OpenGL DllCalls
Goto page Previous  1, 2, 3, 4  Next
 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
Zippo()
Guest





PostPosted: Sun Apr 27, 2008 5:37 am    Post subject: Reply with quote

I'm posting this well before it is ready. It needs a lot of work, but I don't have time ATM to finish it up. Just thought I'd post it to show how to go about loading images etc. It is based off Nehe's tutorial #10 if you want to follow along and tinker with it.

You need the includes listed on the 1st page (GL.ahk and WINDERS.ahk). And save this image to the same directory you will be running the script from:
MUD.bmp

Be sure to rename it MUD.bmp if you need to.

And presto, you have Doom, AHK style:
Code:
;   This script is based off of Nehe's Open GL Tutorial #10, which can be found at
;   http://nehe.gamedev.net


;/////////////////////////////////////////////////////////////////////////////////////////////
#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.   ;//
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.   ;//
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.                    ;//
;/////////////////////////////////////////////////////////////////////////////////////////////

#include WINDERS.ahk
#include GL.ahk

OnExit, Exit

hOpenGL := DllCall("LoadLibrary", Str, "opengl32.dll")
hGlu32  := DllCall("LoadLibrary", Str, "glu32.dll")
hGdi32  := DllCall("LoadLibrary", Str, "gdi32.dll")

hInstance := 0
hWnd := 0
ATOM := 0
hDC := 0
hRC := 0
F1 := 0
active := 1
fullscreen := 1
filter := 0
lpszClassName := "OpenGL"
numtriangles := 0
piover180 := 0.0174532925
;Loop, 3
;  Texture%A_Index% := 0
filter := 1
walkbias := 0
walkbiasangle := 0
lookupdown := 0.0
z := 0.0
tri := 1
vec := 1
Count := 1
xpos := 0
zpos := 0
heading := 0

sector1 =
(LTrim Join

   -3.0,0.0,-3.0,0.0,6.0,
   -3.0,0.0,3.0,0.0,0.0,
    3.0,0.0,3.0,6.0,0.0,
   -3.0,0.0,-3.0,0.0,6.0,
    3.0,0.0,-3.0,6.0,6.0,
    3.0,0.0,3.0,6.0,0.0,
   -3.0,1.0,-3.0,0.0,6.0,
   -3.0,1.0,3.0,0.0,0.0,
   3.0,1.0,3.0,6.0,0.0,
   -3.0,1.0,-3.0,0.0,6.0,
   3.0,1.0,-3.0,6.0,6.0,
   3.0,1.0,3.0,6.0,0.0,
   -2.0,1.0,-2.0,0.0,1.0,
   -2.0,0.0,-2.0,0.0,0.0,
   -0.5,0.0,-2.0,1.5,0.0,
   -2.0,1.0,-2.0,0.0,1.0,
   -0.5,1.0,-2.0,1.5,1.0,
   -0.5,0.0,-2.0,1.5,0.0,
   2.0,1.0,-2.0,2.0,1.0,
   2.0,0.0,-2.0,2.0,0.0,
   0.5,0.0,-2.0,0.5,0.0,
   2.0,1.0,-2.0,2.0,1.0,
   0.5,1.0,-2.0,0.5,1.0,
   0.5,0.0,-2.0,0.5,0.0,
   -2.0,1.0,2.0,2.0,1.0,
   -2.0,0.0,2.0,2.0,0.0,
   -0.5,0.0,2.0,0.5,0.0,
   -2.0,1.0,2.0,2.0,1.0,
   -0.5,1.0,2.0,0.5,1.0,
   -0.5,0.0,2.0,0.5,0.0,
   2.0,1.0,2.0,2.0,1.0,
   2.0,0.0,2.0,2.0,0.0,
   0.5,0.0,2.0,0.5,0.0,
   2.0,1.0,2.0,2.0,1.0,
   0.5,1.0,2.0,0.5,1.0,
   0.5,0.0,2.0,0.5,0.0,
   -2.0,1.0,-2.0,0.0,1.0,
   -2.0,0.0,-2.0,0.0,0.0,
   -2.0,0.0,-0.5,1.5,0.0,
   -2.0,1.0,-2.0,0.0,1.0,
   -2.0,1.0,-0.5,1.5,1.0,
   -2.0,0.0,-0.5,1.5,0.0,
   -2.0,1.0,2.0,2.0,1.0,
   -2.0,0.0,2.0,2.0,0.0,
   -2.0,0.0,0.5,0.5,0.0,
   -2.0,1.0,2.0,2.0,1.0,
   -2.0,1.0,0.5,0.5,1.0,
   -2.0,0.0,0.5,0.5,0.0,
   2.0,1.0,-2.0,0.0,1.0,
   2.0,0.0,-2.0,0.0,0.0,
   2.0,0.0,-0.5,1.5,0.0,
   2.0,1.0,-2.0,0.0,1.0,
   2.0,1.0,-0.5,1.5,1.0,
   2.0,0.0,-0.5,1.5,0.0,
   2.0,1.0,2.0,2.0,1.0,
   2.0,0.0,2.0,2.0,0.0,
   2.0,0.0,0.5,0.5,0.0,
   2.0,1.0,2.0,2.0,1.0,
   2.0,1.0,0.5,0.5,1.0,
   2.0,0.0,0.5,0.5,0.0,
   -0.5,1.0,-3.0,0.0,1.0,
   -0.5,0.0,-3.0,0.0,0.0,
   -0.5,0.0,-2.0,1.0,0.0,
   -0.5,1.0,-3.0,0.0,1.0,
   -0.5,1.0,-2.0,1.0,1.0,
   -0.5,0.0,-2.0,1.0,0.0,
   0.5,1.0,-3.0,0.0,1.0,
   0.5,0.0,-3.0,0.0,0.0,
   0.5,0.0,-2.0,1.0,0.0,
   0.5,1.0,-3.0,0.0,1.0,
   0.5,1.0,-2.0,1.0,1.0,
   0.5,0.0,-2.0,1.0,0.0,
   -0.5,1.0,3.0,0.0,1.0,
   -0.5,0.0,3.0,0.0,0.0,
   -0.5,0.0,2.0,1.0,0.0,
   -0.5,1.0,3.0,0.0,1.0,
   -0.5,1.0,2.0,1.0,1.0,
   -0.5,0.0,2.0,1.0,0.0,
   0.5,1.0,3.0,0.0,1.0,
   0.5,0.0,3.0,0.0,0.0,
   0.5,0.0,2.0,1.0,0.0,
   0.5,1.0,3.0,0.0,1.0,
   0.5,1.0,2.0,1.0,1.0,
   0.5,0.0,2.0,1.0,0.0,
   -3.0,1.0,0.5,1.0,1.0,
   -3.0,0.0,0.5,1.0,0.0,
   -2.0,0.0,0.5,0.0,0.0,
   -3.0,1.0,0.5,1.0,1.0,
   -2.0,1.0,0.5,0.0,1.0,
   -2.0,0.0,0.5,0.0,0.0,
   -3.0,1.0,-0.5,1.0,1.0,
   -3.0,0.0,-0.5,1.0,0.0,
   -2.0,0.0,-0.5,0.0,0.0,
   -3.0,1.0,-0.5,1.0,1.0,
   -2.0,1.0,-0.5,0.0,1.0,
   -2.0,0.0,-0.5,0.0,0.0,
   3.0,1.0,0.5,1.0,1.0,
   3.0,0.0,0.5,1.0,0.0,
   2.0,0.0,0.5,0.0,0.0,
   3.0,1.0,0.5,1.0,1.0,
   2.0,1.0,0.5,0.0,1.0,
   2.0,0.0,0.5,0.0,0.0,
   3.0,1.0,-0.5,1.0,1.0,
   3.0,0.0,-0.5,1.0,0.0,
   2.0,0.0,-0.5,0.0,0.0,
   3.0,1.0,-0.5,1.0,1.0,
   2.0,1.0,-0.5,0.0,1.0,
   2.0,0.0,-0.5,0.0,0.0
)

   WinMain()

; ==============================================================================================

SetupWorld()
{

   Global

   Loop, Parse, sector1, `,
   {
      If Count = 1
         sector1_triangle%tri%_vect%vec%_x := A_LoopField
      If Count = 2
         sector1_triangle%tri%_vect%vec%_y := A_LoopField
      If Count = 3
         sector1_triangle%tri%_vect%vec%_z := A_LoopField
      If Count = 4
         sector1_triangle%tri%_vect%vec%_u := A_LoopField
      If Count = 5
      {
         sector1_triangle%tri%_vect%vec%_v := A_LoopField
         Count := 1
         vec++
         If vec = 4
         {
            vec := 1
            tri++
         }
         Continue
      }

      Count++
   }

   tri := tri - 1
   Return 1


}




LoadImage()
{

   Global

   VarSetCapacity(imgInfo, 24, 0)
   VarSetCapacity(texture, 12, 0)

   DllCall("opengl32\glGenTextures", Int, 3, UInt, &texture)
   lpszName = %A_ScriptDir%\MUD.bmp
   hBmp := DllCall("LoadImage", UInt, 0, UInt, &lpszName, UInt, IMAGE_BITMAP, Int, 0, Int, 0, UInt, LR_LOADFROMFILE | LR_CREATEDIBSECTION)

   ; BITMAP size: 24
   DllCall("gdi32.dll\GetObject", UInt, hBmp, UInt, 24, UInt, &imgInfo)
   bmWidth := NumGet(imgInfo, 4, "Int")
   bmHeight := NumGet(imgInfo, 8, "Int")
   bmBits := NumGet(imgInfo, 20, "UInt")

   DllCall("opengl32.dll\glBindTexture", UInt, GL_TEXTURE_2D, UInt, NumGet(texture, 0, "UInt"))
   DllCall("opengl32.dll\glTexParameteri", UInt, GL_TEXTURE_2D, UInt, GL_TEXTURE_MIN_FILTER, UInt, GL_NEAREST)
   DllCall("opengl32.dll\glTexParameteri", UInt, GL_TEXTURE_2D, UInt, GL_TEXTURE_MAG_FILTER, UInt,GL_NEAREST)
   DllCall("opengl32.dll\glTexImage2D", UInt, GL_TEXTURE_2D, Int, 0, Int, 3
               , Int, bmWidth, Int, bmHeight, Int , 0, UInt, GL_BGR_EXT
               , UInt, GL_UNSIGNED_BYTE, UInt, bmBits)

   DllCall("opengl32.dll\glBindTexture", UInt, GL_TEXTURE_2D, UInt, NumGet(texture, 4, "UInt"))
   DllCall("opengl32.dll\glTexParameteri", UInt, GL_TEXTURE_2D, UInt, GL_TEXTURE_MIN_FILTER, UInt, GL_LINEAR)
   DllCall("opengl32.dll\glTexParameteri", UInt, GL_TEXTURE_2D, UInt, GL_TEXTURE_MAG_FILTER, UInt,GL_LINEAR)
   DllCall("opengl32.dll\glTexImage2D", UInt, GL_TEXTURE_2D, Int, 0, Int, 3
               , Int, bmWidth, Int, bmHeight, Int , 0, UInt, GL_BGR_EXT
               , UInt, GL_UNSIGNED_BYTE, UInt, bmBits)

   DllCall("opengl32.dll\glBindTexture", UInt, GL_TEXTURE_2D, UInt, NumGet(texture, 8, "UInt"))
   DllCall("opengl32.dll\glTexParameteri", UInt, GL_TEXTURE_2D, UInt, GL_TEXTURE_MIN_FILTER, UInt, GL_LINEAR)
   DllCall("opengl32.dll\glTexParameteri", UInt, GL_TEXTURE_2D, UInt, GL_TEXTURE_MAG_FILTER, UInt,GL_LINEAR_MIPMAP_NEAREST)
   DllCall("opengl32.dll\glTexImage2D", UInt, GL_TEXTURE_2D, Int, 0, Int, 3
               , Int, bmWidth, Int, bmHeight, Int , 0, UInt, GL_BGR_EXT
               , UInt, GL_UNSIGNED_BYTE, UInt, bmBits)

   Return 1

}




ReSizeGLScene()
{

   Global

   If height = 0               ;Prevent divide by 0
      height := 1

   DllCall("opengl32.dll\glViewport", Int, 0, Int, 0, Int, width, Int, height)
   DllCall("opengl32.dll\glMatrixMode", UInt, GL_PROJECTION)
   DllCall("opengl32.dll\glLoadIdentity")

   ; Calculate aspect ratio of the window
   DllCall("glu32.dll\gluPerspective", Double, 45.0, Double, width/height, Double, 0.1, Double, 100.0)

   DllCall("opengl32.dll\glMatrixMode", UInt, GL_MODELVIEW)
   DllCall("opengl32.dll\glLoadIdentity")

   Return

}




InitGL()
{

   Global

   If !LoadImage()
      Return 0


   DllCall("opengl32.dll\glEnable", UInt, GL_TEXTURE_2D)
   DllCall("opengl32.dll\glBlendFunc", UInt, GL_SRC_ALPHA,GL_ONE)
   DllCall("opengl32.dll\glClearColor", Float, 0.0, Float, 0.0, Float, 0.0, Float, 0.0)
   DllCall("opengl32.dll\glClearDepth", Double, 1.0)
   DllCall("opengl32.dll\glDepthFunc", UInt, GL_LESS)
   DllCall("opengl32.dll\glEnable", UInt, GL_DEPTH_TEST)
   DllCall("opengl32.dll\glShadeModel", UInt, GL_SMOOTH)
   DllCall("opengl32.dll\glHint", UInt, GL_PERSPECTIVE_CORRECTION_HINT, UInt, GL_NICEST)

   SetupWorld()

   Return 1

}




DrawGLScene()
{

   Global

   xtrans :=- xpos
   ztrans :=- zpos
   ytrans :=- walkbias-0.25
   sceneroty := 360.0 - yrot

   DllCall("opengl32.dll\glClear", Int, GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
   DllCall("opengl32.dll\glLoadIdentity")

   DllCall("opengl32.dll\glRotatef", Float, lookupdown, Float, 1.0, Float, 0, Float, 0)
   DllCall("opengl32.dll\glRotatef", Float, sceneroty, Float, 0, Float, 1.0, Float, 0)

   DllCall("opengl32.dll\glTranslatef", Float, xtrans, Float, ytrans, Float, ztrans)
   DllCall("opengl32.dll\glBindTexture", UInt, GL_TEXTURE_2D, UInt, NumGet(texture, filter*4, "UInt"))

   Loop, %tri%
   {
      DllCall("opengl32.dll\glBegin", UInt, GL_TRIANGLES)
         x_m := sector1_triangle%A_Index%_vect1_x
         y_m := sector1_triangle%A_Index%_vect1_y
         z_m := sector1_triangle%A_Index%_vect1_z
         u_m := sector1_triangle%A_Index%_vect1_u
         v_m := sector1_triangle%A_Index%_vect1_v
         DllCall("opengl32.dll\glTexCoord2f", Float, u_m, Float, v_m)
         DllCall("opengl32.dll\glVertex3f", Float, x_m, Float, y_m, Float, z_m)

         x_m := sector1_triangle%A_Index%_vect2_x
         y_m := sector1_triangle%A_Index%_vect2_y
         z_m := sector1_triangle%A_Index%_vect2_z
         u_m := sector1_triangle%A_Index%_vect2_u
         v_m := sector1_triangle%A_Index%_vect2_v
         DllCall("opengl32.dll\glTexCoord2f", Float, u_m, Float, v_m)
         DllCall("opengl32.dll\glVertex3f", Float, x_m, Float, y_m, Float, z_m)

         x_m := sector1_triangle%A_Index%_vect3_x
         y_m := sector1_triangle%A_Index%_vect3_y
         z_m := sector1_triangle%A_Index%_vect3_z
         u_m := sector1_triangle%A_Index%_vect3_u
         v_m := sector1_triangle%A_Index%_vect3_v
         DllCall("opengl32.dll\glTexCoord2f", Float, u_m, Float, v_m)
         DllCall("opengl32.dll\glVertex3f", Float, x_m, Float, y_m, Float, z_m)

      DllCall("opengl32.dll\glEnd")
   }

   DllCall("gdi32.dll\SwapBuffers", UInt, hDC)

   Return 1

}




KillGLWindow()
{

   Global

   If fullscreen
   {
      DllCall("ChangeDisplaySettings", UInt, 0, UInt, 0)
      DllCall("ShowCursor", Int, 1)
   }

   If hRC
   {
      If !DllCall("opengl32.dll\wglMakeCurrent", UInt, 0, UInt, 0)
         MsgBox, Release of DC and RC failed.`nError: %A_LastError%

      If !DllCall("opengl32.dll\wglDeleteContext", UInt, hRC)
         MsgBox, Release rendering context failed.`nError: %A_LastError%
   }

   If hDC
   {
      If !DllCall("ReleaseDC", UInt, hWnd, UInt, hDC)
         MsgBox, Release device context failed.`nError: %A_LastError%
   }

   If hWnd
   {
      If !DllCall("DestroyWindow", UInt, hWnd)
         MsgBox, Could not release hWnd.`nError: %A_LastError%
   }

   If ATOM
   {
      If !DllCall("UnregisterClass", UInt, &lpszClassName, UInt, hInstance)
         MsgBox, Could not unregister class.`nError: %A_LastError%
   }

   hInstance := 0
   hWnd := 0
   ATOM := 0
   hDC := 0
   hRC := 0
}




CreateGLWindow(title, width, height, bits)
{

   Global

   VarSetCapacity(wc, 40, 0)
   VarSetCapacity(WindowRect, 16, 0)
   VarSetCapacity(pfd, 40, 0)

   NumPut(0, WindowRect, 0, "Int")
   NumPut(0, WindowRect, 4, "Int")
   NumPut(width, WindowRect, 8, "Int")
   NumPut(height, WindowRect, 12, "Int")

   Style := CS_HREDRAW | CS_VREDRAW | CS_OWNDC
   lpfnWndProc := RegisterCallback("WndProc", "", 4)
   cbClsExtra := 0
   cbWndExtra := 0
   hInstance := DllCall("GetModuleHandle", UInt, 0)
   hbrBackground := 0
   hCursor := DllCall("LoadCursor", UInt, 0, UInt, IDC_ARROW)
   hIcon := DllCall("LoadIcon", UInt, 0, UInt, IDI_APPLICATION)
   lpszMenuName := 0

   NumPut(Style, wc, 0, "UInt")
   NumPut(lpfnWndProc, wc, 4, "UInt")
   NumPut(cbClsExtra, wc, 8, "UInt")
   NumPut(cbWndExtra, wc, 12, "UInt")
   NumPut(hInstance, wc, 16, "UInt")
   NumPut(hIcon, wc, 20, "UInt")
   NumPut(hCursor, wc, 24, "UInt")
   NumPut(hbrBackground, wc, 28, "UInt")
   NumPut(&lpszMenuName, wc, 32, "UInt")
   NumPut(&lpszClassName, wc, 36, "UInt")

   ATOM := DllCall("RegisterClass", UInt, &wc)
   If !ATOM
   {
      MsgBox, Failed to register class.`nError: %A_LastError%
      ExitApp
   }

   If fullscreen
   {
      ; DEVMODE size: 156 ANSI, 220 UNICODE
      VarSetCapacity(dmScreenSettings, 156, 0)

      dmFields := DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT

      NumPut(156, dmScreenSettings, 0, "UShort")

      Result := DllCall("EnumDisplaySettings", UInt, 0, UInt, 0, UInt, &dmScreenSettings)

      NumPut(width, dmScreenSettings, 108, "UInt")
      NumPut(height, dmScreenSettings, 112, "UInt")
      NumPut(bits, dmScreenSettings, 104, "UInt") ;bits
      NumPut(dmFields, dmScreenSettings, 40, "UInt")

      Result := DllCall("ChangeDisplaySettings", UInt, &dmScreenSettings, UInt, CDS_FULLSCREEN)
      If Result != %DISP_CHANGE_SUCCESSFUL%
      {
         MsgBox,4, Error, The requested fullscreen mode is not supported by`nyour video card. Use windowed mode instead?
         IfMsgBox Yes
            fullscreen := 0
         Else
         {
            ; Let the user know the program is closing
            MsgBox, The program will now close.
            ExitApp
         }
      }
   }

   If fullscreen
   {
      dwExStyle := WS_EX_APPWINDOW
      dwStyle := WS_POPUP
      DllCall("ShowCursor", Int, 0)
   }
   Else
   {
      dwExStyle := WS_EX_APPWINDOW | WS_EX_WINDOWEDGE
      dwStyle := WS_OVERLAPPEDWINDOW
   }

   DllCall("AdjustWindowRectEx", UInt, &WindowRect, UInt, dwStyle, UInt, 0, UInt, dwExStyle)

   hWnd := DllCall("CreateWindowEx", UInt, dwExStyle
               , UInt, &lpszClassName
               , "Str", title
               , UInt, dwStyle | WS_CLIPSIBLINGS | WS_CLIPCHILDREN
               , Int, 0
               , Int, 0
               , Int, NumGet(WindowRect, 8, "Int")-NumGet(WindowRect, 0, "Int")
               , Int, NumGet(WindowRect, 12, "Int")-NumGet(WindowRect, 4, "Int")
               , UInt, 0
               , UInt, 0
               , UInt, hInstance
               , UInt, 0
               , UInt)
   If !hWnd
   {
      MsgBox, Window creation error.`nError: %A_LastError%
      ExitApp
   }

   dwFlags := PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER

   NumPut(40, pfd, 0, "UShort")
   NumPut(1, pfd, 2, "UShort")
   NumPut(dwFlags, pfd, 4, "UInt")
   NumPut(PFD_TYPE_RGBA, pfd, 8, "UChar")
   NumPut(bits, pfd, 9, "UChar")
   NumPut(16, pfd, 23, "UChar")
   NumPut(PFD_MAIN_PLANE, pfd, 26, "UChar")

   hDC := DllCall("GetDC", UInt, hWnd)
   If !hDC
   {
      MsgBox, Can't create GL device context.`nError: %A_LastError%
      ExitApp
   }

   PixelFormat := DllCall("gdi32.dll\ChoosePixelFormat", UInt, hDC, UInt, &pfd)
   If !PixelFormat
   {
      MsgBox, Can't find a suitable pixel format.`nError: %A_LastError%
      ExitApp
   }

   If !DllCall("gdi32.dll\SetPixelFormat", UInt, hDC, UInt, PixelFormat, UInt, &pfd)
   {
      MsgBox, Can't set the pixel format.`nError: %A_LastError%
      ExitApp
   }

   hRC := DllCall("opengl32.dll\wglCreateContext", UInt, hDC)
   If !hRC
   {
      MsgBox, Can't create GL rendering context.`nError: %A_LastError%
      ExitApp
   }

   If !DllCall("opengl32.dll\wglMakeCurrent", UInt, hDC, UInt, hRC)
   {
      MsgBox, Can't activate the GL rendering context.`nError: %A_LastError%
      ExitApp
   }

   DllCall("ShowWindow", UInt, hWnd, Int, SW_SHOW)
   DllCall("SetForegroundWindow", UInt, hWnd)
   DllCall("SetFocus", UInt, hWnd)
   ReSizeGLScene()

   If !InitGL()
   {
      MsgBox, Initialization failed.
      ExitApp
   }

   Return 1

}




WndProc(hwnd, uMsg, wParam, lParam)
{

   Global

   If uMsg = %WM_ACTIVATE%
   {
      If !(wParam >> 16)
         active := 1
      Else
         active := 0

      Return 0
   }

   If uMsg = %WM_SYSCOMMAND%
   {
      If wParam = %SC_SCREENSAVE%
         Return 0

      If wParam = %SC_MONITORPOWER%
         Return 0
   }

   If uMsg = %WM_CLOSE%
      ExitApp

   If uMsg = %WM_SIZE%
   {
      width := lParam & 0x0ffff
      height := lParam >> 16
      ReSizeGLScene()
      Return 0
   }

   Return DllCall("DefWindowProc", UInt, hwnd, UInt, uMsg, UInt, wParam, UInt, lParam)

}




WinMain()
{

   Global

   MsgBox, 4, Start Fullscreen?, Would you like to run in fullscreen mode?
   IfMsgBox No
      fullscreen := 0

   CreateGLWindow("Nehe's First Polygon Tutorial", 640, 480, 16)

   Loop
   {
      If F1
      {
         KillGLWindow()
         F1 := 0
         fullscreen := !fullscreen
         CreateGLWindow("Nehe's First Polygon Tutorial", 640, 480, 16)
      }

      If active
      If !DrawGLScene()
         Break
   }

   ExitApp

}

; ==============================================================================================

Esc::PostMessage, %WM_CLOSE%, 0, 0,, ahk_id %hWnd%
F1::F1++

*Up::
xpos := xpos - (sin(heading*piover180) * 0.05)
zpos := zpos - (cos(heading*piover180) * 0.05)
If walkbiasangle >= 359.0
   walkbiasangle := 0
Else
   walkbiasangle := walkbiasangle + 10
walkbias := sin(walkbiasangle * piover180)/20.0
Return

*Down::
xpos := xpos + (sin(heading*piover180) * 0.05)
zpos := zpos + (cos(heading*piover180) * 0.05)
If walkbiasangle <= 1.0
   walkbiasangle := 359.0
Else
   walkbiasangle := walkbiasangle - 10
walkbias := sin(walkbiasangle * piover180)/20.0
Return

*Right::
heading := heading - 1.0
yrot := heading
Return

*Left::
heading := heading + 1.0
yrot := heading
Return

*PgDn::lookupdown := lookupdown - 1.0
*PgUp::lookupdown := lookupdown + 1.0

*f::
filter++
If filter >2
  filter := 0
Return








Exit:
KillGLWindow()

If hOpenGL
   DllCall("FreeLibrary", UInt, hOpenGL)
If hGlu32
   DllCall("FreeLibrary", UInt, hGlu32)
If hGdi32
   DllCall("FreeLibrary", UInt, hGdi32)
ExitApp


Not sure the image is getting binded with the filter exactly like it should, but it is close. Maybe someone can pinpoint something I've missed. If not I'll go back through it later and work it out.

Cleanup code needs some work too. I'm getting script errors sometimes on exit.

Have fun Smile
Back to top
engunneer



Joined: 30 Aug 2005
Posts: 6349
Location: Pacific Northwest, US

PostPosted: Sun Apr 27, 2008 5:54 am    Post subject: Reply with quote

really cool demo.

It's not very happy on my Vista PC though. I'm seeing if admin rights help. I get a few black squares in white space.

edit:I saved the image badly. I get errors releasing the DC and RC unless I run as admin.

I really like the walking "effect" (no spoilers here)
_________________
Unless otherwise noted, all code is untested.
Common Answers: 1.(Loops, Viruses, etc.) 2. Search 3.RTFM
Back to top
View user's profile Send private message Visit poster's website
SomeGuy



Joined: 21 Apr 2008
Posts: 94
Location: somewhere

PostPosted: Sun Apr 27, 2008 6:37 am    Post subject: Reply with quote

yeah that is really neat.............you might host the image at autohotkey.net instead of imageshack, though....it appears to be converted to jpg when put on imageshack.
Back to top
View user's profile Send private message
Zippo()
Guest





PostPosted: Sun Apr 27, 2008 7:16 am    Post subject: Reply with quote

Ouch. Thanks for the heads-up. I uploaded it to that image hosting site, found it trashed the image and put it on Autohotkey.net. I just forgot to change the link before posting.

Here she be: MUD.bmp

Thanks
Back to top
Zippo()
Guest





PostPosted: Sun Apr 27, 2008 1:44 pm    Post subject: Reply with quote

After thinking about it for a while, I guess OpenGL doesn't like it when you try to destroy a DC or RC it is using. That was causing the error on exit. Should have figured on that from the start.

Just a little change to the exit behavior:
Code:
;   This script is based off of Nehe's Open GL Tutorial #10, which can be found at
;   http://nehe.gamedev.net


;/////////////////////////////////////////////////////////////////////////////////////////////
#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.   ;//
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.   ;//
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.                    ;//
;/////////////////////////////////////////////////////////////////////////////////////////////

#include WINDERS.ahk
#include GL.ahk

OnExit, Exit

hOpenGL := DllCall("LoadLibrary", Str, "opengl32.dll")
hGlu32  := DllCall("LoadLibrary", Str, "glu32.dll")
hGdi32  := DllCall("LoadLibrary", Str, "gdi32.dll")

hInstance := 0
hWnd := 0
ATOM := 0
hDC := 0
hRC := 0
F1 := 0
active := 1
fullscreen := 1
filter := 0
lpszClassName := "OpenGL"
piover180 := 0.0174532925
filter := 1
walkbias := 0
walkbiasangle := 0
lookupdown := 0.0
z := 0.0
tri := 1
vec := 1
Count := 1
xpos := 0
zpos := 0
heading := 0
exit := 0

sector1 =
(LTrim Join

   -3.0,0.0,-3.0,0.0,6.0,
   -3.0,0.0,3.0,0.0,0.0,
    3.0,0.0,3.0,6.0,0.0,
   -3.0,0.0,-3.0,0.0,6.0,
    3.0,0.0,-3.0,6.0,6.0,
    3.0,0.0,3.0,6.0,0.0,
   -3.0,1.0,-3.0,0.0,6.0,
   -3.0,1.0,3.0,0.0,0.0,
   3.0,1.0,3.0,6.0,0.0,
   -3.0,1.0,-3.0,0.0,6.0,
   3.0,1.0,-3.0,6.0,6.0,
   3.0,1.0,3.0,6.0,0.0,
   -2.0,1.0,-2.0,0.0,1.0,
   -2.0,0.0,-2.0,0.0,0.0,
   -0.5,0.0,-2.0,1.5,0.0,
   -2.0,1.0,-2.0,0.0,1.0,
   -0.5,1.0,-2.0,1.5,1.0,
   -0.5,0.0,-2.0,1.5,0.0,
   2.0,1.0,-2.0,2.0,1.0,
   2.0,0.0,-2.0,2.0,0.0,
   0.5,0.0,-2.0,0.5,0.0,
   2.0,1.0,-2.0,2.0,1.0,
   0.5,1.0,-2.0,0.5,1.0,
   0.5,0.0,-2.0,0.5,0.0,
   -2.0,1.0,2.0,2.0,1.0,
   -2.0,0.0,2.0,2.0,0.0,
   -0.5,0.0,2.0,0.5,0.0,
   -2.0,1.0,2.0,2.0,1.0,
   -0.5,1.0,2.0,0.5,1.0,
   -0.5,0.0,2.0,0.5,0.0,
   2.0,1.0,2.0,2.0,1.0,
   2.0,0.0,2.0,2.0,0.0,
   0.5,0.0,2.0,0.5,0.0,
   2.0,1.0,2.0,2.0,1.0,
   0.5,1.0,2.0,0.5,1.0,
   0.5,0.0,2.0,0.5,0.0,
   -2.0,1.0,-2.0,0.0,1.0,
   -2.0,0.0,-2.0,0.0,0.0,
   -2.0,0.0,-0.5,1.5,0.0,
   -2.0,1.0,-2.0,0.0,1.0,
   -2.0,1.0,-0.5,1.5,1.0,
   -2.0,0.0,-0.5,1.5,0.0,
   -2.0,1.0,2.0,2.0,1.0,
   -2.0,0.0,2.0,2.0,0.0,
   -2.0,0.0,0.5,0.5,0.0,
   -2.0,1.0,2.0,2.0,1.0,
   -2.0,1.0,0.5,0.5,1.0,
   -2.0,0.0,0.5,0.5,0.0,
   2.0,1.0,-2.0,0.0,1.0,
   2.0,0.0,-2.0,0.0,0.0,
   2.0,0.0,-0.5,1.5,0.0,
   2.0,1.0,-2.0,0.0,1.0,
   2.0,1.0,-0.5,1.5,1.0,
   2.0,0.0,-0.5,1.5,0.0,
   2.0,1.0,2.0,2.0,1.0,
   2.0,0.0,2.0,2.0,0.0,
   2.0,0.0,0.5,0.5,0.0,
   2.0,1.0,2.0,2.0,1.0,
   2.0,1.0,0.5,0.5,1.0,
   2.0,0.0,0.5,0.5,0.0,
   -0.5,1.0,-3.0,0.0,1.0,
   -0.5,0.0,-3.0,0.0,0.0,
   -0.5,0.0,-2.0,1.0,0.0,
   -0.5,1.0,-3.0,0.0,1.0,
   -0.5,1.0,-2.0,1.0,1.0,
   -0.5,0.0,-2.0,1.0,0.0,
   0.5,1.0,-3.0,0.0,1.0,
   0.5,0.0,-3.0,0.0,0.0,
   0.5,0.0,-2.0,1.0,0.0,
   0.5,1.0,-3.0,0.0,1.0,
   0.5,1.0,-2.0,1.0,1.0,
   0.5,0.0,-2.0,1.0,0.0,
   -0.5,1.0,3.0,0.0,1.0,
   -0.5,0.0,3.0,0.0,0.0,
   -0.5,0.0,2.0,1.0,0.0,
   -0.5,1.0,3.0,0.0,1.0,
   -0.5,1.0,2.0,1.0,1.0,
   -0.5,0.0,2.0,1.0,0.0,
   0.5,1.0,3.0,0.0,1.0,
   0.5,0.0,3.0,0.0,0.0,
   0.5,0.0,2.0,1.0,0.0,
   0.5,1.0,3.0,0.0,1.0,
   0.5,1.0,2.0,1.0,1.0,
   0.5,0.0,2.0,1.0,0.0,
   -3.0,1.0,0.5,1.0,1.0,
   -3.0,0.0,0.5,1.0,0.0,
   -2.0,0.0,0.5,0.0,0.0,
   -3.0,1.0,0.5,1.0,1.0,
   -2.0,1.0,0.5,0.0,1.0,
   -2.0,0.0,0.5,0.0,0.0,
   -3.0,1.0,-0.5,1.0,1.0,
   -3.0,0.0,-0.5,1.0,0.0,
   -2.0,0.0,-0.5,0.0,0.0,
   -3.0,1.0,-0.5,1.0,1.0,
   -2.0,1.0,-0.5,0.0,1.0,
   -2.0,0.0,-0.5,0.0,0.0,
   3.0,1.0,0.5,1.0,1.0,
   3.0,0.0,0.5,1.0,0.0,
   2.0,0.0,0.5,0.0,0.0,
   3.0,1.0,0.5,1.0,1.0,
   2.0,1.0,0.5,0.0,1.0,
   2.0,0.0,0.5,0.0,0.0,
   3.0,1.0,-0.5,1.0,1.0,
   3.0,0.0,-0.5,1.0,0.0,
   2.0,0.0,-0.5,0.0,0.0,
   3.0,1.0,-0.5,1.0,1.0,
   2.0,1.0,-0.5,0.0,1.0,
   2.0,0.0,-0.5,0.0,0.0
)

   WinMain()

; ==============================================================================================

SetupWorld()
{

   Global

   Loop, Parse, sector1, `,
   {
      If Count = 1
         sector1_triangle%tri%_vect%vec%_x := A_LoopField
      If Count = 2
         sector1_triangle%tri%_vect%vec%_y := A_LoopField
      If Count = 3
         sector1_triangle%tri%_vect%vec%_z := A_LoopField
      If Count = 4
         sector1_triangle%tri%_vect%vec%_u := A_LoopField
      If Count = 5
      {
         sector1_triangle%tri%_vect%vec%_v := A_LoopField
         Count := 1
         vec++
         If vec = 4
         {
            vec := 1
            tri++
         }
         Continue
      }

      Count++
   }

   tri := tri - 1
   Return 1


}




LoadImage()
{

   Global

   VarSetCapacity(imgInfo, 24, 0)
   VarSetCapacity(texture, 12, 0)

   DllCall("opengl32\glGenTextures", Int, 3, UInt, &texture)
   lpszName = %A_ScriptDir%\MUD.bmp
   hBmp := DllCall("LoadImage", UInt, 0, UInt, &lpszName, UInt, IMAGE_BITMAP, Int, 0, Int, 0, UInt, LR_LOADFROMFILE | LR_CREATEDIBSECTION)

   ; BITMAP size: 24
   DllCall("gdi32.dll\GetObject", UInt, hBmp, UInt, 24, UInt, &imgInfo)
   bmWidth := NumGet(imgInfo, 4, "Int")
   bmHeight := NumGet(imgInfo, 8, "Int")
   bmBits := NumGet(imgInfo, 20, "UInt")

   DllCall("opengl32.dll\glBindTexture", UInt, GL_TEXTURE_2D, UInt, NumGet(texture, 0, "UInt"))
   DllCall("opengl32.dll\glTexParameteri", UInt, GL_TEXTURE_2D, UInt, GL_TEXTURE_MIN_FILTER, UInt, GL_NEAREST)
   DllCall("opengl32.dll\glTexParameteri", UInt, GL_TEXTURE_2D, UInt, GL_TEXTURE_MAG_FILTER, UInt,GL_NEAREST)
   DllCall("opengl32.dll\glTexImage2D", UInt, GL_TEXTURE_2D, Int, 0, Int, 3
               , Int, bmWidth, Int, bmHeight, Int , 0, UInt, GL_BGR_EXT
               , UInt, GL_UNSIGNED_BYTE, UInt, bmBits)

   DllCall("opengl32.dll\glBindTexture", UInt, GL_TEXTURE_2D, UInt, NumGet(texture, 4, "UInt"))
   DllCall("opengl32.dll\glTexParameteri", UInt, GL_TEXTURE_2D, UInt, GL_TEXTURE_MIN_FILTER, UInt, GL_LINEAR)
   DllCall("opengl32.dll\glTexParameteri", UInt, GL_TEXTURE_2D, UInt, GL_TEXTURE_MAG_FILTER, UInt,GL_LINEAR)
   DllCall("opengl32.dll\glTexImage2D", UInt, GL_TEXTURE_2D, Int, 0, Int, 3
               , Int, bmWidth, Int, bmHeight, Int , 0, UInt, GL_BGR_EXT
               , UInt, GL_UNSIGNED_BYTE, UInt, bmBits)

   DllCall("opengl32.dll\glBindTexture", UInt, GL_TEXTURE_2D, UInt, NumGet(texture, 8, "UInt"))
   DllCall("opengl32.dll\glTexParameteri", UInt, GL_TEXTURE_2D, UInt, GL_TEXTURE_MIN_FILTER, UInt, GL_LINEAR)
   DllCall("opengl32.dll\glTexParameteri", UInt, GL_TEXTURE_2D, UInt, GL_TEXTURE_MAG_FILTER, UInt,GL_LINEAR_MIPMAP_NEAREST)
   DllCall("opengl32.dll\glTexImage2D", UInt, GL_TEXTURE_2D, Int, 0, Int, 3
               , Int, bmWidth, Int, bmHeight, Int , 0, UInt, GL_BGR_EXT
               , UInt, GL_UNSIGNED_BYTE, UInt, bmBits)

   Return 1

}




ReSizeGLScene()
{

   Global

   If height = 0               ;Prevent divide by 0
      height := 1

   DllCall("opengl32.dll\glViewport", Int, 0, Int, 0, Int, width, Int, height)
   DllCall("opengl32.dll\glMatrixMode", UInt, GL_PROJECTION)
   DllCall("opengl32.dll\glLoadIdentity")

   ; Calculate aspect ratio of the window
   DllCall("glu32.dll\gluPerspective", Double, 45.0, Double, width/height, Double, 0.1, Double, 100.0)

   DllCall("opengl32.dll\glMatrixMode", UInt, GL_MODELVIEW)
   DllCall("opengl32.dll\glLoadIdentity")

   Return

}




InitGL()
{

   Global

   If !LoadImage()
      Return 0


   DllCall("opengl32.dll\glEnable", UInt, GL_TEXTURE_2D)
   DllCall("opengl32.dll\glBlendFunc", UInt, GL_SRC_ALPHA,GL_ONE)
   DllCall("opengl32.dll\glClearColor", Float, 0.0, Float, 0.0, Float, 0.0, Float, 0.0)
   DllCall("opengl32.dll\glClearDepth", Double, 1.0)
   DllCall("opengl32.dll\glDepthFunc", UInt, GL_LESS)
   DllCall("opengl32.dll\glEnable", UInt, GL_DEPTH_TEST)
   DllCall("opengl32.dll\glShadeModel", UInt, GL_SMOOTH)
   DllCall("opengl32.dll\glHint", UInt, GL_PERSPECTIVE_CORRECTION_HINT, UInt, GL_NICEST)

   SetupWorld()

   Return 1

}




DrawGLScene()
{

   Global

   xtrans :=- xpos
   ztrans :=- zpos
   ytrans :=- walkbias-0.25
   sceneroty := 360.0 - yrot

   DllCall("opengl32.dll\glClear", Int, GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
   DllCall("opengl32.dll\glLoadIdentity")

   DllCall("opengl32.dll\glRotatef", Float, lookupdown, Float, 1.0, Float, 0, Float, 0)
   DllCall("opengl32.dll\glRotatef", Float, sceneroty, Float, 0, Float, 1.0, Float, 0)

   DllCall("opengl32.dll\glTranslatef", Float, xtrans, Float, ytrans, Float, ztrans)
   DllCall("opengl32.dll\glBindTexture", UInt, GL_TEXTURE_2D, UInt, NumGet(texture, filter*4, "UInt"))

   Loop, %tri%
   {
      DllCall("opengl32.dll\glBegin", UInt, GL_TRIANGLES)
         x_m := sector1_triangle%A_Index%_vect1_x
         y_m := sector1_triangle%A_Index%_vect1_y
         z_m := sector1_triangle%A_Index%_vect1_z
         u_m := sector1_triangle%A_Index%_vect1_u
         v_m := sector1_triangle%A_Index%_vect1_v
         DllCall("opengl32.dll\glTexCoord2f", Float, u_m, Float, v_m)
         DllCall("opengl32.dll\glVertex3f", Float, x_m, Float, y_m, Float, z_m)

         x_m := sector1_triangle%A_Index%_vect2_x
         y_m := sector1_triangle%A_Index%_vect2_y
         z_m := sector1_triangle%A_Index%_vect2_z
         u_m := sector1_triangle%A_Index%_vect2_u
         v_m := sector1_triangle%A_Index%_vect2_v
         DllCall("opengl32.dll\glTexCoord2f", Float, u_m, Float, v_m)
         DllCall("opengl32.dll\glVertex3f", Float, x_m, Float, y_m, Float, z_m)

         x_m := sector1_triangle%A_Index%_vect3_x
         y_m := sector1_triangle%A_Index%_vect3_y
         z_m := sector1_triangle%A_Index%_vect3_z
         u_m := sector1_triangle%A_Index%_vect3_u
         v_m := sector1_triangle%A_Index%_vect3_v
         DllCall("opengl32.dll\glTexCoord2f", Float, u_m, Float, v_m)
         DllCall("opengl32.dll\glVertex3f", Float, x_m, Float, y_m, Float, z_m)

      DllCall("opengl32.dll\glEnd")
   }

   DllCall("gdi32.dll\SwapBuffers", UInt, hDC)

   Return 1

}




KillGLWindow()
{

   Global

   If fullscreen
   {
      DllCall("ChangeDisplaySettings", UInt, 0, UInt, 0)
      DllCall("ShowCursor", Int, 1)
   }

   If hRC
   {
      If !DllCall("opengl32.dll\wglMakeCurrent", UInt, 0, UInt, 0)
         MsgBox, Release of DC and RC failed.`nError: %A_LastError%

      If !DllCall("opengl32.dll\wglDeleteContext", UInt, hRC)
         MsgBox, Release rendering context failed.`nError: %A_LastError%
   }

   If hDC
   {
      If !DllCall("ReleaseDC", UInt, hWnd, UInt, hDC)
         MsgBox, Release device context failed.`nError: %A_LastError%
   }

   If hWnd
   {
      If !DllCall("DestroyWindow", UInt, hWnd)
         MsgBox, Could not release hWnd.`nError: %A_LastError%
   }

   If ATOM
   {
      If !DllCall("UnregisterClass", UInt, &lpszClassName, UInt, hInstance)
         MsgBox, Could not unregister class.`nError: %A_LastError%
   }

   hInstance := 0
   hWnd := 0
   ATOM := 0
   hDC := 0
   hRC := 0
}




CreateGLWindow(title, width, height, bits)
{

   Global

   VarSetCapacity(wc, 40, 0)
   VarSetCapacity(WindowRect, 16, 0)
   VarSetCapacity(pfd, 40, 0)

   NumPut(0, WindowRect, 0, "Int")
   NumPut(0, WindowRect, 4, "Int")
   NumPut(width, WindowRect, 8, "Int")
   NumPut(height, WindowRect, 12, "Int")

   Style := CS_HREDRAW | CS_VREDRAW | CS_OWNDC
   lpfnWndProc := RegisterCallback("WndProc", "", 4)
   cbClsExtra := 0
   cbWndExtra := 0
   hInstance := DllCall("GetModuleHandle", UInt, 0)
   hbrBackground := 0
   hCursor := DllCall("LoadCursor", UInt, 0, UInt, IDC_ARROW)
   hIcon := DllCall("LoadIcon", UInt, 0, UInt, IDI_APPLICATION)
   lpszMenuName := 0

   NumPut(Style, wc, 0, "UInt")
   NumPut(lpfnWndProc, wc, 4, "UInt")
   NumPut(cbClsExtra, wc, 8, "UInt")
   NumPut(cbWndExtra, wc, 12, "UInt")
   NumPut(hInstance, wc, 16, "UInt")
   NumPut(hIcon, wc, 20, "UInt")
   NumPut(hCursor, wc, 24, "UInt")
   NumPut(hbrBackground, wc, 28, "UInt")
   NumPut(&lpszMenuName, wc, 32, "UInt")
   NumPut(&lpszClassName, wc, 36, "UInt")

   ATOM := DllCall("RegisterClass", UInt, &wc)
   If !ATOM
   {
      MsgBox, Failed to register class.`nError: %A_LastError%
      ExitApp
   }

   If fullscreen
   {
      ; DEVMODE size: 156 ANSI, 220 UNICODE
      VarSetCapacity(dmScreenSettings, 156, 0)

      dmFields := DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT

      NumPut(156, dmScreenSettings, 0, "UShort")

      Result := DllCall("EnumDisplaySettings", UInt, 0, UInt, 0, UInt, &dmScreenSettings)

      NumPut(width, dmScreenSettings, 108, "UInt")
      NumPut(height, dmScreenSettings, 112, "UInt")
      NumPut(bits, dmScreenSettings, 104, "UInt") ;bits
      NumPut(dmFields, dmScreenSettings, 40, "UInt")

      Result := DllCall("ChangeDisplaySettings", UInt, &dmScreenSettings, UInt, CDS_FULLSCREEN)
      If Result != %DISP_CHANGE_SUCCESSFUL%
      {
         MsgBox,4, Error, The requested fullscreen mode is not supported by`nyour video card. Use windowed mode instead?
         IfMsgBox Yes
            fullscreen := 0
         Else
         {
            ; Let the user know the program is closing
            MsgBox, The program will now close.
            ExitApp
         }
      }
   }

   If fullscreen
   {
      dwExStyle := WS_EX_APPWINDOW
      dwStyle := WS_POPUP
      DllCall("ShowCursor", Int, 0)
   }
   Else
   {
      dwExStyle := WS_EX_APPWINDOW | WS_EX_WINDOWEDGE
      dwStyle := WS_OVERLAPPEDWINDOW
   }

   DllCall("AdjustWindowRectEx", UInt, &WindowRect, UInt, dwStyle, UInt, 0, UInt, dwExStyle)

   hWnd := DllCall("CreateWindowEx", UInt, dwExStyle
               , UInt, &lpszClassName
               , "Str", title
               , UInt, dwStyle | WS_CLIPSIBLINGS | WS_CLIPCHILDREN
               , Int, 0
               , Int, 0
               , Int, NumGet(WindowRect, 8, "Int")-NumGet(WindowRect, 0, "Int")
               , Int, NumGet(WindowRect, 12, "Int")-NumGet(WindowRect, 4, "Int")
               , UInt, 0
               , UInt, 0
               , UInt, hInstance
               , UInt, 0
               , UInt)
   If !hWnd
   {
      MsgBox, Window creation error.`nError: %A_LastError%
      ExitApp
   }

   dwFlags := PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER

   NumPut(40, pfd, 0, "UShort")
   NumPut(1, pfd, 2, "UShort")
   NumPut(dwFlags, pfd, 4, "UInt")
   NumPut(PFD_TYPE_RGBA, pfd, 8, "UChar")
   NumPut(bits, pfd, 9, "UChar")
   NumPut(16, pfd, 23, "UChar")
   NumPut(PFD_MAIN_PLANE, pfd, 26, "UChar")

   hDC := DllCall("GetDC", UInt, hWnd)
   If !hDC
   {
      MsgBox, Can't create GL device context.`nError: %A_LastError%
      ExitApp
   }

   PixelFormat := DllCall("gdi32.dll\ChoosePixelFormat", UInt, hDC, UInt, &pfd)
   If !PixelFormat
   {
      MsgBox, Can't find a suitable pixel format.`nError: %A_LastError%
      ExitApp
   }

   If !DllCall("gdi32.dll\SetPixelFormat", UInt, hDC, UInt, PixelFormat, UInt, &pfd)
   {
      MsgBox, Can't set the pixel format.`nError: %A_LastError%
      ExitApp
   }

   hRC := DllCall("opengl32.dll\wglCreateContext", UInt, hDC)
   If !hRC
   {
      MsgBox, Can't create GL rendering context.`nError: %A_LastError%
      ExitApp
   }

   If !DllCall("opengl32.dll\wglMakeCurrent", UInt, hDC, UInt, hRC)
   {
      MsgBox, Can't activate the GL rendering context.`nError: %A_LastError%
      ExitApp
   }

   DllCall("ShowWindow", UInt, hWnd, Int, SW_SHOW)
   DllCall("SetForegroundWindow", UInt, hWnd)
   DllCall("SetFocus", UInt, hWnd)
   ReSizeGLScene()

   If !InitGL()
   {
      MsgBox, Initialization failed.
      ExitApp
   }

   Return 1

}




WndProc(hwnd, uMsg, wParam, lParam)
{

   Global

   If uMsg = %WM_ACTIVATE%
   {
      If !(wParam >> 16)
         active := 1
      Else
         active := 0

      Return 0
   }

   If uMsg = %WM_SYSCOMMAND%
   {
      If wParam = %SC_SCREENSAVE%
         Return 0

      If wParam = %SC_MONITORPOWER%
         Return 0
   }

   If uMsg = %WM_CLOSE%
   {
      exit := 1
      Return 0
   }

   If uMsg = %WM_SIZE%
   {
      width := lParam & 0x0ffff
      height := lParam >> 16
      ReSizeGLScene()
      Return 0
   }

   Return DllCall("DefWindowProc", UInt, hwnd, UInt, uMsg, UInt, wParam, UInt, lParam)

}




WinMain()
{

   Global

   MsgBox, 4, Start Fullscreen?, Would you like to run in fullscreen mode?
   IfMsgBox No
      fullscreen := 0

   CreateGLWindow("Nehe's First Polygon Tutorial", 640, 480, 16)

   Loop
   {
      If F1
      {
         KillGLWindow()
         F1 := 0
         fullscreen := !fullscreen
         CreateGLWindow("Nehe's First Polygon Tutorial", 640, 480, 16)
      }

      If active
      If !DrawGLScene()
         Break

      If exit
         Break
   }

   ExitApp

}

; ==============================================================================================

Esc::PostMessage, %WM_CLOSE%, 0, 0,, ahk_id %hWnd%
F1::F1++

*Up::
xpos := xpos - (sin(heading*piover180) * 0.05)
zpos := zpos - (cos(heading*piover180) * 0.05)
If walkbiasangle >= 359.0
   walkbiasangle := 0
Else
   walkbiasangle := walkbiasangle + 10
walkbias := sin(walkbiasangle * piover180)/20.0
Return

*Down::
xpos := xpos + (sin(heading*piover180) * 0.05)
zpos := zpos + (cos(heading*piover180) * 0.05)
If walkbiasangle <= 1.0
   walkbiasangle := 359.0
Else
   walkbiasangle := walkbiasangle - 10
walkbias := sin(walkbiasangle * piover180)/20.0
Return

*Right::
heading := heading - 1.0
yrot := heading
Return

*Left::
heading := heading + 1.0
yrot := heading
Return

*PgDn::lookupdown := lookupdown - 1.0
*PgUp::lookupdown := lookupdown + 1.0

*f::
filter++
If filter >2
  filter := 0
Return








Exit:
KillGLWindow()

If hOpenGL
   DllCall("FreeLibrary", UInt, hOpenGL)
If hGlu32
   DllCall("FreeLibrary", UInt, hGlu32)
If hGdi32
   DllCall("FreeLibrary", UInt, hGdi32)
ExitApp
Back to top
holomind



Joined: 11 Mar 2006
Posts: 299
Location: Munich, Germany

PostPosted: Sun Apr 27, 2008 11:14 pm    Post subject: Reply with quote

Zippo() wrote:
I'm pretty sure I got all of the constants from gl.h and glu.h. The Gdi constants are needed but I'm currently trying to collect the ones I see mentioned in tutorials. When I get a decent list I'll update one of the include file.


the link above to the .h file contains many gl-constants.
ttp://www.khronos.org/registry/gles/api/1.0/gl.h


The following might work... (glTexImage2D Documentation )
Code:

http://msdn2.microsoft.com/en-us/library/ms537140(VS.85).aspx


Code:

glGenTextures(1,&Texture);            // Allocate space for texture
glBindTexture(GL_TEXTURE_2D,Texture); // Set our Tex handle as current
lpszName := "path/to/image.bmp"
hBmp := DllCall("LoadImage", UInt, 0, UInt, &lpszName, UInt, IMAGE_BITMAP, Int, 0, Int, 0, UInt, LR_LOADFROMFILE | LR_CREATEDIBSECTION)
glTexImage2D( Texture, 0, 512, 512 , 0, GL_BGRA_EXT, GL_BITMAP, hBmp ); 

glBegin() ;
; draw some vectors, which will use the Texture of glBindTexture()
glEnd() ;


the texture stays in memory, so if you have different textures, you can switch the "brush" simply by calling glBindTexture(..., Texture-Nr ). And all Following Vectors in glBegin()...glEnd() will use this texture.

The code above is Pseudocode, but might be near on a working version

P.S. Had the same idea as the other Post with the Doom-Demo, but the version in the Doom is real code Wink Thanks for the tipp with DllCall LoadImage..., I post my version also, so others understand better how this LoadImage thing works.

I am amazed by the Doom-Demo, how to do this script it in so short time.. now we only need somebody to translate the DLL-Calls into the Wrapper-Functions to make the code more readable and compatible to other NeHe examples.

If we continue with the NeHe example implementation in AHK, we can post it on their website as AHK-Portation Wink


Last edited by holomind on Mon Apr 28, 2008 12:02 am; edited 2 times in total
Back to top
View user's profile Send private message Visit poster's website
holomind



Joined: 11 Mar 2006
Posts: 299
Location: Munich, Germany

PostPosted: Sun Apr 27, 2008 11:55 pm    Post subject: Reply with quote

@zippo: you seem to understand ahk + gdi/mfc + opengl very good.

do you have an idea how to port the Window2BMP -Function to AHK,
http://community.thinbasic.com/index.php?topic=1690.msg12291#msg12291

Code:
sub Window2BMP( whandle as dword )
    if whandle = 0 then exit sub
 
    LOCAL hBMPDC, hMemDC, hMemBMP AS dword
    LOCAL rc AS RECT
    LOCAL bm AS BITMAP
    LOCAL bmi AS BITMAPINFO
    LOCAL bmpFileHdr AS BITMAPFILEHEADER
    LOCAL bmpInfoHdr AS BITMAPINFOHEADER
    LOCAL sBmpFile AS STRING
 
    GetWindowRect (whandle, rc)
 
    hBMPDC = CreateDC( "DISPLAY", "", "", "" )
    hMemDC = CreateCompatibleDC( hBMPDC )
    bmi.bmiHeader.biSize = SIZEOF( bmi.bmiHeader )
    bmi.bmiHeader.biWidth = ( rc.nRight - rc.nLeft )
    bmi.bmiHeader.biHeight = ( rc.nBottom - rc.nTop )
    bmi.bmiHeader.biPlanes = 1
    bmi.bmiHeader.biBitCount = 24
    bmi.bmiHeader.biCompression = %BI_RGB
 
    hMemBmp = CreateDIBSection( hMemDC, bmi, %DIB_RGB_COLORS, 0, 0, 0 )
    GlobalLock (hMemBmp)
    SelectObject (hMemDC, hMemBmp)
 
    GetObject (hMemBmp, SIZEOF( bm ), varptr(bm))
   
    BitBlt (hMemDC, 0, 0, bm.bmWidth, bm.bmHeight, hBMPDC, rc.nLeft, rc.nTop, %SRCCOPY)
    bmpFileHdr.bfType = CVI( "BM" )
    bmpFileHdr.bfSize = LEN( bmpFileHdr ) + LEN( bmpInfoHdr ) + bm.bmWidthBytes * bm.bmHeight
    bmpFileHdr.bfOffBits = 54
    bmpInfoHdr.biSize = 40
    bmpInfoHdr.biWidth = bm.bmWidth
    bmpInfoHdr.biHeight = bm.bmHeight
    bmpInfoHdr.biPlanes = 1
    bmpInfoHdr.biBitCount = 24
    bmpInfoHdr.biSizeImage = 54 + bm.bmWidthBytes * bm.bmHeight
 
    local sBuffer as string
    local bmptr as dword = bm.bmBits
    sBuffer = PEEK$(VARPTR(bmpFileHdr), SIZEOF(bmpFileHdr))+PEEK$(VARPTR(bmpInfoHdr), SIZEOF(bmpInfoHdr))+PEEK$( bmptr, bm.bmWidthBytes * bm.bmHeight )
    'tbgl_setWindowTitle(hWnd, "Dim:"+STR$(bm.bmWidth)+STR$(bm.bmHeight)+STR$(rc.nRight - rc.nLeft)+STR$(rc.nBottom - rc.nTop))
    'sbuffer = tbgl_getwindowbmp(whandle)
    tbgl_MakeTexture sBuffer, %TBGL_FILE_BMP, bm.bmWidth, bm.bmHeight, 1, %TBGL_TEX_MIPMAP, 16
 
    ' -- Cleanup
    DeleteDC (hBMPDC)
    DeleteDC (hMemDC)
    GlobalUnlock (hMemBmp)
    DeleteObject (hMemBmp)
end sub


I dont understand the Peek$ Part of the script, and whats going on there.
also do you have an idea to even do this shorter with similar DllCalls like the really nice DllCall(LoadImage) ? the tbgl_* commands are very similar to the gl* commands. its a kind of wrapper to make the syntax easier for thinBasic.

This Window2BMP allows to Put an hDC into the Texture, which means you can store the Desktop (=Screenshot) or any other Window with DllCall(Printwindow) into a Texture.

Greetings and thanks for you cool Doom-Demo script, which contains many new opengl/ahk things i have learned from it.

P.S. about the GDI-Wrapper-File, i have discussed with Chris (=Programmer of AHK-Engine) about the distribution of the file and it would be no problem to put it into the installer-Package of AHK if we want to. Then in a script one could simple write #include GL or similar.

Another idea would be to put an "auto-updater" ahk-script into the distribution, which downloads some includefile from an "trusted" www.autohotkey.net account (e.g the one of chris? or some other forum admin one can trust) and get the latest "wrapper"-files automatically.

it should be really easy to use them, and downloading them manually is not so comfortable.
Back to top
View user's profile Send private message Visit poster's website
SomeGuy



Joined: 21 Apr 2008
Posts: 94
Location: somewhere

PostPosted: Mon Apr 28, 2008 3:52 am    Post subject: Reply with quote

holomind wrote:
Code:
sBuffer = PEEK$(VARPTR(bmpFileHdr), SIZEOF(bmpFileHdr))+PEEK$(VARPTR(bmpInfoHdr), SIZEOF(bmpInfoHdr))+PEEK$( bmptr, bm.bmWidthBytes * bm.bmHeight )
   

I dont know thin basic at all, but I am assuming that the + = concatenation....and that the PEEK$() is comparable to numget()
Back to top
View user's profile Send private message
Zippo()
Guest





PostPosted: Mon Apr 28, 2008 7:54 am    Post subject: Reply with quote

holomind wrote:
@zippo: you seem to understand ahk + gdi/mfc + opengl very good.

do you have an idea how to port the Window2BMP -Function to AHK,
http://community.thinbasic.com/index.php?topic=1690.msg12291#msg12291


Know nothing about thinBasic (or MFC for that matter), but it looks like he is just copying the outline of a bitmap file structure into a buffer (file header, bitmap info header and then the image data itself).

The magic to do that from AHK would be CopyMemory. Fill out the structures with NumPut/etc, then CopyMemory it into one pile in a variable.

But aren't there already a few screenshot scripts posted that could be modified? As far as a 1-hit function to automatically save a bitmap, there isn't one that I know of.

holomind wrote:
P.S. about the GDI-Wrapper-File, i have discussed with Chris (=Programmer of AHK-Engine) about the distribution of the file and it would be no problem to put it into the installer-Package of AHK if we want to. Then in a script one could simple write #include GL or similar.

Another idea would be to put an "auto-updater" ahk-script into the distribution, which downloads some includefile from an "trusted" www.autohotkey.net account (e.g the one of chris? or some other forum admin one can trust) and get the latest "wrapper"-files automatically.

it should be really easy to use them, and downloading them manually is not so comfortable.

I'm still having trouble getting into the wrapper thing. But I'll look at the header files and see how much of an overall PITA it would be. If it's not too bad I might wrap it up.

And by the way... I'm using the new gl.h and glu.h files from the Server 2008 SDK. If you find constants defined in other header files that aren't in the files I posted, it might be because MS commented them out for some reason or another in the current files. I didn't include anything that was commented out. Seemed the safest thing to do...
Back to top
holomind



Joined: 11 Mar 2006
Posts: 299
Location: Munich, Germany

PostPosted: Mon Apr 28, 2008 10:56 am    Post subject: Reply with quote

@zippo: thanks for the explanaition, i will try CopyMemory. i guess this should be enough to port the Window2BMP from thinbasic to ahk, and do some experiments with textures. (like copying window-contents of a window into a texture for a 3d/opengl-version of my real-expose-clone).

perhaps the following technique is the fastest way to do it, as it uses DMA (Direct-memory-Access) to do the Copy of Pixeldata, in hardware instead of copying all through the "slow" CPU.

http://www.songho.ca/opengl/gl_pbo.html
Back to top
View user's profile Send private message Visit poster's website
holomind



Joined: 11 Mar 2006
Posts: 299
Location: Munich, Germany

PostPosted: Mon Apr 28, 2008 10:32 pm    Post subject: Reply with quote

IsNull wrote:
In these examples, opengl binds a new window to himself.


Here is an example how to do it with a Child-Window. As the OpenGL is a normal window (or a control ...) it can be embeded into another window.
http://irrlicht.sourceforge.net/tut014.html

Code:
// create window to put irrlicht in



   HWND hIrrlichtWindow =
    CreateWindow("BUTTON", "", WS_CHILD | WS_VISIBLE | BS_OWNERDRAW,

         50, 80, 320, 220, hWnd, NULL, hInstance, NULL);


Also each Button in a Window has its own hdc. not only windows have hdcs, but controls in general.
Back to top
View user's profile Send private message Visit poster's website
Zippo



Joined: 21 Apr 2006
Posts: 56
Location: East Coast, USA

PostPosted: Tue Apr 29, 2008 9:55 am    Post subject: Reply with quote

Like I said, I took a look at wrapping the DllCalls. It didn't look overly complicated, so I took a stab at it. That is some mind-numbing stuff right there. A few macros and a couple of hours and this is what I have.

I'd like people to test it all to make sure there aren't any major problems with how I went about doing things. I wrapped every single function (at least to the best of my knowledge) from both gl.h and glu.h. You should now be able to call all of them like you see them in the tutorials.

Haven't touched the gdi calls yet. I might get around to it if what I have done so far isn't too screwed up Very Happy

Here is the Doom demo thing with the new wrappers:
Code:
#include winders.ahk
#include gl.ahk
#include gl_functions.ahk
#include glu_functions.ahk
#include main_window.ahk

OnExit, Exit

hOpenGL    := DllCall("LoadLibrary", Str, "opengl32.dll")
hGlu32     := DllCall("LoadLibrary", Str, "glu32.dll")
gdi32      := DllCall("LoadLibrary", Str, "gdi32.dll")

filter       := 0
piover180    := 0.0174532925
filter      := 1
walkbias    := 0
walkbiasangle   := 0
lookupdown   := 0.0
z       := 0.0
tri       := 1
vec       := 1
Count       := 1
xpos       := 0
zpos       := 0
heading    := 0

F1       := 0

sector1 =
(LTrim Join

   -3.0,0.0,-3.0,0.0,6.0,
   -3.0,0.0,3.0,0.0,0.0,
    3.0,0.0,3.0,6.0,0.0,
   -3.0,0.0,-3.0,0.0,6.0,
     3.0,0.0,-3.0,6.0,6.0,
     3.0,0.0,3.0,6.0,0.0,
   -3.0,1.0,-3.0,0.0,6.0,
   -3.0,1.0,3.0,0.0,0.0,
    3.0,1.0,3.0,6.0,0.0,
   -3.0,1.0,-3.0,0.0,6.0,
    3.0,1.0,-3.0,6.0,6.0,
    3.0,1.0,3.0,6.0,0.0,
   -2.0,1.0,-2.0,0.0,1.0,
   -2.0,0.0,-2.0,0.0,0.0,
   -0.5,0.0,-2.0,1.5,0.0,
   -2.0,1.0,-2.0,0.0,1.0,
   -0.5,1.0,-2.0,1.5,1.0,
   -0.5,0.0,-2.0,1.5,0.0,
    2.0,1.0,-2.0,2.0,1.0,
    2.0,0.0,-2.0,2.0,0.0,
    0.5,0.0,-2.0,0.5,0.0,
    2.0,1.0,-2.0,2.0,1.0,
    0.5,1.0,-2.0,0.5,1.0,
    0.5,0.0,-2.0,0.5,0.0,
   -2.0,1.0,2.0,2.0,1.0,
   -2.0,0.0,2.0,2.0,0.0,
   -0.5,0.0,2.0,0.5,0.0,
   -2.0,1.0,2.0,2.0,1.0,
   -0.5,1.0,2.0,0.5,1.0,
   -0.5,0.0,2.0,0.5,0.0,
    2.0,1.0,2.0,2.0,1.0,
    2.0,0.0,2.0,2.0,0.0,
    0.5,0.0,2.0,0.5,0.0,
    2.0,1.0,2.0,2.0,1.0,
    0.5,1.0,2.0,0.5,1.0,
    0.5,0.0,2.0,0.5,0.0,
   -2.0,1.0,-2.0,0.0,1.0,
   -2.0,0.0,-2.0,0.0,0.0,
   -2.0,0.0,-0.5,1.5,0.0,
   -2.0,1.0,-2.0,0.0,1.0,
   -2.0,1.0,-0.5,1.5,1.0,
   -2.0,0.0,-0.5,1.5,0.0,
   -2.0,1.0,2.0,2.0,1.0,
   -2.0,0.0,2.0,2.0,0.0,
   -2.0,0.0,0.5,0.5,0.0,
   -2.0,1.0,2.0,2.0,1.0,
   -2.0,1.0,0.5,0.5,1.0,
   -2.0,0.0,0.5,0.5,0.0,
    2.0,1.0,-2.0,0.0,1.0,
    2.0,0.0,-2.0,0.0,0.0,
    2.0,0.0,-0.5,1.5,0.0,
    2.0,1.0,-2.0,0.0,1.0,
    2.0,1.0,-0.5,1.5,1.0,
    2.0,0.0,-0.5,1.5,0.0,
    2.0,1.0,2.0,2.0,1.0,
    2.0,0.0,2.0,2.0,0.0,
    2.0,0.0,0.5,0.5,0.0,
    2.0,1.0,2.0,2.0,1.0,
    2.0,1.0,0.5,0.5,1.0,
    2.0,0.0,0.5,0.5,0.0,
   -0.5,1.0,-3.0,0.0,1.0,
   -0.5,0.0,-3.0,0.0,0.0,
   -0.5,0.0,-2.0,1.0,0.0,
   -0.5,1.0,-3.0,0.0,1.0,
   -0.5,1.0,-2.0,1.0,1.0,
   -0.5,0.0,-2.0,1.0,0.0,
    0.5,1.0,-3.0,0.0,1.0,
    0.5,0.0,-3.0,0.0,0.0,
    0.5,0.0,-2.0,1.0,0.0,
    0.5,1.0,-3.0,0.0,1.0,
    0.5,1.0,-2.0,1.0,1.0,
    0.5,0.0,-2.0,1.0,0.0,
   -0.5,1.0,3.0,0.0,1.0,
   -0.5,0.0,3.0,0.0,0.0,
   -0.5,0.0,2.0,1.0,0.0,
   -0.5,1.0,3.0,0.0,1.0,
   -0.5,1.0,2.0,1.0,1.0,
   -0.5,0.0,2.0,1.0,0.0,
    0.5,1.0,3.0,0.0,1.0,
    0.5,0.0,3.0,0.0,0.0,
    0.5,0.0,2.0,1.0,0.0,
    0.5,1.0,3.0,0.0,1.0,
    0.5,1.0,2.0,1.0,1.0,
    0.5,0.0,2.0,1.0,0.0,
   -3.0,1.0,0.5,1.0,1.0,
   -3.0,0.0,0.5,1.0,0.0,
   -2.0,0.0,0.5,0.0,0.0,
   -3.0,1.0,0.5,1.0,1.0,
   -2.0,1.0,0.5,0.0,1.0,
   -2.0,0.0,0.5,0.0,0.0,
   -3.0,1.0,-0.5,1.0,1.0,
   -3.0,0.0,-0.5,1.0,0.0,
   -2.0,0.0,-0.5,0.0,0.0,
   -3.0,1.0,-0.5,1.0,1.0,
   -2.0,1.0,-0.5,0.0,1.0,
   -2.0,0.0,-0.5,0.0,0.0,
    3.0,1.0,0.5,1.0,1.0,
    3.0,0.0,0.5,1.0,0.0,
    2.0,0.0,0.5,0.0,0.0,
    3.0,1.0,0.5,1.0,1.0,
    2.0,1.0,0.5,0.0,1.0,
    2.0,0.0,0.5,0.0,0.0,
    3.0,1.0,-0.5,1.0,1.0,
    3.0,0.0,-0.5,1.0,0.0,
    2.0,0.0,-0.5,0.0,0.0,
    3.0,1.0,-0.5,1.0,1.0,
    2.0,1.0,-0.5,0.0,1.0,
    2.0,0.0,-0.5,0.0,0.0
)


MsgBox, 4, Start Fullscreen?, Would you like to run in fullscreen mode?
IfMsgBox No
   fullscreen := 0

CreateGLWindow("Nehe's First Polygon Tutorial", 640, 480, 16)

If !InitGL()
   ExitApp

Loop
{
   If F1
   {
      KillGLWindow()
      F1 := 0
      fullscreen := !fullscreen
      CreateGLWindow("Nehe's First Polygon Tutorial", 640, 480, 16)
   }

   If active
   If !DrawGLScene()
      Break

   If exit
      Break
}

ExitApp




SetupWorld()
{

   Global

   Loop, Parse, sector1, `,
   {
      If Count = 1
         sector1_triangle%tri%_vect%vec%_x := A_LoopField
      If Count = 2
         sector1_triangle%tri%_vect%vec%_y := A_LoopField
      If Count = 3
         sector1_triangle%tri%_vect%vec%_z := A_LoopField
      If Count = 4
         sector1_triangle%tri%_vect%vec%_u := A_LoopField
      If Count = 5
      {
         sector1_triangle%tri%_vect%vec%_v := A_LoopField
         Count := 1
         vec++
         If vec = 4
         {
            vec := 1
            tri++
         }
         Continue
      }

      Count++
   }

   tri := tri - 1
   Return 1


}




LoadImage()
{

   Global

   DIB_RGB_COLORS := 0

   VarSetCapacity(imgInfo, 24, 0)
   VarSetCapacity(texture, 12, 0)
   VarSetCapacity(array, 20, 0)

   glGenTextures(3, &texture)
   lpszName = %A_ScriptDir%\MUD.bmp
   hBmp := DllCall("LoadImage", UInt, 0, UInt, &lpszName, UInt, IMAGE_BITMAP, Int, 0, Int, 0, UInt, LR_LOADFROMFILE | LR_CREATEDIBSECTION)

   ; BITMAP size: 24
   DllCall("gdi32.dll\GetObject", UInt, hBmp, UInt, 24, UInt, &imgInfo)
   bmWidth := NumGet(imgInfo, 4, "Int")
   bmHeight := NumGet(imgInfo, 8, "Int")
   bmBits := NumGet(imgInfo, 20, "UInt")

   glBindTexture(GL_TEXTURE_2D, NumGet(texture, 0, "UInt"))
   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST)
   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)
   glTexImage2D(GL_TEXTURE_2D, 0, 3, bmWidth, bmHeight, 0, GL_BGR_EXT, GL_UNSIGNED_BYTE, bmBits)

   glBindTexture(GL_TEXTURE_2D, NumGet(texture, 4, "UInt"))
   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)
   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)
   glTexImage2D(GL_TEXTURE_2D, 0, 3, bmWidth, bmHeight, 0, GL_BGR_EXT, GL_UNSIGNED_BYTE, bmBits)

   glBindTexture(GL_TEXTURE_2D, NumGet(texture, 8, "UInt"))
   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)
   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_NEAREST)
   glTexImage2D(GL_TEXTURE_2D, 0, 3, bmWidth, bmHeight, 0, GL_BGR_EXT, GL_UNSIGNED_BYTE, bmBits)

   Return 1

}




InitGL()
{

   Global

   If !LoadImage()
      Return 0

   glEnable(GL_TEXTURE_2D)
   glBlendFunc(GL_SRC_ALPHA, GL_ONE)
   glClearColor(0.0, 0.0, 0.0, 0.0)
   glClearDepth(1.0)
   glDepthFunc(GL_LESS)
   glEnable(GL_DEPTH_TEST)
   glShadeModel(GL_SMOOTH)
   glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST)

   SetupWorld()