Easy GL2D

User projects written in or related to FreeBASIC.
Post Reply
sir_mud
Posts: 1401
Joined: Jul 29, 2006 3:00
Location: US
Contact:

Post by sir_mud »

Ha, I think Lachie's old computer did GL better than this laptop, only get 2 fps.
Ophelius
Posts: 428
Joined: Feb 26, 2006 1:57

Post by Ophelius »

-The bugs were because I wasn't including the .bas module. I assumed it was written in the .bi file already.

-Under the screeninit function, I had to include 'OR 1' to the flag for screenres to make it fullscreen. I know it's easy to add manually, but it should be an option.

-I tried asteroidz in fullscreen and its really smooth, but every 1-2 seconds, I see a scan line distorting the image, which looks like evidence of no vsync or poorly done vsync. Is GL in charge of maintaning and syncing the refresh rate? Any way of fixing this? Don't know much about GL.
Lachie Dazdarian
Posts: 2338
Joined: May 31, 2005 9:59
Location: Croatia
Contact:

Post by Lachie Dazdarian »

GL2D lib demo on my PC, full screen (GeForce 8600 GTS): 510 + FPS
Asteroidz: 3600 FPS

In windowed mode higher FPS values.

But, I had to force no VSYNC in my video card settings to get these values. Otherwise, I get 60 FPS, naturally.

Any my card is not really high end.

Not sure what to say to people who don't want to update with the year 2005 (which I think is enough in video card quality sense)...erm, just don't use the lib.
badmrbox
Posts: 664
Joined: Oct 27, 2005 14:40
Location: Sweden
Contact:

Post by badmrbox »

relsoft wrote: As for the errors, you need add gl2d.bas as a module.
Ah. I should have seen that.
relsoft
Posts: 1767
Joined: May 27, 2005 10:34
Location: Philippines
Contact:

Post by relsoft »

Ophelius: I'll add the fullscreen switch next update (I also forgot to add h4tten's ellipse code). As for the vsync, your card controls that. I could add a screensync call in there but that would make if do a double vsynch call.


I also tested this on a 64mb Nvidia mx400 (A video card so old, it's older than my daughter who is 10 years now) and the FPS I'm getting is about 200 FPS.

Should GL2D support FB.IMAGE rather than what it uses now?

http://www.freebasic.net/forum/viewtopic.php?t=16287
rolliebollocks
Posts: 2655
Joined: Aug 28, 2008 10:54
Location: new york

Post by rolliebollocks »

@Rel

My entire polygon library is based on sprites (don't ask, nothing I do makes sense). So my answer is YES. I will port all my drawing routines over if I you can support FB IMAGES, since all the cool stuff my lib does is worthless without the sprite stuff.

But I'm really interested in 3600 FPS.

:)
relsoft
Posts: 1767
Joined: May 27, 2005 10:34
Location: Philippines
Contact:

Post by relsoft »

rolliebollocks wrote:@Rel

My entire polygon library is based on sprites (don't ask, nothing I do makes sense). So my answer is YES. I will port all my drawing routines over if I you can support FB IMAGES, since all the cool stuff my lib does is worthless without the sprite stuff.

But I'm really interested in 3600 FPS.

:)
I'm waiting for the go ahead with dkl on this. I'll work on the FB.IMAGE compatible version once dkl says _reserved() won't ever be used.

Cross your fingers.

I'm talking with dkl on irc right now.
relsoft
Posts: 1767
Joined: May 27, 2005 10:34
Location: Philippines
Contact:

Post by relsoft »

Code: Select all

Update ver 0.5

    Fixed:
      1. pixel inconsistency in sprite rendering
      2. Filled primitive stuff discrepancy
    Added:
      Vsynch
      Ellipse
      Made a version compatible with FB.IMAGE

Code: Select all

**Everything is the same as the standard mode except that:

*******1. all calls to "byref image as Tglsprite" has been changed to
          "byval spr as image ptr"

*******2. Calling the sprite routines needs casting
          ie.
          PUT (310,30), images(81)
   
          becomes:

          gl2d.sprite(310,30,cast(gl2d.image ptr, images(81)))
	
            * no way to go around this as of the moment as we cannot undef stuff
              inside namespaces

*******3. init_sprites() changed prototypes (a lot simpler now)

*******4. Added load_image_to_HW(byval spr as image ptr) 
          * Loads an FB.image to texture
          * See example file
 

There are now two versions. The standard(old one) and the FB.IMAGE compatible one.

Difference are noted above.

Also by making it FB.Image compatible I was able to make use of Mysoft's pixel-perfect collision routine.

So we collide via sofware and at the same time, rendering via hardware. Check out the example exes.
Lachie Dazdarian
Posts: 2338
Joined: May 31, 2005 9:59
Location: Croatia
Contact:

Post by Lachie Dazdarian »

I was just about to ask for pixel perfect collision. This is so awesome.
rolliebollocks
Posts: 2655
Joined: Aug 28, 2008 10:54
Location: new york

Post by rolliebollocks »

THANKS REL!
relsoft
Posts: 1767
Joined: May 27, 2005 10:34
Location: Philippines
Contact:

Post by relsoft »

No problem guys. I need you to test it for bugzzors.

Also what's your FPS w/o vsynch?
Landeel
Posts: 777
Joined: Jan 25, 2007 10:32
Location: Brazil
Contact:

Post by Landeel »

Hahah, this is getting pretty cool.

Please change it to

Code: Select all

#include once "GL/gl.bi" 

#include once "GL/glu.bi"   

So it compiles on Linux.
I also tested this on a 64mb Nvidia mx400 (A video card so old, it's older than my daughter who is 10 years now) and the FPS I'm getting is about 200 FPS.
I have one of those too. It has no fan, and still works.
I seriously doubt any video card made in the last 2 years will survive for 10 years.
rolliebollocks
Posts: 2655
Joined: Aug 28, 2008 10:54
Location: new york

Post by rolliebollocks »

@Rel

In your demo I'm getting about 740 FPS.

A couple of quick questions... Reading data from the screenbuffer... Is it any different? I need something like

somecolor = point(x,y)

...but probably faster. Can I read pixdata directly from the screen?

<edit>

and something like

Get ( source_gl_sprite, x1,y1, x2,y2, dest_gl_sprite )

<edit>

Oh. With vsync? I get a solid 60 all the way.

Also, your lib is rendering my polygons, points, and lines without a hitch, and about a half an hour's worth of work.
rolliebollocks
Posts: 2655
Joined: Aug 28, 2008 10:54
Location: new york

Post by rolliebollocks »

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 ) 
Landeel
Posts: 777
Joined: Jan 25, 2007 10:32
Location: Brazil
Contact:

Post by Landeel »

A couple of quick questions... Reading data from the screenbuffer... Is it any different? I need something like

somecolor = point(x,y)

...but probably faster. Can I read pixdata directly from the screen?
You can use glReadPixels to copy the pixel data from the framebuffer to a system memory buffer, or glCopyTexImage2D to copy pixel data from the framebuffer to a texture.

They're both not very fast, glCopyTexImage2d is a bit faster. Also the double buffer usually causes me problems with those.

The best way would be using a Frame Buffer Object (FBO), but that's something I didn't have time to look at yet.
Post Reply