Easy GL2D

Got something cool to help make the toolchains better? Post it here.

Should libgl2d be integrated into libnds? http://devkitpro.org/viewtopic.php?p=6893#p6893

Yes, integrate it immediately if not sooner.
41
40%
No, let's have this as a separate library and work towards middleware.
20
20%
Let's do both - integrate it as is and build an abstraction layer on top.
17
17%
I'm good with whatever is decided.
24
24%
 
Total votes: 102

relminator
Posts: 84
Joined: Sun Apr 11, 2010 10:43 am

Re: Easy GL2D

Post by relminator » Sat Apr 02, 2011 3:49 am

Update 04/02/2011
  • Added gl[Get/Set]ActiveTexture() for Stencil FX (See Sprites example)
    Added uoff and voff to glSpriteOnQuad for more FX
    Changed Sprite Examples

suprsmashkng
Posts: 3
Joined: Sat Jul 16, 2011 8:27 pm

Re: Easy GL2D

Post by suprsmashkng » Sat Jul 16, 2011 11:06 pm

Hey relminator,

I really love your Easy GL2D library. I'd been floundering around with the 2D engine for a few weeks and then found your library and haven't looked back.

I'm at an impasse with collision checking in a game I'm trying to make. Can you recommend a way to do it? After looking around the Internet for ideas, my initial plan was to do rough collision checking by looking at sprites' bounding boxes and then following up, if necessary, with precise, per-pixel checking within the bounding boxes' rectangle of intersection. The problem is I have no idea how to check if a pixel is "on" in Easy GL2D! Can you think of a way to do it, or a workaround? Any help would be appreciated. Thanks a lot.

relminator
Posts: 84
Joined: Sun Apr 11, 2010 10:43 am

Re: Easy GL2D

Post by relminator » Thu Sep 01, 2011 1:43 am

Hi. sorry for the late reply. Been kinda busy these days. ;*(

Yeah AABB is very fast and I would stick to it if it can do what you want.

I've used only AABBs on this game and I did fine:

http://rel.phatcode.net/index.php?actio ... Impakto-DS


For a more geometrically friendly collision detection you can use SAT.

http://rel.phatcode.net/junk.php?id=109

I would not use pixel by pixel collisions on the DS as it's very slow even after clipping and cropping collision bounds via AABB.

suprsmashkng
Posts: 3
Joined: Sat Jul 16, 2011 8:27 pm

Re: Easy GL2D

Post by suprsmashkng » Thu Sep 01, 2011 2:24 am

I looked into SAT a little bit. I tried to do myself with someone else's fixed-point arithmetic library but ran into problems, so I'm excited to see how your implementation works. I settled on treating an object's bounding box as a convex hull and doing an inclusion test on each of the vertices of the other object's bounding box, and it works perfectly. However, I can imaging it slowing down for a busy game with lots of bounding boxes, so perhaps I'll try your SAT method.

Thanks for the help!

defer
Posts: 3
Joined: Sat Feb 26, 2011 7:15 pm

Re: Easy GL2D

Post by defer » Sat Dec 10, 2011 4:09 am

Hi,
I've used gl2d for the sdl 1.3 port, which has saved me alot of time. I'd like to integrate it into sdl as well as fix an issue I'm facing. However your code doesn't have a licence. SDL is using the zlib licence (http://hg.libsdl.org/SDL/file/tip/COPYING). Could you consider allowing me to use your code there, or licence gl2d with a zlib compatible licence ?

relminator
Posts: 84
Joined: Sun Apr 11, 2010 10:43 am

Re: Easy GL2D

Post by relminator » Fri Jan 27, 2012 8:53 am

defer wrote:Hi,
I've used gl2d for the sdl 1.3 port, which has saved me alot of time. I'd like to integrate it into sdl as well as fix an issue I'm facing. However your code doesn't have a licence. SDL is using the zlib licence (http://hg.libsdl.org/SDL/file/tip/COPYING). Could you consider allowing me to use your code there, or licence gl2d with a zlib compatible licence ?
Sure, just use it in anyway you like.
;*)

slenkar
Posts: 43
Joined: Sun Apr 17, 2011 8:10 pm

Re: Easy GL2D

Post by slenkar » Wed Sep 12, 2012 2:52 pm

do all sprites have to be power of 2?
what about sprites that are NOT power of 2 on a texture that IS power of 2?

also I would like to alter the gl2d source so I can parent one sprite to another, so I would have to remove some calls to glLoadidentity

as gl2d is included as a .a file how would I do this

elhobbs
Posts: 358
Joined: Thu Jul 02, 2009 1:19 pm

Re: Easy GL2D

Post by elhobbs » Wed Sep 12, 2012 4:27 pm

sprites do not need to be a power of 2, but the textures used to hold the sprite frames do need to be power of 2. look at the spritres example, this is how it is setup. The lib source is in the download - the distributable_source directory. instead of referencing the lib in your makefile just copy the files in the gl2d source and include directories to your project's source and include directories. then you can change whatever you like.

slenkar
Posts: 43
Joined: Sun Apr 17, 2011 8:10 pm

Re: Easy GL2D

Post by slenkar » Wed Sep 12, 2012 6:46 pm

thanks for the help on sprites,

I realized the texturedquad function is all you need to do do funky stuff like parenting etc. as long as xtranslatef32 is copied from gl2d.c as its inline

relminator
Posts: 84
Joined: Sun Apr 11, 2010 10:43 am

Re: Easy GL2D

Post by relminator » Thu Sep 13, 2012 10:36 am

Yep, what elhobbs said. By parenting you mean...

Code: Select all

Parent
    transform
        Child
           transform
              Grandchild
Or something like that?

Just do something like this:

Code: Select all


void DrawTentacle( s32 angle, int Segments, glImage *spr )
{

	int i;
	glPushMatrix();
	
		for( i = 0; i < Segments; i++ )
		{
			glTranslate3f32( 7, 0, 0 );
			glRotateZi( angle );
			glSpriteRotate( 0, 0, 0, GL_FLIP_NONE, spr );
		}

	glPopMatrix( 1 );
	
	
}
Then call it like:

Code: Select all

// Start 2D mode
		glBegin2D();

			
			// Draw our enemies
			glSpriteRotate(    x, y, Frame*30 * 3, GL_FLIP_NONE, &Enemies[81]);
			
			
			glPushMatrix();
				glLoadIdentity();
				glTranslate3f32( 128, 96, 0 );   // center of the tentakill
				glRotateZi( Frame * 280);		  // rotation of the tentakill
			
				s32 angle = (sinLerp(-Frame*40));	// angle of the first tentacle
				glPushMatrix();						// relative draw tentacle
					DrawTentacle( angle, 8, &Bullets[Frame/4 & 3] );
				glPopMatrix( 1 );
				
				
				angle = (sinLerp(-Frame*60));
				glRotateZi(BRAD_PI/2);				// quarter turn for next tentacle
				glPushMatrix();
					DrawTentacle( angle, 8, &Bullets[Frame/4 & 3] );
				glPopMatrix( 1 );
				
				angle = (sinLerp(-Frame*40));
				glRotateZi(BRAD_PI/2);
				glPushMatrix();
					DrawTentacle( angle, 8, &Bullets[Frame/4 & 3] );
				glPopMatrix( 1 );
				
				angle = (sinLerp(-Frame*60));
				glRotateZi(BRAD_PI/2);
				glPushMatrix();
					DrawTentacle( angle, 8, &Bullets[Frame/4 & 3] );
				glPopMatrix( 1 );
				
			glPopMatrix( 1 );
			
			// draw the center of tentacle
			glSpriteRotate(    128, 96, Frame*180 * 3, GL_FLIP_NONE, &Enemies[1]);

				
		glEnd2D();

		

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest