Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length

 
Advanced search

1075929 Posts in 44152 Topics- by 36119 Members - Latest Member: Royalhandstudios

December 29, 2014, 04:00:54 PM
TIGSource ForumsDeveloperTechnical (Moderators: Glaiel-Gamer, ThemsAllTook)Rendering sprites on quads
Pages: [1]
Print
Author Topic: Rendering sprites on quads  (Read 381 times)
paulisere
Level 0
**


View Profile
« on: December 01, 2012, 03:12:08 AM »

Hi

I am writing a game at the moment and I am using C# and OpenGL.  I want to render the characters as sprites.  I plan on drawing the sprite as an image and then rendering it on a quad. However, I am not sure how to do this.  For example, if I render an image like a blue blob surrounded in transparent pixels on a white quad, I get a white square with a blue blob in the middle.  I understand why this is happening, but is it possible to make the white part transparent and just show the blue bit?  Can I do this on a quad?

I'm sorry if this is not clear enough.  Just ask if you need more info.

Paul
Logged

InfiniteStateMachine
Level 10
*****



View Profile WWW Email
« Reply #1 on: December 01, 2012, 03:42:19 AM »

you probably just need to enable the blending mode. What version of opengl are you using?

Actually regardless I think almost everything works by enabling the required blending mode.

It would be something close to the following

glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable( GL_BLEND );

If you google those functions or check your documentation you should be able to find the equivalent code. Essentially you just need to enable the feature.

If you are doing a pixel art type game then you can also do this in the pixel shader by discarding fragments with an alpha under a certain threshold like so. You can also achieve the same results by enabling Alphatest.

I dont have my coding computer in front of me so I cant paste anything specific but this should solve your problem.
Logged

paulisere
Level 0
**


View Profile
« Reply #2 on: December 01, 2012, 04:29:04 AM »

Thanks for the help.  I had a quick test and it seems to work.  I am already using:

glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable( GL_BLEND );

to render semi-transparent grey quads.  (My game is 2d in X and Z viewed from an isometric perspective so the semi-transparent grey quads are back-facing walls, so the user can kind of see through them).

When I am doing this for the sprites, I am assuming that they have to be done in the second render pass like all transparent/semi-transparent stuff.  Is this right?

Paul
Logged

InfiniteStateMachine
Level 10
*****



View Profile WWW Email
« Reply #3 on: December 01, 2012, 04:54:38 AM »

yeah the standard way for translucent sprites is in a second pass that goes back to front.

If you are ok doing it that way then you should be good.

Logged

Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic