Calling OpenGL directly using external library

Use of external libraries (DLLs) from ZGE.

Moderator: Moderators

User avatar
VilleK
Site Admin
Posts: 2274
Joined: Mon Jan 15, 2007 4:50 pm
Location: Stockholm, Sweden
Contact:

Calling OpenGL directly using external library

Post by VilleK »

One very powerful new feature made possible thanks to external libraries is the ability to make direct OpenGL-calls to draw your own graphics.

Using ZExpressions in OnRender-lists you can mix the standard ZGE-Render components with your custom OpenGL-calls. This gives you the best of two worlds: Use the render-components for an high level approach and code your own OpenGL-effects for more advanced possibilities.

Attached is an example. Main code is this:

Code: Select all

//Draw distorted circles using OpenGL-calls
int circleCount=2;
for(int circle=0; circle<circleCount; circle++) {
  //Set color
  glColor3f(0.5,circle,0);

  //Line-loop
  glBegin(2);
  float radius=3;
  int steps=64;
  for(int i=0; i<steps; i++) {
    float a=i * (PI*2)/steps;
    float x=sin(a) * radius;
    float y=cos(a) * radius;
    x+=noise3( abs(x),abs(y),App.Time*0.45 + (circle*1.131))*2.95;
    y+=noise3( abs(x*0.3),abs(y*0.95),App.Time*0.3 + (circle*1.133441))*1;
    glVertex2f(x,y);
  }
  glEnd();
}
I've only defined the OpenGL-functions that I use in this example, but I plan to make a more complete set of functions so that we can have a OpenGL-component in the Library ready to be pasted into any project for easy access.
Attachments
zge_opengl.png
zge_opengl.png (16.11 KiB) Viewed 32415 times
OpenglLib.zgeproj
(1.15 KiB) Downloaded 999 times
User avatar
Kjell
Posts: 1876
Joined: Sat Feb 23, 2008 11:15 pm

Post by Kjell »

:?:

Neat!

But why not add some of these features to ZGE itself? Shouldn't be too hard to add a drop-down with GL_POINTS / GL_LINES / GL_TRIANGLES etc. to Mesh and a accompanying addVertex Component, right?

At least we can finally use the build-in light capacities of OpenGL this way ( and turn off that dreaded ambient light :wink: ) ~

K
User avatar
y offs et
Posts: 418
Joined: Wed Apr 22, 2009 4:26 pm
Location: BC, Canada

Post by y offs et »

ZGE rocks!
"great expectations"
User avatar
jph_wacheski
Posts: 1005
Joined: Sat Feb 16, 2008 8:10 pm
Location: Canada
Contact:

Post by jph_wacheski »

SuperCool indeed!

I will have to start looking into the gl stuff,. any nice web link that describe all the niffty functions ?

Here is (yet another) glitchy hyptographic .scr,. . Thanks Ville.
Attachments
Opening_a_Static_Channel3.zip
.scr
(51.17 KiB) Downloaded 1072 times
iterationGAMES.com
User avatar
Kjell
Posts: 1876
Joined: Sat Feb 23, 2008 11:15 pm

Post by Kjell »

:arrow: OpenGL Reference
User avatar
diki
Posts: 140
Joined: Thu Sep 11, 2008 7:53 pm
Location: GMT+1
Contact:

Post by diki »

Ha, i was wondering wether placing opengl-calls through external libraries would be possible - absolutely wonderful that it is!
User avatar
diki
Posts: 140
Joined: Thu Sep 11, 2008 7:53 pm
Location: GMT+1
Contact:

Post by diki »

it there a way to get a hold of the int-values for flags like GL_DEPTH_BUFFER_BIT - to use them as arguments from inside zge?
User avatar
VilleK
Site Admin
Posts: 2274
Joined: Mon Jan 15, 2007 4:50 pm
Location: Stockholm, Sweden
Contact:

Post by VilleK »

You can google for that constant, or find a opengl-headers file on the net.

Like this one:

http://www.koders.com/delphi/fidE163653 ... s=pos#L387

GL_DEPTH_BUFFER_BIT = $00000100;

So use 0x100 in zge.
User avatar
diki
Posts: 140
Joined: Thu Sep 11, 2008 7:53 pm
Location: GMT+1
Contact:

Post by diki »

alright! thanks!

btw, does ZGE locate the opengl32.dll in the system folder or is it integrated into ZGE - because it works without the .dll being present in the project folder ... ?
User avatar
VilleK
Site Admin
Posts: 2274
Joined: Mon Jan 15, 2007 4:50 pm
Location: Stockholm, Sweden
Contact:

Post by VilleK »

ZGE asks the operating system for the DLL without a path so Windows will first look in the path of the executable and then in other directories including System32 where Opengl32.dll normally is located.

See the remarks-section here for details:

http://msdn.microsoft.com/en-us/library ... 85%29.aspx
User avatar
Kjell
Posts: 1876
Joined: Sat Feb 23, 2008 11:15 pm

Post by Kjell »

8)

For people without a photographic memory.

Code: Select all

ZZDC<?xml version="1.0" encoding="iso-8859-1" ?>
<Group Comment="Constants">
  <Children>  
    <DefineConstant Name="GL_TRUE" Type="1" IntValue="1"/>
    <DefineConstant Name="GL_FALSE" Type="1" IntValue="0"/>

    <DefineConstant Name="GL_NEVER" Type="1" IntValue="512"/>
    <DefineConstant Name="GL_LESS" Type="1" IntValue="513"/>
    <DefineConstant Name="GL_EQUAL" Type="1" IntValue="514"/>
    <DefineConstant Name="GL_LEQUAL" Type="1" IntValue="515"/>
    <DefineConstant Name="GL_GREATER" Type="1" IntValue="516"/>
    <DefineConstant Name="GL_NOTEQUAL" Type="1" IntValue="517"/>
    <DefineConstant Name="GL_GEQUAL" Type="1" IntValue="518"/>
    <DefineConstant Name="GL_ALWAYS" Type="1" IntValue="519"/>

    <DefineConstant Name="GL_CLEAR" Type="1" IntValue="5376"/>
    <DefineConstant Name="GL_AND" Type="1" IntValue="5377"/>
    <DefineConstant Name="GL_AND_REVERSE" Type="1" IntValue="5378"/>
    <DefineConstant Name="GL_COPY" Type="1" IntValue="5379"/>
    <DefineConstant Name="GL_AND_INVERTED" Type="1" IntValue="5380"/>
    <DefineConstant Name="GL_NOOP" Type="1" IntValue="5381"/>
    <DefineConstant Name="GL_XOR" Type="1" IntValue="5382"/>
    <DefineConstant Name="GL_OR" Type="1" IntValue="5383"/>
    <DefineConstant Name="GL_NOR" Type="1" IntValue="5384"/>
    <DefineConstant Name="GL_EQUIV" Type="1" IntValue="5385"/>
    <DefineConstant Name="GL_INVERT" Type="1" IntValue="5386"/>
    <DefineConstant Name="GL_OR_REVERSE" Type="1" IntValue="5387"/>
    <DefineConstant Name="GL_COPY_INVERTED" Type="1" IntValue="5388"/>
    <DefineConstant Name="GL_OR_INVERTED" Type="1" IntValue="5389"/>
    <DefineConstant Name="GL_NAND" Type="1" IntValue="5390"/>
    <DefineConstant Name="GL_SET" Type="1" IntValue="5391"/>

    <DefineConstant Name="GL_NONE" Type="1" IntValue="0"/>
    <DefineConstant Name="GL_FRONT" Type="1" IntValue="1028"/>
    <DefineConstant Name="GL_BACK" Type="1" IntValue="1029"/>

    <DefineConstant Name="GL_POINTS" Type="1" IntValue="0"/>
    <DefineConstant Name="GL_LINES" Type="1" IntValue="1"/>
    <DefineConstant Name="GL_LINE_LOOP" Type="1" IntValue="2"/>
    <DefineConstant Name="GL_LINE_STRIP" Type="1" IntValue="3"/>
    <DefineConstant Name="GL_TRIANGLES" Type="1" IntValue="4"/>
    <DefineConstant Name="GL_TRIANGLE_STRIP" Type="1" IntValue="5"/>
    <DefineConstant Name="GL_TRIANGLE_FAN" Type="1" IntValue="6"/>
    <DefineConstant Name="GL_QUADS" Type="1" IntValue="7"/>
    <DefineConstant Name="GL_QUAD_STRIP" Type="1" IntValue="8"/>
    <DefineConstant Name="GL_POLYGON" Type="1" IntValue="9"/>

    <DefineConstant Name="GL_POINT_SMOOTH" Type="1" IntValue="2832"/>
    <DefineConstant Name="GL_POINT_SIZE" Type="1" IntValue="2833"/>
    <DefineConstant Name="GL_POINT_SIZE_RANGE" Type="1" IntValue="2834"/>
    <DefineConstant Name="GL_POINT_SIZE_GRANULARITY" Type="1" IntValue="2835"/>

    <DefineConstant Name="GL_LINE_SMOOTH" Type="1" IntValue="2848"/>
    <DefineConstant Name="GL_LINE_WIDTH" Type="1" IntValue="2849"/>
    <DefineConstant Name="GL_LINE_WIDTH_RANGE" Type="1" IntValue="2850"/>
    <DefineConstant Name="GL_LINE_WIDTH_GRANULARITY" Type="1" IntValue="2851"/>
    <DefineConstant Name="GL_LINE_STIPPLE" Type="1" IntValue="2852"/>
    <DefineConstant Name="GL_LINE_STIPPLE_PATTERN" Type="1" IntValue="2853"/>
    <DefineConstant Name="GL_LINE_STIPPLE_REPEAT" Type="1" IntValue="2854"/>

    <DefineConstant Name="GL_ZERO" Type="1" IntValue="0"/>
    <DefineConstant Name="GL_ONE" Type="1" IntValue="1"/>
    <DefineConstant Name="GL_SRC_COLOR" Type="1" IntValue="768"/>
    <DefineConstant Name="GL_ONE_MINUS_SRC_COLOR" Type="1" IntValue="769"/>
    <DefineConstant Name="GL_SRC_ALPHA" Type="1" IntValue="770"/>
    <DefineConstant Name="GL_ONE_MINUS_SRC_ALPHA" Type="1" IntValue="771"/>
    <DefineConstant Name="GL_DST_ALPHA" Type="1" IntValue="772"/>
    <DefineConstant Name="GL_ONE_MINUS_DST_ALPHA" Type="1" IntValue="773"/>
    <DefineConstant Name="GL_DST_COLOR" Type="1" IntValue="774"/>
    <DefineConstant Name="GL_ONE_MINUS_DST_COLOR" Type="1" IntValue="775"/>
    <DefineConstant Name="GL_SRC_ALPHA_SATURATE" Type="1" IntValue="776"/>

    <DefineConstant Name="GL_MODELVIEW" Type="1" IntValue="5888"/>
    <DefineConstant Name="GL_PROJECTION" Type="1" IntValue="5889"/>
    <DefineConstant Name="GL_TEXTURE" Type="1" IntValue="5890"/>

    <DefineConstant Name="GL_MODELVIEW_MATRIX" Type="1" IntValue="2982"/>
    <DefineConstant Name="GL_PROJECTION_MATRIX" Type="1" IntValue="2983"/>
    <DefineConstant Name="GL_TEXTURE_MATRIX" Type="1" IntValue="2984"/>

    <DefineConstant Name="GL_FOG" Type="1" IntValue="2912"/>
    <DefineConstant Name="GL_FOG_INDEX" Type="1" IntValue="2913"/>
    <DefineConstant Name="GL_FOG_DENSITY" Type="1" IntValue="2914"/>
    <DefineConstant Name="GL_FOG_START" Type="1" IntValue="2915"/>
    <DefineConstant Name="GL_FOG_END" Type="1" IntValue="2916"/>
    <DefineConstant Name="GL_FOG_MODE" Type="1" IntValue="2917"/>
    <DefineConstant Name="GL_FOG_COLOR" Type="1" IntValue="2918"/>

    <DefineConstant Name="GL_NEAREST" Type="1" IntValue="9728"/>
    <DefineConstant Name="GL_LINEAR" Type="1" IntValue="9729"/>

    <DefineConstant Name="GL_EXP" Type="1" IntValue="2048"/>
    <DefineConstant Name="GL_EXP2" Type="1" IntValue="2049"/>

    <DefineConstant Name="GL_NEAREST_MIPMAP_NEAREST" Type="1" IntValue="9984"/>
    <DefineConstant Name="GL_LINEAR_MIPMAP_NEAREST" Type="1" IntValue="9985"/>
    <DefineConstant Name="GL_NEAREST_MIPMAP_LINEAR" Type="1" IntValue="9986"/>
    <DefineConstant Name="GL_LINEAR_MIPMAP_LINEAR" Type="1" IntValue="9987"/>

    <DefineConstant Name="GL_LIGHTING" Type="1" IntValue="2896"/>

    <DefineConstant Name="GL_LIGHT0" Type="1" IntValue="16384"/>
    <DefineConstant Name="GL_LIGHT1" Type="1" IntValue="16385"/>
    <DefineConstant Name="GL_LIGHT2" Type="1" IntValue="16386"/>
    <DefineConstant Name="GL_LIGHT3" Type="1" IntValue="16387"/>
    <DefineConstant Name="GL_LIGHT4" Type="1" IntValue="16388"/>
    <DefineConstant Name="GL_LIGHT5" Type="1" IntValue="16389"/>
    <DefineConstant Name="GL_LIGHT6" Type="1" IntValue="16390"/>
    <DefineConstant Name="GL_LIGHT7" Type="1" IntValue="16391"/>

    <DefineConstant Name="GL_AMBIENT" Type="1" IntValue="4608"/>
    <DefineConstant Name="GL_DIFFUSE" Type="1" IntValue="4609"/>
    <DefineConstant Name="GL_SPECULAR" Type="1" IntValue="4610"/>
    <DefineConstant Name="GL_POSITION" Type="1" IntValue="4611"/>
    <DefineConstant Name="GL_SPOT_DIRECTION" Type="1" IntValue="4612"/>
    <DefineConstant Name="GL_SPOT_EXPONENT" Type="1" IntValue="4613"/>
    <DefineConstant Name="GL_SPOT_CUTOFF" Type="1" IntValue="4614"/>
    <DefineConstant Name="GL_CONSTANT_ATTENUATION" Type="1" IntValue="4615"/>
    <DefineConstant Name="GL_LINEAR_ATTENUATION" Type="1" IntValue="4616"/>
    <DefineConstant Name="GL_QUADRATIC_ATTENUATION" Type="1" IntValue="4617"/>

    <DefineConstant Name="GL_EMISSION" Type="1" IntValue="5632"/>
    <DefineConstant Name="GL_SHININESS" Type="1" IntValue="5633"/>
    <DefineConstant Name="GL_AMBIENT_AND_DIFFUSE" Type="1" IntValue="5634"/>
    <DefineConstant Name="GL_COLOR_INDEXES" Type="1" IntValue="5635"/>

    <DefineConstant Name="GL_ACCUM" Type="1" IntValue="256"/>
    <DefineConstant Name="GL_LOAD" Type="1" IntValue="257"/>
    <DefineConstant Name="GL_RETURN" Type="1" IntValue="258"/>
    <DefineConstant Name="GL_MULT" Type="1" IntValue="259"/>
    <DefineConstant Name="GL_ADD" Type="1" IntValue="260"/>    
  </Children>
</Group>
In case I've missed any constants you want to use, let me know ..

K
StevenM
Posts: 149
Joined: Thu Jan 20, 2011 10:03 am

OpenGL Library

Post by StevenM »

I imported an OpenGL header library to ZGE. I'm not sure how useful it will be, but I didn't pay much attention to weeding any thing out. I did this because I am learning OpenGL and I was tired of looking up everything. I'm hoping that those of you with more experience can tidy it up a bit and maybe create some project examples.

Edit: repost - fixed some typos in the External Library Functions
Attachments
OpenGL_Library_fix1.zgeproj
(63.54 KiB) Downloaded 1046 times
User avatar
Kjell
Posts: 1876
Joined: Sat Feb 23, 2008 11:15 pm

Post by Kjell »

Hi Steven,

Keep in mind that functions which require unsupported ( double / pointer / texture / shader etc. ) arguments cannot be called from ZGE .. which eliminates a significant portion of the functions / constants directly or indirectly.

+ Buffers such as Accumulation, Feedback & Stencil only work on certain NVIDIA cards without initialization.

K
StevenM
Posts: 149
Joined: Thu Jan 20, 2011 10:03 am

Post by StevenM »

Kjell wrote:Hi Steven,

Keep in mind that functions which require unsupported ( double / pointer / texture / shader etc. ) arguments cannot be called from ZGE .. which eliminates a significant portion of the functions / constants.

K
I thought double would work as a float.

Yes, There are probably many constants that are not needed too. I still imported as much as i could -hoping there was some work around. I will weed things out once I'm more familiar with openGL. Right now I'm not familiar enough with openGL to know what will or will not work. The code completion in ZGEviz has been really helpful.
User avatar
Kjell
Posts: 1876
Joined: Sat Feb 23, 2008 11:15 pm

Post by Kjell »

:roll:
I thought double would work as a float.
Well .. you can actually use functions that require arguments of the type double, but it's a pain in the *ss. For example ..

Code: Select all

void glTranslated(GLdouble x, GLdouble y, GLdouble z);              // Original function ..
void glTranslated(int x1, int x2, int y1, int y2, int z1, int z2){} // .. becomes this in ZGE
Then you need to fill the bits individually following the IEEE 754 standard, so for a translation of x = 1/3 you actually need to use ..

Code: Select all

glTranslated(0x55555555,0x3fd55555,0,0,0,0);
Image
I've got a library that generates the arguments from a float ( 32-bit range ) if you really need it .. but I rather see doubles being added as variable type to ZGE natively.

K
Post Reply