G2: OpenGL 2D Library (Very Easy to Use!!)

User projects written in or related to FreeBASIC.
maddogg6
Posts: 824
Joined: Dec 07, 2005 22:58
Contact:

Postby maddogg6 » Feb 11, 2008 4:40

wow - definitly smoother using hardware than software (in the posted code above for FBGL...

But when I try intenseparticles.bas - with #define fbgl_hard
It crashed at run time, and compiling gives me this:

Code: Select all

Command executed:
"K:\FreeBASIC\fbc.exe" "K:\FreeBASIC\examples\g2\fbgl\intenseparticles.bas" -exx

Compiler output:
K:/FreeBASIC/examples/g2/fbgl/intenseparticles.bas(59) warning 2(1): Passing pointer to scalar, at parameter 3 (graphic) of G2MULTIPUT()
K:/FreeBASIC/examples/g2/fbgl/intenseparticles.bas(70) warning 4(1): Suspicious pointer assignment
K:/FreeBASIC/examples/g2/fbgl/intenseparticles.bas(100) warning 2(1): Passing pointer to scalar, at parameter 3 (graphic) of G2MULTIPUT()

Results:
Compilation successful
Generated executable: K:\FreeBASIC\examples\g2\fbgl\intenseparticles.exe

System:
FBIde: 0.4.6
fbc:   FreeBASIC Compiler - Version 0.18.2 (10-12-2007) for win32 (target:win32)
OS:    Windows XP (build 2600, Service Pack 2)


I suppose I should finally update to .18.3... but, is this to be expected with FB .18.2?
notthecheatr
Posts: 1759
Joined: May 23, 2007 21:52
Location: Cut Bank, MT
Contact:

Postby notthecheatr » Feb 11, 2008 5:00

Oddly I don't get the error (0.18.4) but presumably it's not a problem so long as the program runs. That's a warning, not an actual compile error - what it means is that the code tries to pass a pointer when a scalar value is actually expected. It's allowed, although not recommended, but in some cases it will produce unexpected results, which is why the compiler gives warnings about that sort of thing even though when it isn't a problem.
notthecheatr
Posts: 1759
Joined: May 23, 2007 21:52
Location: Cut Bank, MT
Contact:

Postby notthecheatr » Feb 11, 2008 16:27

KristopherWindsor wrote:
notthecheatr wrote:Does anyone have routines for converting between OpenGL textures and fbgfx Image buffers?


Yes, this is the g2ImageCreate function. It's not exactly equivalent to the FBGFX function of the same name, but there is no point in creating an empty texture if you can't edit it. ;-)


Yeah, but I'm wondering if there's a way to convert a texture into an FB.Image buffer and vice-versa. Like taking a regular image buffer created with ImageCreate() and converting it into an OpenGL texture. Not the most useful thing I guess, but it might be useful for some things. Being able to convert this way would help until you get actual support for drawing to buffers enabled. A g2Get would be nice, too. I really need buffered drawing to be able to do anything useful.

Clipping should be possible because I can specify the points on the texture that correspond to the points on the polygon, but I haven't tried it yet.

Someday I will write a list of FBGFX functions and attempt to support all of them in GL. ;-)


If you just get clipping and buffered drawing, I'll be quite happy with it :) But yeah, it would be nice to get everything supported. Maybe someday this could replace the software fbgfx, or at least be used as an alternative.
KristopherWindsor
Posts: 2428
Joined: Jul 19, 2006 19:17
Location: Sunnyvale, CA
Contact:

Postby KristopherWindsor » Feb 12, 2008 0:46

notthecheatr wrote:Like taking a regular image buffer created with ImageCreate() and converting it into an OpenGL texture.


That's... that's what I said. :-P

Regarding the bug, are you compiling just the one source file? fbc intenseparticles.bas is all you need to type to compile this.

The graphic data type depends on which mode you use, but it compiles for me in .18 (from May) without problems. Make sure you #define fbgl_hard in the FBGL file, so it is processed before graphic is Dimmed. :-)
notthecheatr
Posts: 1759
Joined: May 23, 2007 21:52
Location: Cut Bank, MT
Contact:

Postby notthecheatr » Feb 12, 2008 1:14

KristopherWindsor wrote:
notthecheatr wrote:Like taking a regular image buffer created with ImageCreate() and converting it into an OpenGL texture.


That's... that's what I said. :-P


Oh! OK, sorry I misunderstood. Well anyways. Look forward to see more of this.
Lachie Dazdarian
Posts: 2338
Joined: May 31, 2005 9:59
Location: Croatia
Contact:

Postby Lachie Dazdarian » Jul 05, 2008 19:16

I'm planning to make a game using this lib, but I'm having problems with g2put (it gives me a black screen while the g2multiput works), and grabbing more sprites from a single BMP file. Is GETing possible with g2?

Help Kris!
KristopherWindsor
Posts: 2428
Joined: Jul 19, 2006 19:17
Location: Sunnyvale, CA
Contact:

