PDA

View Full Version : 2D Scrolls Side Game (help with textures)



CarlosContreras.cl
06-11-2005, 08:07 PM
Hello guys, i am new here, this is my first post, in fact :D

Well, this is my problem:

----------------------------

I have to make a 2D Scroll Side game, like Mario Bros, you know.

For that, i know all the concepts (the matrix, the tiles with attribs, etc)

I have done some work with that (a level creator), but when i arrived to the Graphics section (for the Engine itself) , i got some problems...

At first, i wanted to do it with the Canvas of C++ Builder, but it is sooooo, soooo, SLOW.

So i decided to use OpenGL.... But i don't know nothing about OpenGL !!

Si i started a few weeks ago, and i have learned some basic concepts... but i have not solve the main problem: the engine for the game.

The details:

I need to create a Big Rectangle, wich contains the "parallax" (a big texture for background, example: far mountains, of 640*480 pixels)

On top of that big texture, i need various squares, that will contain different textures (of 32*32 pixels)

Obviously, almost all of that textures, will have some transparent pixels, showing what is behind... i mean, showing the parallax.

-----------------------------

So, if anyone here can help...

can you post some EXAMPLES like... ?

-quads showing Different Textures...

-quads showing textures, but some quads having TRANSPARENT TEXTURES...

-moving quads around X axis in a "fast" way (you know... 2D world)

PLEASE, i need a lot of help, as i said, i am a very very begginer.

Carlos,
CHILE.

t3jem
06-11-2005, 11:08 PM
Well, to learn how to translate on the x-axis go to http://programminghq.tk there aren't texture tutorials yet, thought.

To use a texture in opengl you have to load it first. here is a function to load a texture.


void text(UINT textureArray[], LPSTR strFileName, int ID)
{
if(!strFileName) return;

AUX_RGBImageRec *pBitMap = auxDIBImageLoad(strFileName);

if(pBitMap == NULL) exit(0);

glGenTextures(1, &textureArray[ID]);
glBindTexture(GL_TEXTURE_2D, textureArray[ID]);
gluBuild2DMipmaps(GL_TEXTURE_2D, 3, pBitMap->sizeX, pBitMap->sizeY, GL_RGB, GL_UNSIGNED_BYTE, pBitMap->data);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTE R,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTE R,GL_LINEAR);

if (pBitMap)
{
if (pBitMap->data)
{
free(pBitMap->data);
}
free(pBitMap);
}
}This will only load bitmaps, though. To load a tga file go here http://www.morrowland.com/apron/tut_gl.php and find the download on tga files.

Overmind
06-12-2005, 02:25 AM
http://nehe.gamedev.net/

There are a lot of tutorials on this site.

The most interesting for you is propably Lesson 9, and depending on how much you already know the ones before that, too...

CarlosContreras.cl
06-12-2005, 09:04 AM
Hi,

i was reading Nehe Lesson #6, and there is a comment: "The width and height must be at least 64 pixels, and for compatability reasons, shouldn't be more than 256 pixels"

But i have done all the previous work with 32*32 pixels !!!

What can i do ? (please don't tell me "start all again an resize all the textures with a paint program")

Thanks.

Carlos.
CHILE

Overmind
06-12-2005, 10:00 AM
You're the second one to mention to me that textures have to be at least 64x64 recently, so I just checked the spec myself ;)

There seems to be a misunderstanding: The maximum allowed texture size has to be at least 64x64 for any OpenGL implementation. There is no minimum texture size (except 1 :D )

This means you can use any smaller texture size, as long as it is a power of 2 (except for the ARB_texture_rectangle and ARB_texture_npot extensions)...

CarlosContreras.cl
06-13-2005, 10:51 AM
Hi, thanks for the answers...

can you help me with this, please??

I have two quads, one with a green texture (quad #1), and the other with a texture with Fuchsia pixels (quad #2)... and i want ONLY the FUCHSIA pixels be transparent...

so, when the Quad#2 be on top of the Quad #1, the fuchsia pixels show what is behind the quad...

like this image:
http://www.carloscontreras.cl/JUEGO_2D/transparent.GIF

I hope someone can help me.. because i don't find the answer in the tutorials.

THANKS.

Carlos,
Chile.

ZbuffeR
06-13-2005, 12:31 PM
When loading texture, create a RGBA texture, with A being the transparency : 0 transparent, 255 opaque, other values for different transparency.

Ehsan Kamrani
06-13-2005, 12:36 PM
Originally posted by Overmind:

This means you can use any smaller texture size, as long as it is a power of 2 (except for the ARB_texture_rectangle and ARB_texture_npot extensions)...Overmind,
I can load the textures that aren't a power of 2. it seems that this limitation refers to the previous versions of OpenGL.
-Ehsan-

powerpad
06-13-2005, 12:48 PM
As far as I know this feature is only exposed through extensions otherwise it is not possible because this adds a new texture target ...

ZbuffeR
06-13-2005, 01:51 PM
Originally posted by powerpad:
As far as I know this feature is only exposed through extensions otherwise it is not possible because this adds a new texture target ...To be more precise, GL_ARB_texture_non_power_of_two (http://oss.sgi.com/projects/ogl-sample/registry/ARB/texture_non_power_of_two.txt) does not add any new entrypoint, just relaxes power-of-two size limitations.

(ARB_texture_rectangle is not so great though)

06-13-2005, 02:21 PM
you should always use power of two textures anyway, because the system *is* going to resize them internally to a power of two. if you do it yourself you have much more control, obviously, as well as possibly saving a little bit of startup time.

CarlosContreras.cl
06-13-2005, 03:45 PM
Originally posted by ZbuffeR:
When loading texture, create a RGBA texture, with A being the transparency : 0 transparent, 255 opaque, other values for different transparency.ok, but HOW to indicate that i want just 1 color to be 100% transparent... ????????

In the example i gave, i mean "i dont want all the texture transparent, i just want the Fuchsia color pixels be transparent"

Carlos.-

06-14-2005, 07:36 PM
no one knows??

or maybe i didn't explain good enough... sorry but english is not my native languaje.

Carlos.

Overmind
06-14-2005, 11:58 PM
You have to build a RGBA texture yourself. Just use the image you have (RGB) and add an alpha channel with A=1 for every pixel except the fuchsia ones where you set A=0...

Pseudocode:

char RGB[w][h][3]; // this is your original image
char RGBA[w][h][4]; // this is the result texture

load_image_into(RGB);

for(i = 0; i < w; i++)
for(j = 0; j < h; j++) {
for(k = 0; k < 3; j++)
RGBA[i][j][k] = RGB[i][j][k];
if(RGB[i][j] == fuchsia)
RGBA[i][j][3] = 0;
else
RGBA[i][j][3] = 255;
}

glTexture2D(..., GL_RGBA, ..., RGBA);Ehsan:
You're right, that's what I meant with "except for ARB_texture_npot". The same applies to OpenGL 2.0, where it is included in the core. But this extension is only fully supported on GF6xxx, on other cards you will get software when trying to use it e.g. with mipmapping...

06-15-2005, 10:53 AM
And this is the unique way ??
Maybe it is not so fast... imagine you have width=256, height = 256 , and 50 transparent textures... 256*256*3*50 = 9830400 iterations :s

Carlos.

ZbuffeR
06-15-2005, 01:57 PM
Originally posted by <CarlosContreras>:
256*256*3*50 = 9830400 iterations :s you only do this once, at startup time. You can even store the textures once preprocessed.
In any case this will get unnoticable compared to the loading time from harddrive.