[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: OpenGL texturing



Francesco Orsenigo wrote:
Steve Baker:

Francesco Orsenigo wrote:

How can i load a texture to use within OpenGL calls?
Each demo/tutorial i see uses different functions, many of wich are not
native OpenGL...

OpenGL doesn't have calls for doing file I/O - it's a graphics API!

Ok, my question was bad expressed.
Let's say i have a texture _already in memory_ in some format OpenGL can understand.
Now, i want to feed somewhat that memory texture to OpenGL, and maybe someone will return me an integer texture-id... or at least so i expect.
That's more or less how it works.

You use glGenTextures() to get either one handle - or a bunch of them if
you need a lot of textures.

Then you use glBindTexture() to make that handle "current".  From that
point on, everything you do refers to that texture.  Loading images
(glTexImage2D), drawing polygons, etc, etc.  That texture remains
active until you glBindTexture() with a different handle.

So, no run-time manipulations....
I need to draw the game units with some patches colored with the player color... how could be this achieved?
At the time i'm working with single images, but i can split them between the part to be transformed and the part to drawn as is.
Well, there are several ways to do this:

1) Draw the texture with transparent parts where the unit colours
   are needed.  Draw each unit twice - once in it's "unit colour"
   and then again in white with the texture applied to it. Wherever
   there are holes in the texture, your unit colours show through.
   No textures to download or modify in realtime!  One set of textures
   does for all the players.

2) Just create one set of textures for each player and download them
   all at the start of the game.   If there aren't too many unit
   types and player colours - that's a simple thing to do.

...you could probably come up with a dozen other ways - but those
are the two that I'd consider.

---------------------------- Steve Baker -------------------------
HomeEmail: <sjbaker1@airmail.net>    WorkEmail: <sjbaker@link.com>
HomePage : http://www.sjbaker.org
Projects : http://plib.sf.net    http://tuxaqfh.sf.net
           http://tuxkart.sf.net http://prettypoly.sf.net
-----BEGIN GEEK CODE BLOCK-----
GCS d-- s:+ a+ C++++$ UL+++$ P--- L++++$ E--- W+++ N o+ K? w--- !O M- V-- PS++ PE- Y-- PGP-- t+ 5 X R+++ tv b++ DI++ D G+ e++ h--(-) r+++ y++++
-----END GEEK CODE BLOCK-----