Postby KristopherWindsor » Jul 05, 2008 20:07

Why is my lib crashing for me...???? I'll have to test on the other computer. :-P
I think the lib needs some work since Get can be implemented in OpenGL, but is not in the library.
Optimally you would create your program in FBGFX, then change each FBGFX line to work with FBGL; that way this lib won't stop you from getting a working version of your program.
(And hopefully I will improve this lib by then.)
;-)
Lachie Dazdarian
Posts: 2338
Joined: May 31, 2005 9:59
Location: Croatia
Contact:

Postby Lachie Dazdarian » Jul 05, 2008 22:16

I'm not sure I can work in these sort of "maybe I'll make another version of the lib" circumtances.

Bah, I'll try to dig though the lib myself.
KristopherWindsor
Posts: 2428
Joined: Jul 19, 2006 19:17
Location: Sunnyvale, CA
Contact:

Postby KristopherWindsor » Jul 05, 2008 22:33

Lachie Dazdarian wrote:I'm not sure I can work in these sort of "maybe I'll make another version of the lib" circumstances.


I'm not too good with OpenGL so I can't guarantee anything.
Also given all the quirks in FBGFX, and the differences in OpenGL, I ported the easiest things, and I never expect it to support *everything* FBGFX does.
However, I do need to make my latest project work with OpenGL before it's done, and this is looking like the best way to do that.

Bah, I'll try to dig though the lib myself.


Yes, given the small size of this project, it is sort of an "extend as necessary" lib.
At least you can learn some things looking through it. ;-)
Lachie Dazdarian
Posts: 2338
Joined: May 31, 2005 9:59
Location: Croatia
Contact:

Postby Lachie Dazdarian » Jul 05, 2008 22:41

I OpenGL like meant to work with 2D sprites and stuff? The way I need to treat my sprites as square-shaped textures feels awfully awkward.
DaveUnit
Posts: 239
Joined: Apr 20, 2006 15:47
Location: Central MA
Contact:

Postby DaveUnit » Jul 07, 2008 2:03

Yeah, OpenGL needs to have texture with power of 2 dimensions. There are extensions that can handle not power of 2 textures, but not all cards support this and is not recommended. Mine doesn't and will crawl if the texture isn't a power of 2. I've been able to successfully use OpenGL for 2D sprites by making sure that the tileset loaded has power of 2 dimensions, and then the sprites can be whatever dimension you want since the texture will not be split up into smaller chunks for each sprite frame. I like OpenGL for 2D rendering way more than any software library.
Lachie Dazdarian
Posts: 2338
Joined: May 31, 2005 9:59
Location: Croatia
Contact:

Postby Lachie Dazdarian » Jul 07, 2008 21:51

I'm not sure I get the second part. Once you load your tileset (which is the power of two), how do you extract individual sprites from that single texture?
KristopherWindsor
Posts: 2428
Joined: Jul 19, 2006 19:17
Location: Sunnyvale, CA
Contact:

Postby KristopherWindsor » Jul 07, 2008 22:26

Lachie Dazdarian wrote:I'm not sure I get the second part. Once you load your tileset (which is the power of two), how do you extract individual sprites from that single texture?


One way is to use standard FBGFX functions to load the sprites and split each one onto a different FBGFX image.
Then you can put each FBGFX image onto a different texture. ;-)
Lachie Dazdarian
Posts: 2338
Joined: May 31, 2005 9:59
Location: Croatia
Contact:

Postby Lachie Dazdarian » Jul 07, 2008 22:44

Yes, yes, like it's done in G2. But that code crashed on Dr_D's PC so we are...ahem...looking for an alternative.
DaveUnit
Posts: 239
Joined: Apr 20, 2006 15:47
Location: Central MA
Contact:

Postby DaveUnit » Jul 07, 2008 23:28

I only draw part of the texture via the glTexCoord command.

For example, this would draw a quad that is 100x100 and uses 1/4th of a texture to draw it.
(Remember that the texture will be drawn from the bottom-left rather than top-right like in fbgfx)

Code: Select all

glBindTexture(GL_TEXTURE_2D, texture_index)

glBegin(GL_QUADS)
   glTexCoord2f(0.0, 0.0)
   glVertex2f(0.0, 0.0)

   glTextCoord2f(0.5, 0.0)
   glVertex2f(100.0, 0.0)
   
   glTexCoord2f(0.5, 0.5)
   glVertex2f(100.0, 100.0)
   
   glTexCoord2f(0.0, 0.5)
   glVertex2f(0.0, 100.0)
glEnd()


Just adapt that code to draw a quad that is the sprite's dimensions in size and draws only the right part of the texture on it.

That other method of loading sprites works until you use a sprite that doesn't have power of 2 dimensions. Since not all cards support non-power of 2 textures you will have a lot of problems.

Return to “Projects”

Who is online

Users browsing this forum: No registered users and 3 guests