Easy GL2D
-
- Posts: 2338
- Joined: May 31, 2005 9:59
- Location: Croatia
- Contact:
Both demos (gfx and the collision one) give me 511 FPS on my GeForce 8600 GTS, 60 FPS with VSYNC on.
Although, I should warn you that the programs' VSYNC on/off option seems to be ignored by my video card, and VSYNC is in effect (on or off) only through my NVIDIA control panel. It might be my video card software setup, I don't know.
In my control panel it does say that in Windows XP I am to control VSYNC on that way, while only in Windows VISTA "use the 3D application setting" option for controling VSYNC has an effect.
Although, I should warn you that the programs' VSYNC on/off option seems to be ignored by my video card, and VSYNC is in effect (on or off) only through my NVIDIA control panel. It might be my video card software setup, I don't know.
In my control panel it does say that in Windows XP I am to control VSYNC on that way, while only in Windows VISTA "use the 3D application setting" option for controling VSYNC has an effect.
What's the best way to regulate frames? I've always used vsync, but like Lachie's situation, it might not work on all systems if it's not set up correctly in your video card settings. Also, if someone's monitor refresh rate is set other than what you've coded it to run at, it will run faster or slower which can cause undesirable results. If I code a game, I would want it to run the same on all systems. In the Allegro game library, I use certain refresh rate functions to force it to what I coded the game in, but that doesn't work on all systems too. I've tested this using your library and it's the same thing, vsync syncs to the monitor's refresh rate which can be different on any computer, which makes sense, but not practical. How can I get smooth graphics which run the same on any computer? vsync isn't reliable enough.
When the window/screen is created with fbgfx, you can set the refresh rate you want in screenres, and then use screensync every frame.Screen mode [, [ depth ] [, [ num_pages ] [, [ flags ] [, [ refresh_rate ]]]]]
Without fbgfx, you will probably have to write your own using "timer".
[Edit]
Ah, it still uses fbgfx to create the window:
Code: Select all
if flags then
screenres screen_wid, screen_hei, 32, 2, FB.GFX_OPENGL or flags
else
screenres screen_wid, screen_hei, 32, 2, FB.GFX_OPENGL
endif
-
- Posts: 2655
- Joined: Aug 28, 2008 10:54
- Location: new york
@Rel
http://www.imakegames.com/rolliebollock ... 201.99.zip
The drawing routines were fine to port. I'm having serious problems with your sprite system. Can't get anything to laod properly even in the standard lib, which I used here for the sprite engine till you get weirdness with the fb.image compat one hammered out.
Firstly your lib would only really need to be able to cast, or LET an fb.image into a tglsprite.
Anyway, if you want to take a look and let me know what I'm screwing up, I'd appreciate it. I have no clue what I'm doing with OGL, it operates on a logic which is foreign to me.
http://www.imakegames.com/rolliebollock ... 201.99.zip
The drawing routines were fine to port. I'm having serious problems with your sprite system. Can't get anything to laod properly even in the standard lib, which I used here for the sprite engine till you get weirdness with the fb.image compat one hammered out.
Firstly your lib would only really need to be able to cast, or LET an fb.image into a tglsprite.
Anyway, if you want to take a look and let me know what I'm screwing up, I'd appreciate it. I have no clue what I'm doing with OGL, it operates on a logic which is foreign to me.
Sorry for the delay guys. Haven't been able to code lately but I started to do the tute for back to basic yesterday and this is the rough-draft:
http://rel.betterwebber.com/junk.php?id=112
GL2D is version 0.6 in those examples and I also fixed some bugs while writing the tute.
Updates:
1. Glowlines can use a different texture.
2. Ability to use linear instead of nearest.
3. Limit fps (timer based for those where vsynch does not work)
4. Ability to load spritesets not made by my texture packer.
5. A lot I have to document yet.
Check out the example files (There are lots of examples in the tutorial DL)
RB: I'm downloading your zip. spriteset and sprite sizes are limited to a power of 2 right now.
[edit]
RB: Your sprites are 50x50 (not a power of 2). You should use my texture packer to pack those sprites in a 512*256 texture atlas and use init_sprites().
Will finish the tute and upload a new version probably Sunday. Though the version in the tute is the latest. And no it won't break your existing code.
http://rel.betterwebber.com/junk.php?id=112
GL2D is version 0.6 in those examples and I also fixed some bugs while writing the tute.
Updates:
1. Glowlines can use a different texture.
2. Ability to use linear instead of nearest.
3. Limit fps (timer based for those where vsynch does not work)
4. Ability to load spritesets not made by my texture packer.
5. A lot I have to document yet.
Check out the example files (There are lots of examples in the tutorial DL)
RB: I'm downloading your zip. spriteset and sprite sizes are limited to a power of 2 right now.
[edit]
RB: Your sprites are 50x50 (not a power of 2). You should use my texture packer to pack those sprites in a 512*256 texture atlas and use init_sprites().
Will finish the tute and upload a new version probably Sunday. Though the version in the tute is the latest. And no it won't break your existing code.
Ophelius wrote:What's the best way to regulate frames? I've always used vsync, but like Lachie's situation, it might not work on all systems if it's not set up correctly in your video card settings. Also, if someone's monitor refresh rate is set other than what you've coded it to run at, it will run faster or slower which can cause undesirable results. If I code a game, I would want it to run the same on all systems. In the Allegro game library, I use certain refresh rate functions to force it to what I coded the game in, but that doesn't work on all systems too. I've tested this using your library and it's the same thing, vsync syncs to the monitor's refresh rate which can be different on any computer, which makes sense, but not practical. How can I get smooth graphics which run the same on any computer? vsync isn't reliable enough.
I've already added a limit_fps() function which returns the FPS and needs an argument of frames_per_second.
Code: Select all
declare function fps_limit(byval max_FPS as single) as single
so to get 60 FPS:
Code: Select all
fps = fps_limit(60)
BTW, the latest version is in the draft of my tute I posted above.
rolliebollocks wrote:I found a bug. This code is causing the fb.image to stretch across the buffer. If I call these two functions twice however:
gl2d.screen_init ( screen_x, screen_y )
gl2d.start_2d ( screen_x, screen_y )
There is no problem...
Weird.
Code: Select all
gl2d.screen_init ( screen_x, screen_y ) gl2d.start_2d ( screen_x, screen_y ) dim img as fb.image ptr = imagecreate( 32, 32, rgb(255, 0, 255), 32 ) circle img, (16, 16), 15, rgb(255, 255, 0), , , 1, f circle img, (10, 10), 3, rgb( 0, 0, 0), , , 2, f circle img, (23, 10), 3, rgb( 0, 0, 0), , , 2, f circle img, (16, 18), 10, rgb( 0, 0, 0), 3.14, 6.28 gl2d.load_image_to_HW(cast(gl2d.image ptr, img)) 'gl2d.vsync_on() dim as integer numpoints = 1500, frames, fps dim as double tnow, tlast 'dim as polygon p = LoadPoly2d ( "shape1.txt" ) 'p = Scale ( p, 10,10 ) do gl2d.clear_screen() ' GLPutPolygon2d ( , p ) ' RotateRad (,.01,p ) gl2d.sprite(400,350,cast(gl2d.image ptr,img)) gl2d.set_blend_mode(GL2D.E_TRANS) gl2d.sprite(500,0,cast(gl2d.image ptr,img)) gl2d.set_blend_mode(GL2D.E_BLENDED) glColor4ub(255,255,255,128) gl2d.sprite(550,0,cast(gl2d.image ptr,img)) gl2d.set_blend_mode(GL2D.E_SOLID) gl2d.sprite(600,0,cast(gl2d.image ptr,img)) flip sleep 1 frames+=1 If frames=100 Then tNow = Timer() fps = frames/(tNow-tLast) windowtitle "fps = " & fps Sleep 1 tLast=Timer():frames=0 End If Loop Until Multikey( FB.SC_ESCAPE )
This:
Code: Select all
gl2d.screen_init ( screen_x, screen_y )
gl2d.start_2d ( screen_x, screen_y )
For a straight 2d game, start_2d() and end_2d() should never be invoked at all.
I only put those two functions as non private for people who would code a 2d/3d hybrid game.
Check out the link for my tute draft and run 2d and 3d for a more in depth example.
Re: GET, POINT, ETC (direct Vram Access). I could implement this using an FBO but people with older cards might squirm at the idea as it's an "extension". I'll do this with just FFP all the way.
Reading and writing to VRAM using the FFP is not really that fast. For direct pixel manipulations GLSL is the way to go with fragment shaders. However, my card is so old it only has shader 1.0 when the latest cards support PS3(shader 3).
As for your sprite engine, you could texturepack it using my texture packer or put them in a single tileset which has a 2+2^n dimension and use either of the 2 flavors of init_sprites().
-
- Posts: 2338
- Joined: May 31, 2005 9:59
- Location: Croatia
- Contact:
Asking without checking sorry, but can we implement z axis zooming easily with GL2D in our games? Because a while ago I hacked up an OpenGL platform engine featuring that. Hope that this is EASILY done in GL2D.
Edit: Also, the glowlines. Is it possible to dimish the effect of glowing vertices with polylines? I don't like the vertices glowing like that.
Edit: Also, the glowlines. Is it possible to dimish the effect of glowing vertices with polylines? I don't like the vertices glowing like that.
Lachie: If you downloaded my draft of the tute, you will see zooming in there.
Ophelius: I have tested the examples on win7 32 bit and they worked fine. Try downloading this new draft + more examples:
http://rel.betterwebber.com/junk.php?id=112
[edit]
Ophelius: It seems you're not the only one having crashes. This time it's Vista64. so it basically boils down to 64 bit systems.
Ophelius: I have tested the examples on win7 32 bit and they worked fine. Try downloading this new draft + more examples:
http://rel.betterwebber.com/junk.php?id=112
[edit]
Ophelius: It seems you're not the only one having crashes. This time it's Vista64. so it basically boils down to 64 bit systems.
I don't have a 64 bit machine to test this though. Anyone has any idea why it crashes on 64 bit machines?Well, it worked fine once I set the right compile options in FBEdit :)
Only 1 of the example exes in the tutorial you link to work on my PC - the lightsaber one - the rest crash.
I have a GTX 295 graphics card, but am running on Vista64.
e.g.
Problem Event Name: APPCRASH
Application Name: tute_metaballs.exe
Application Version: 0.0.0.0
Application Timestamp: 4c839257
Fault Module Name: StackHash_18c5
HI
I don't do much GL, but I've put together a GL regular polygon drawer.
You can have it solidly coloured, or just any thickness of line.
You can draw solid or line circles/ellipses.
available:
2d rotation
anywhere on screen
change colour/shade
any size/thickness
Hope it may be of some use to somebody!
loads of options, probably too many, but they are FREE, so there you are, ain't you all lucky?
just press space to change, esc to exit, and then have a tweak at the variables in the code.
Good luck.
I don't do much GL, but I've put together a GL regular polygon drawer.
You can have it solidly coloured, or just any thickness of line.
You can draw solid or line circles/ellipses.
available:
2d rotation
anywhere on screen
change colour/shade
any size/thickness
Hope it may be of some use to somebody!
loads of options, probably too many, but they are FREE, so there you are, ain't you all lucky?
just press space to change, esc to exit, and then have a tweak at the variables in the code.
Good luck.
Code: Select all
#Include Once "GL/glu.bi"
dim shared as integer xres,yres
screeninfo xres,yres
Screenres xres,yres,32,,2
declare Sub GLpolygon(n As Integer,_ 'number of sides
centreX As Double,_ 'centres
centreY As Double,_
col() as double,_ 'dim 1 to 6, see below
t As Double=1,_ 'thickness
size As Double=100,_ 'max (radius) of polygon
angle As Double=0,_ 'turn a few degrees to one side
shade1 as double=1,_ 'line shaders
shade2 as double=1,_
ex As Double=1,_ 'eccentricity on x plane
ey As Double=1,_ 'eccentricity on y plane
im as any pointer=0) 'UNUSED
declare sub GL2dsetup
'Generate randoms within a range
Function r(first As Double, last As Double) As Double
Function = Rnd * (last - first) + first
End Function
'an example colouring macro
#macro getcolour(x)
select case x
case 1
colour(1)=1: colour(2)=0 :colour(3)=.2
colour(4)=.5:colour(5)=0:colour(6)=.2
case 2
colour(1)=r(0,1):colour(2)=r(0,1):colour(3)=r(0,1)
colour(4)=colour(1):colour(5)=colour(2):colour(6)=colour(3)
end select
#endmacro
dim as double colour(1 to 6) 'colour(1 to 3) one end, colour(4 to 6) other end of line
dim sides as integer=6 'number of polygon sides
dim size as double=200 'radial size of polygon
dim thickness as double=200 'thickness=size for solid colour
dim angle as double 'rotation angle
dim shade1 as double=1 'shaders 0 to 1 (shade each line)
dim shade2 as double=1 'just tweak the shaders to suit. shade1=1, shade2=1 no shading
dim eccentricityX as double=1 'if sides > 50 then a circle is drawn
dim eccentricityY as double=1 'tweaking eccentricity produces an ellipse
dim cx as double 'centre of polygon
dim cy as double
dim ii as string 'for the inkey
randomize
GL2dsetup 'initialise GL2d
do
getcolour(2) ' colour(2) is homogenous,colour(1) is variable reddish
angle=r(1,360) 'random in 1 to 360 degrees
cx=r(.3*xres,.7*xres) 'random polygon centres
cy=r(.3*yres,.7*yres)
sides =int(r(3,10)) 'random in 3 to 10
'Please note if you want ellipses, set sides to >50 and adjust
' one of the eccentricities above
do
if ii=chr(27) then end
glClear (GL_COLOR_BUFFER_BIT)
glBegin (GL_LINES)
glpolygon(sides,cx,cy,colour(),thickness,size,angle,shade1,shade2,eccentricityX,eccentricityY)
glend
flip
ii=inkey
loop until ii=" "
loop
'THE PROCEDURES
sub GL2dsetup
glMatrixMode (GL_PROJECTION)
glLoadIdentity ()
glOrtho (0,xres, 0,yres, -1, 1)
glMatrixMode (GL_MODELVIEW)
glDisable (GL_DEPTH_TEST)
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA)
glEnable (GL_BLEND)
glEnable (GL_LINE_SMOOTH)
glLineWidth(4)
end sub
Sub GLpolygon(n As Integer,_ 'number of sides
centreX As Double,_ 'centres
centreY As Double,_
col() as double,_ 'dim 1 to 6
t As Double=1,_ 'thickness
size As Double=100,_ 'radius if circle
angle As Double=0,_ 'turn a few degrees to one side
shade1 as double=1,_ 'line shader
shade2 as double=1,_
ex As Double=1,_ 'eccentricity on x plane
ey As Double=1,_ 'eccentricity on y plane
im as any pointer=0)
Dim pi As Double=4*Atn(1)
#define rad *pi/180
angle=angle rad 'can rotate the polygon by degrees
Dim slug As Double=2*pi/n
Dim As Double dist=size
dim as double x1,x2,y1,y2
dim as double x1r,x2r,y1r,y2r
For z As Double=0 To 2*pi Step slug
For k As Double =0 To t Step 1
x1=centrex+ex*(dist-k)*Cos(z)
y1=centrey+ey*(dist-k)*Sin(z)
x2=centrex+ex*(dist-k)*Cos(z+slug)
y2=centrey+ey*(dist-k)*Sin(z+slug)
'now rotate
x1r=(cos(angle)*(x1-centreX)-sin(angle)*(y1-centreY))+centreX
y1r=(sin(angle)*(x1-centreX)+cos(angle)*(y1-centreY))+centreY
x2r=(cos(angle)*(x2-centreX)-sin(angle)*(y2-centrey))+centreX
y2r=(sin(angle)*(x2-centreX)+cos(angle)*(y2-centreY))+centreY
glColor4f (col(1),col(2),col(3),shade1 )
glVertex2f (x1r, y1r)
glColor4f (col(4),col(5),col(6),shade2)
glVertex2f (x2r,y2r)
Next k
Next z
End Sub
-
- Posts: 289
- Joined: Oct 10, 2006 7:19
can you to me as a robot-sprite with 2 poor :
Titel: parent
Poster: funkheld
Verfasst am: 01.04.2010, 15:03
http://www.roboternetz.de/phpBB2/album_ ... 82eb4edf03
with gl2d?
gruss
Titel: parent
Poster: funkheld
Verfasst am: 01.04.2010, 15:03
http://www.roboternetz.de/phpBB2/album_ ... 82eb4edf03
with gl2d?
gruss
I have no idea what you are saying but if you're asking me if GL2D can do that? Yes it can easily do that.super_castle wrote:can you to me as a robot-sprite with 2 poor :
Titel: parent
Poster: funkheld
Verfasst am: 01.04.2010, 15:03
http://www.roboternetz.de/phpBB2/album_ ... 82eb4edf03
with gl2d?
gruss