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
holomind



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

PostPosted: Fri Apr 25, 2008 9:56 am    Post subject: Reply with quote

i prefer using the wrappers and "simulate" dllcalls as "native" AHK-Functions. I dont like the way to write DllCll at each line, it distracts too much and is not neccessary. as i stated above, the most CPU is spent inside the dll, so a bit more wrapping does not hurt performance (much).
also i dont like to define UInt etc. in each statement, makes it less readable. but that can be discusses, because some like typed and strict languages. On my side i perferere short simple code and prefer the ahk-syntax vs. DllCalls-Syntax, which looks more like a Hack.

Also the Wrapper has the purpose to smooth copy-pasting code from c-code examples or thinbasic code in this case. You can find way more examples written in c in opengl than you will find in AHK. (because we just start this section) Wink

In my Expose-Clone i used the wrappers so that i can use VisualBasic examples easier. (I learn best by reusing and modifying examples, which i find in forums)
Back to top
View user's profile Send private message Visit poster's website
engunneer



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

PostPosted: Fri Apr 25, 2008 4:26 pm    Post subject: Reply with quote

A few note:

This is really awesome. I've been toying with opengl for a while, but I am an engineer, not a programmer, so I didn't get very far.

I moved the topic to S&F as requested, and edited the title a touch. ~Zippo, please feel free to edit it as needed.

I think holomind makes a good point. I am already in the process of wrapping your functions (mostly just renaming to standard library format) for my personal use, but I think this could be developed into a GL stnadard library file. If we can manage to do it in a way that can include this other language (that I want to look into more), then I see no harm. I expect the main difference will be in function names anyway, so they can always write a mini wrapper to make the names how they want.

Can someone help explain OpenGL to me? does it remember all your objects, or do you have to redraw every frame, even if they don't move?
_________________
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
Rhys



Joined: 17 Apr 2007
Posts: 707
Location: Florida

PostPosted: Fri Apr 25, 2008 4:31 pm    Post subject: Reply with quote

I need to look into it more as well, I'd like to know how hard it would be to create an interactive scene (pyramid always points to mouse or objects that react to clicking or dragging, etc.).
_________________
[Join IRC!]
Back to top
View user's profile Send private message
holomind



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

PostPosted: Fri Apr 25, 2008 6:38 pm    Post subject: Reply with quote

engunneer wrote:
Can someone help explain OpenGL to me? does it remember all your objects, or do you have to redraw every frame, even if they don't move?


OpenGL is a Statemachine, which means is keeps the same until you change anything. even Objects keep at the same position. So you can timebased say rotate by 10degree on x-axis or move 10virtual-meters to the left. and then simply say "redraw" (in opengl-syntax) .

you should try the examples (and also the bonus-pack) on the thinbasic website. which helps understanding opengl a lot.

also feel free to post comments in the thinbasic, opengl section. (i am doing cross-advertising this forums to exchange knowledge).

My personal experience is, that thinbasic is a good way to learn opengl by examples. and if we ported some scripts for AHK, we can have it here also. Also the TBGL-Documentation is not too bad.

http://psch.thinbasic.com/tutorials_basic_intro.html

a manual is here: (see the attachment of the linked post)
http://community.thinbasic.com/index.php?topic=1690.msg12342#msg12342

greetings
Holomind
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: Fri Apr 25, 2008 7:07 pm    Post subject: Reply with quote

engunneer wrote:
I think holomind makes a good point. I am already in the process of wrapping your functions (mostly just renaming to standard library format) for my personal use, but I think this could be developed into a GL stnadard library file. If we can manage to do it in a way that can include this other language (that I want to look into more), then I see no harm. I expect the main difference will be in function names anyway, so they can always write a mini wrapper to make the names how they want.


perhaps this script helps you to convert a wrapper class automatically:
should also be easy to convert all gl-functions from a .h header file
http://www.autohotkey.com/forum/viewtopic.php?t=13171

