2d game rendering with ogre

Problems building or running the engine, queries about how to use features etc.
Post Reply
murderv
Greenskin
Posts: 105
Joined: Tue Jun 26, 2007 12:20 pm

2d game rendering with ogre

Post by murderv »

hi there,
i dont know if any of you tried the OgreMagic addon for Ogre (http://www.freewebs.com/ogremagic/). i havent but i took a look at it.

aside my reasons why to code a 2d game using ogre, i wanted to know how could i port this code for opengl ?

for what i've seen OgreMagic draws everything using D3D device directly, it gets the d3ddevice from Ogre and from there it does it's own rendering..

i havent seen anything on how i could do this to be able to render using opengl calls..

anyone have any idea? if there a port of this already ?

[EDIT]
i forgot. would it be a good idea or an easier-to-implement way to use ManualObjects to create a 2d rendering system on top of ogre?
[/EDIT]


PS. my needs are static & animated sprites, also the timeline is a useful thing
User avatar
eugen
OGRE Expert User
OGRE Expert User
Posts: 1422
Joined: Sat May 22, 2004 5:28 am
Location: Bucharest
x 8
Contact:

Post by eugen »

i have no knowledge of OgreMagic but why would the owner code it for D3D when all specific render operations are abstracted?!
Are u sure it doesnt work with opengl also?
User avatar
hmoraldo
OGRE Expert User
OGRE Expert User
Posts: 517
Joined: Tue Mar 07, 2006 11:22 pm
Location: Buenos Aires, Argentina
x 1
Contact:

Post by hmoraldo »

Check the SpriteManager2d code in the wiki: http://www.ogre3d.org/wiki/index.php/SpriteManager2d. You might get some idea of how to do 2d rendering that is not dependant of a specific render system.
H. Hernan Moraldo
Personal website
murderv
Greenskin
Posts: 105
Joined: Tue Jun 26, 2007 12:20 pm

Post by murderv »

eugen, yes im pretty sure, he gets the d3d device and does d3d calls himself..

hmoraldo, hey. ive found that too, i was going thru it this afternoon. it only supports static sprites right ?

i have a couple of question regarding this subject, but i have to leave now.. ill post tomorrow..

thanks guys
User avatar
hmoraldo
OGRE Expert User
OGRE Expert User
Posts: 517
Joined: Tue Mar 07, 2006 11:22 pm
Location: Buenos Aires, Argentina
x 1
Contact:

Post by hmoraldo »

What do you mean by static sprites? You can animate them, move them, etc, just as you'd do if you'd blitted them with the good old DirectDraw. They are not static in the sense overlays are, if that's your question.
H. Hernan Moraldo
Personal website
murderv
Greenskin
Posts: 105
Joined: Tue Jun 26, 2007 12:20 pm

Post by murderv »

moraldo, i have just noticed you can feed texture coordinates to the method parameters.. so i should just make a animatedSprite class around this and based on some speed draw different parts of the texture.. would that be the correct way to do it?

another question i have is what about raycasting.. how could i pick any sprite and drag it around the screen?

ive noticed you use relative coordinate system (0,0) is center of the screen.. shouldnt be hard to chagne that to put (0,0) as top-left corner.

one other question moraldo, what about using materials instead of textures? or even use manualobjects? any advantages over this one ?

[EDIT]
what about colorkey masking or transparency? whats the best way to handle it for sprites?
[/EDIT]


thanks
User avatar
hmoraldo
OGRE Expert User
OGRE Expert User
Posts: 517
Joined: Tue Mar 07, 2006 11:22 pm
Location: Buenos Aires, Argentina
x 1
Contact:

Post by hmoraldo »

murderv wrote:moraldo, i have just noticed you can feed texture coordinates to the method parameters.. so i should just make a animatedSprite class around this and based on some speed draw different parts of the texture.. would that be the correct way to do it?
Yes, you can just make animated sprites by feeding the sprite manager with different textures or different parts of a texture so that to the user, a different image is shown at every instant. Also you can displace the sprites by changing their destination coordinates.

All you see in sprite based games, you can do by using this kind of methods. It basically depends on your ingenuity.
murderv wrote:another question i have is what about raycasting.. how could i pick any sprite and drag it around the screen?
Well, the sprite manager isn't prepared for that directly. You can program that by checking what sprite is below the cursor, always checking the cursor isn't pointing to a transparent pixel of course.
murderv wrote:ive noticed you use relative coordinate system (0,0) is center of the screen.. shouldnt be hard to chagne that to put (0,0) as top-left corner.
Not at all, that would be easy, as that kind of change of coordinates only requires using an addition over the coordinate components (x+somevalue, y+somevalue). Sorry I have no time now to send you a patch, but it would be actually easy to implement.
murderv wrote:one other question moraldo, what about using materials instead of textures? or even use manualobjects? any advantages over this one ?
It's just using textures for simplicity and efficiency.
murderv wrote:what about colorkey masking or transparency? whats the best way to handle it for sprites?
Use pngs with transparency channel, Ogre will take care by itself (they will be loaded as sprites with transparency automatically)

I'll copy this to the sprite manager thread...

Best regards!
H. Hernan Moraldo
Personal website
murderv
Greenskin
Posts: 105
Joined: Tue Jun 26, 2007 12:20 pm

Post by murderv »

hmoraldo,

i updated the sprite hanlder class to load and work with animated sprite sheets, but i do have one other question.

how about working with transformed (scaling & rotation) sprites ?

im not sure how to fit this with the sprite element and transforming them locally.

[eDIT]
rotations should be only around z-axis. no need for others.
about scaling it should be uniform. scales to all sides by same amount
[/EDIT]

any idea ?

thanks in advance
User avatar
hmoraldo
OGRE Expert User
OGRE Expert User
Posts: 517
Joined: Tue Mar 07, 2006 11:22 pm
Location: Buenos Aires, Argentina
x 1
Contact:

Post by hmoraldo »

To do that you'll need to further modify the code. Read the 2d sprite manager code and try to understand the way it works, you'll see the change you propose is no very hard to do (though you'll need some basic maths for the orientation stuff).
H. Hernan Moraldo
Personal website
murderv
Greenskin
Posts: 105
Joined: Tue Jun 26, 2007 12:20 pm

Post by murderv »

ive been doing that, experimenting to scale it and working out the orientation part..

as the sprites are aligned by the top left corner the scaling isnt working as i wanted.. it stretches down right. i should create the sprite shapes with its align in the center.. i think that should give me the correct scaling.

about the orientation, here's what i've added

Ogre::Matrix4 rotMat;
Ogre::Quaternion quat;
Ogre::Vector3 dir = Ogre::Vector3::UNIT_Z;
quat.FromAngleAxis( Ogre::Radian(_scale), dir );
rotMat.makeTransform( Ogre::Vector3::ZERO, Ogre::Vector3::UNIT_SCALE, quat );
pos1 = rotMat * pos1;
spriteElement.x1 = pos1.x;
spriteElement.y1 = pos1.y;
rotMat.makeTransform( Ogre::Vector3::ZERO, Ogre::Vector3::UNIT_SCALE, quat );
pos2 = rotMat * pos2;
spriteElement.x2 = pos2.x;
spriteElement.y2 = pos2.y;

its an hack that rotates the rect points but it rotates then shape around the "world" origin and not around the shape center or even shape's pivot point. if anyone have a good idea on how to work this out..
murderv
Greenskin
Posts: 105
Joined: Tue Jun 26, 2007 12:20 pm

Post by murderv »

i have modified the spritehandler class to support sprite animation aswell as scaling + rotations..
if anyone is interested let me know. i can put the code available to everyone..
cheers for the community and support
User avatar
hmoraldo
OGRE Expert User
OGRE Expert User
Posts: 517
Joined: Tue Mar 07, 2006 11:22 pm
Location: Buenos Aires, Argentina
x 1
Contact:

Post by hmoraldo »

murderv wrote:i have modified the spritehandler class to support sprite animation aswell as scaling + rotations..
if anyone is interested let me know. i can put the code available to everyone..
cheers for the community and support
Maybe you can do as the author of OgreSprites did: he posted his changes in the wiki, in a separate page of the original SpriteManager2d (so to keep the original one simple and easy to modify). OgreSprites is here: http://www.ogre3d.org/wiki/index.php/OgreSprites and the SpriteManager2d here: http://www.ogre3d.org/wiki/index.php/SpriteManager2d.

Best regards and thanks for using this code!
H. Hernan Moraldo
Personal website
murderv
Greenskin
Posts: 105
Joined: Tue Jun 26, 2007 12:20 pm

Post by murderv »

im based on top of the OgreSprites namespace. all i did was change it to handle some more stuff. should i create a new one anyway ?
User avatar
hmoraldo
OGRE Expert User
OGRE Expert User
Posts: 517
Joined: Tue Mar 07, 2006 11:22 pm
Location: Buenos Aires, Argentina
x 1
Contact:

Post by hmoraldo »

murderv wrote:im based on top of the OgreSprites namespace. all i did was change it to handle some more stuff. should i create a new one anyway ?
Hmmm... you should contact his author and ask him what he does prefer. I suppose having only two versions (a simple Sprite Manager and an enhanced one) would be better than having a lot of them. But I guess this should be his choice after all.
H. Hernan Moraldo
Personal website
murderv
Greenskin
Posts: 105
Joined: Tue Jun 26, 2007 12:20 pm

Post by murderv »

will do. thank you moraldo!
User avatar
hmoraldo
OGRE Expert User
OGRE Expert User
Posts: 517
Joined: Tue Mar 07, 2006 11:22 pm
Location: Buenos Aires, Argentina
x 1
Contact:

Post by hmoraldo »

No problem, thank you for using the manager...
H. Hernan Moraldo
Personal website
digitalgibs
Gnoblar
Posts: 15
Joined: Wed Aug 04, 2010 8:22 pm
x 1

Re: 2d game rendering with ogre

Post by digitalgibs »

http://www.ogre3d.org/tikiwiki/SpriteManager2d doesn't work for me. I got it to compile but it renders nothing, despite going through the render calls. Using Ogre 1.7.

[edit] It is rendering shadows into the world, so if there is a shadow casting light it will clear the sprite list after the shadow pass. Is there a way around this?
Lax
Hobgoblin
Posts: 583
Joined: Mon Aug 06, 2007 12:53 pm
Location: Saarland, Germany
x 50

Re: 2d game rendering with ogre

Post by Lax »

Hi digitalgibs,

did you solve your issue with spritemanager2d and shadows? I'm encountering the same problem and don't have a hint how to solve this. Ass soon as shadows are enabled I see no background sprite :(

Regards,
Lax

http://www.lukas-kalinowski.com/Homepage/?page_id=1631
Please support Second Earth Technic Base built of Lego bricks for Lego ideas: https://ideas.lego.com/projects/81b9bd1 ... b97b79be62

Bernardtot
Gnoblar
Posts: 1
Joined: Tue Jan 12, 2016 6:28 pm

2d game rendering with ogre

Post by Bernardtot »

how would i start a game of spring? would i do it with spring lobby or spring exe.?
Post Reply