Dont know where to find a header file for the Dll in the moment, also it perhaps is easy enough to port this 10-20 essential opengl-functions manually.
Back to top
View user's profile Send private message Visit poster's website
wibumba (not logged in)
Guest





PostPosted: Fri Apr 25, 2008 11:08 pm    Post subject: Reply with quote

error wrote:

Release of DC and RC failed.
Can't activate the GL rendering context.
Could not unregister class. 1411

[/quote]
Back to top
holomind



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

PostPosted: Sat Apr 26, 2008 1:12 am    Post subject: Reply with quote

I did some first Wrapping, and it works.

download all needed files (AHK_OpenGL.zip) (only ahk-scripts) and run "gl_demo1.ahk"


i excluded all extra-functions and reduced it to variable definition and drawloop.


Code:
;/////////////////////////////////////////////////////////////////////////////////////////////
#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 %A_ScriptDir%\WINDERS.ahk
#include %A_ScriptDir%\GL.ahk
#include %A_ScriptDir%\gl_helpers.ahk
#include %A_ScriptDir%\gl_dllcall_wrapper.ahk

hInstance := 0
hWnd := 0
hDC := 0
hRC := 0
hOpenGL := 0
hGlu32 := 0
hGdi32 := 0
Escape := 0
F1 := 0
active := 1
fullscreen := 1
lpszClassName := "OpenGL"



;-----------------------------------------
;mod to rotate
fRotation := 10.0
;-----------------------------------------


   WinMain()
   ExitApp

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


DrawGLScene()
{

   Global ;hDC, fRotation
   
;-----------------------------------------
;mod to rotate - IsNulll 
   SetFormat, float, 0.2
   fRotation -= 0.4
;-----------------------------------------

   glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT )

   glTranslatef( -1.5, -0.8, -6.0)


;mod to rotate
   glRotatef (fRotation,0.0,1.0,0.0) 

   glBegin( GL_TRIANGLES)


      glColor3f(  0.0, 0.0, 1.0) ;blau
   glVertex3f( 0.0, 1.0, 0.0) ;oben (vorderes Dreieck)
   glVertex3f( -1.0, -1.0, 1.0) ;links (vorderes Dreieck)
   glVertex3f( 1.0, -1.0, 1.0) ;rechts (vorderes Dreieck)

      glColor3f(  1.0, 0.0, 0.0) ;ROT
   glVertex3f( 0.0, 1.0, 0.0) ;oben (rechtes Dreieck)
   glVertex3f( 1.0, -1.0, 1.0) ;links (rechtes Dreieck)
   glVertex3f( 1.0, -1.0, -1.0) ;rechts (rechtes Dreieck)

      glColor3f(   0.0, 1.0, 0.0) ;Grün
   glVertex3f( 0.0, 1.0, 0.0) ;oben (hinteres Dreieck)
   glVertex3f( 1.0, -1.0, -1.0) ;links (hinteres Dreieck)
   glVertex3f( -1.0, -1.0, -1.0) ;rechts (hinteres Dreieck)

      glColor3f(  1.0, 1.0, 0.0) ;GELB
   glVertex3f( 0.0, 1.0, 0.0) ;oben (linkes Dreieck)
   glVertex3f( -1.0, -1.0, -1.0) ;links (linkes Dreieck)
   glVertex3f( -1.0, -1.0, 1.0) ;rechts (linkes Dreieck)


   glEnd()
   glLoadIdentity()

;************************************


   SwapBuffers( hDC)

   Return 1

}



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

Esc::Escape := !Escape
F1::F1 := !F1


nothing really new, but nicer syntax, looks quite similar to c-code ?
Back to top
View user's profile Send private message Visit poster's website
poetbox



Joined: 07 Jan 2007
Posts: 59

PostPosted: Sat Apr 26, 2008 1:47 am    Post subject: Reply with quote

holomind wrote:
I did some first Wrapping, and it works.

download all needed files (AHK_OpenGL.zip) (only ahk-scripts) and run "gl_demo1.ahk"


i excluded all extra-functions and reduced it to variable definition and drawloop.


Code:
;/////////////////////////////////////////////////////////////////////////////////////////////
#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 %A_ScriptDir%\WINDERS.ahk
#include %A_ScriptDir%\GL.ahk
#include %A_ScriptDir%\gl_helpers.ahk
#include %A_ScriptDir%\gl_dllcall_wrapper.ahk

hInstance := 0
hWnd := 0
hDC := 0
hRC := 0
hOpenGL := 0
hGlu32 := 0
hGdi32 := 0
Escape := 0
F1 := 0
active := 1
fullscreen := 1
lpszClassName := "OpenGL"



;-----------------------------------------
;mod to rotate
fRotation := 10.0
;-----------------------------------------


   WinMain()
   ExitApp

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


DrawGLScene()
{

   Global ;hDC, fRotation
   
;-----------------------------------------
;mod to rotate - IsNulll 
   SetFormat, float, 0.2
   fRotation -= 0.4
;-----------------------------------------

   glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT )

   glTranslatef( -1.5, -0.8, -6.0)


;mod to rotate
   glRotatef (fRotation,0.0,1.0,0.0) 

   glBegin( GL_TRIANGLES)


      glColor3f(  0.0, 0.0, 1.0) ;blau
   glVertex3f( 0.0, 1.0, 0.0) ;oben (vorderes Dreieck)
   glVertex3f( -1.0, -1.0, 1.0) ;links (vorderes Dreieck)
   glVertex3f( 1.0, -1.0, 1.0) ;rechts (vorderes Dreieck)

      glColor3f(  1.0, 0.0, 0.0) ;ROT
   glVertex3f( 0.0, 1.0, 0.0) ;oben (rechtes Dreieck)
   glVertex3f( 1.0, -1.0, 1.0) ;links (rechtes Dreieck)
   glVertex3f( 1.0, -1.0, -1.0) ;rechts (rechtes Dreieck)

      glColor3f(   0.0, 1.0, 0.0) ;Grün
   glVertex3f( 0.0, 1.0, 0.0) ;oben (hinteres Dreieck)
   glVertex3f( 1.0, -1.0, -1.0) ;links (hinteres Dreieck)
   glVertex3f( -1.0, -1.0, -1.0) ;rechts (hinteres Dreieck)

      glColor3f(  1.0, 1.0, 0.0) ;GELB
   glVertex3f( 0.0, 1.0, 0.0) ;oben (linkes Dreieck)
   glVertex3f( -1.0, -1.0, -1.0) ;links (linkes Dreieck)
   glVertex3f( -1.0, -1.0, 1.0) ;rechts (linkes Dreieck)


   glEnd()
   glLoadIdentity()

;************************************


   SwapBuffers( hDC)

   Return 1

}



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

Esc::Escape := !Escape
F1::F1 := !F1


nothing really new, but nicer syntax, looks quite similar to c-code ?

Good。
Back to top
View user's profile Send private message
Zippo



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

PostPosted: Sat Apr 26, 2008 8:09 am    Post subject: Reply with quote

@engunneer: Might wanna check out the Red Book also.

@wibumba: I updated the 1st script a little. It does a little more error reporting now. I suspect you might either need to change the bits and/or the resolution. If that fails you could try disabling anti-aisling on your video card long enough to test it.

@holomind: The OpenGL includes come in the Microsoft SDK. There are not really that many functions total. If you don't want to download the SDK you can probably get a decently recent version by searching Google.
_________________
____________________
Back to top
View user's profile Send private message
holomind



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

PostPosted: Sat Apr 26, 2008 10:36 am    Post subject: Reply with quote

Hi, the redbook looks good, interesting introduction.

i have ported the first example to ahk.
you can download ( ahk_opengl_2.zip ) and run gl_demo2.ahk.

Code:

;/////////////////////////////////////////////////////////////////////////////////////////////
#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 %A_ScriptDir%\WINDERS.ahk
#include %A_ScriptDir%\GL.ahk
#include %A_ScriptDir%\gl_helpers.ahk
#include %A_ScriptDir%\gl_dllcall_wrapper.ahk

hInstance := 0
hWnd := 0
hDC := 0
hRC := 0
hOpenGL := 0
hGlu32 := 0
hGdi32 := 0
Escape := 0
F1 := 0
active := 1
fullscreen := 1
lpszClassName := "OpenGL"



;-----------------------------------------
;mod to rotate
fRotation := 10.0
;-----------------------------------------


   WinMain()
   ExitApp

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

; IMPORTANT: Dont add semicolon directly at command end but leave a space (AHK-Syntax!)
DrawGLScene()
{

   Global ;hDC, fRotation
   
;-----------------------------------------
;mod to rotate - IsNulll 
   SetFormat, float, 0.2
   fRotation -= 0.4
;-----------------------------------------
   ; added because else the polygon is offscreen
   glTranslatef( -0.5, -0.5, -2.0) ;
 
   ; code from redbook, only semicolons fixed
   glClearColor(0.4, 0.4, 0.0, 0.0) ;
   glClear(GL_COLOR_BUFFER_BIT) ;
   glColor3f(1.0, 1.0, 1.0) ;
   glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0) ;
   glBegin(GL_POLYGON) ;
      glVertex3f(0.25, 0.25, 0.0) ;
      glVertex3f(0.75, 0.25, 0.0) ;
      glVertex3f(0.75, 0.75, 0.0) ;
      glVertex3f(0.25, 0.75, 0.0) ;
   glEnd() ;
   glFlush() ;
 
   ; added to stop animation, try to comment this line
   glLoadIdentity()

;************************************

   SwapBuffers( hDC)

   Return 1

}



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

Esc::Escape := !Escape
F1::F1 := !F1


The code from Redbook is used nearly 1:1, i had to make some tweaks to get it working correctly.

a) AHK has a *bad* comment syntax and interprets ; (semicolon) as some kind of command instead of starting the comment directly.
This means you need to add a <space> character before each (semicolon) => this should be fixed in AHK, and turned on with something like "#usetightcomments" or similar. its a pain in the ahk-syntax, and i see no benefit at all adding the space-charakter.

b) i added glLoadIdentity() from the other example, because the rectange would animate otherwise. (perhaps thats what you want later anyways)

c) the rendering was offscreen, so i added glTransformf, to move it into the viewport. => perhaps someone can explain why this is needed. (Perhaps there are some strange gl-calls in the init() which now is in gl_helpers..

Have fun porting other gl-scripts.

In my opinion it would be great if the semicolonbug could be prevented somehow. (but a replace of ";" => " ;" in your code would do the trick.
and a big gl_wrapper.inc with all needed glFunctions. (perhaps put this in a wiki and make it available as downloadable file in regular intervals on an www.autohotkey.net filemanager-folder.

Greetings
Holomind
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: Sat Apr 26, 2008 11:16 am    Post subject: Reply with quote

so a litte variation with color and animation..

Code:
DrawGLScene()
{

   Global ;hDC, fRotation
   
;-----------------------------------------
;mod to rotate - IsNulll 
   SetFormat, float, 0.2
   fRotation += 10
;-----------------------------------------
   ; added because else the polygon is offscreen
   glTranslatef( -0.5, -0.5, -2.0) ;
   glRotatef(fRotation,0.0,1.0,1.0) ;
 
   ; code from redbook, only semicolons fixed
   glClearColor(0.4, 0.4, 0.0, 0.0) ;
   glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT )
   ;glClear(GL_COLOR_BUFFER_BIT) ;
   glColor3f(1.0, 1.0, 1.0) ;
   glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0) ;
   glBegin(GL_POLYGON) ;
   glColor3f(0.0, 1.0, 1.0) ;
      glVertex3f(0.25, 0.25, 0.0) ;
   glColor3f(1.0, 0.5, 0.0) ;
      glVertex3f(0.75, 0.25, 0.0) ;
   glColor3f(1.0, 0.0, 0.5) ;
      glVertex3f(0.75, 0.75, 0.0) ;
   glColor3f(0.0, 0.0, 1.0) ;
      glVertex3f(0.25, 0.75, 0.0) ;

   glEnd() ;
   glFlush() ;
 
   ; added to stop animation, try to comment this line
   glLoadIdentity()

;************************************

   SwapBuffers( hDC)

   Return 1

}


looks much more 3d-ish Wink
Back to top
View user's profile Send private message Visit poster's website
biotech as guest
Guest





PostPosted: Sat Apr 26, 2008 1:11 pm    Post subject: Reply with quote

i guess this makes it possible to use 3d engine with autohotkey like irrlicht 3d engine. the most simplest 3d engine. maybe some of you gurus could try to do it...
Back to top
IsNull



Joined: 10 May 2007
Posts: 64
Location: .switzerland

PostPosted: Sat Apr 26, 2008 1:12 pm    Post subject: Reply with quote

Thx holomind. I think too, we should wrap the functions. If we have a example of ataching textures I'll become really happy Razz

However, I have a next Question:
In these examples, opengl binds a new window to himself. The full window is used by OpenGL. Is it possible to have an area with opengl and a other part for normal AHK-GUI use? See Image below for better understanding:


This would be very usefull.
_________________
http://securityvision.ch
Back to top
View user's profile Send private message
holomind



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

PostPosted: Sat Apr 26, 2008 6:04 pm    Post subject: Reply with quote

IsNull wrote:
Thx holomind. I think too, we should wrap the functions. If we have a example of ataching textures I'll become really happy Razz

However, I have a next Question:
In these examples, opengl binds a new window to himself. The full window is used by OpenGL. Is it possible to have an area with opengl and a other part for normal AHK-GUI use? See Image below for better understanding:

This would be very usefull.


Attaching images should not be too hard. its 2 opengl calls. the hard part is loading the BMP into a DIB, to get the correct format. But there should be functions to do this in the AHK-Forum already. Only need to find the right posts. (similar to the one with saving a screenshot without iview, which uses some tricky function to convert the hdc into a BMP...)

Combining the two windows, should also be possible i guess if the viewport is limited to the first half of the screen. the opengl-window should be a normal window i guess. the mechanism i guess is to simply "draw" the opengl-result over the window at the defined sized. which means if you add controlls to the window they should stay.

some nice opengl-function manual / wiki. (delphy but similar enough to ahk). (in german)
http://wiki.delphigl.com/index.php/OpenGL-Funktionsübersicht

the opgengl constants, the list in our example is not complete. (e.g. GL_BLEND ) is missing...
http://www.khronos.org/registry/gles/api/1.0/gl.h

you can prevent opengl from writing on the full window by defining a smaller viewport:
DllCall("opengl32.dll\glViewport", Int, 0, Int, 0, Int, width, Int, height-100)
Back to top
View user's profile Send private message Visit poster's website
Zippo()
Guest





PostPosted: Sun Apr 27, 2008 12:28 am    Post subject: Reply with quote

GL.ahk wrote:
GL_BLEND := 0x0BE2


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.

And getting compatible bitmap from a file isn't that bad: hBmp := DllCall("LoadImage", UInt, 0, UInt, &lpszName, UInt, IMAGE_BITMAP, Int, 0, Int, 0, UInt, LR_LOADFROMFILE | LR_CREATEDIBSECTION)

Looks cut-n-dry to me.

Btw thanks for moving the thread engunneer. I thought I thanked you earlier but it must have slipped my mind (like many other things these days Sad ).
Back to top
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Goto page Previous  1, 2, 3, 4  Next
Page 2 of 4

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group