2D Scrolls Side Game (help with textures)

Hello guys, i am new here, this is my first post, in fact :smiley:

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.

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_FILTER,GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,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.

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ā€¦

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

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 :wink:

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 :smiley: )

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)ā€¦

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:

I hope someone can help meā€¦ because i donā€™t find the answer in the tutorials.

THANKS.

Carlos,
Chile.

When loading texture, create a RGBA texture, with A being the transparency : 0 transparent, 255 opaque, other values for different transparency.

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-

As far as I know this feature is only exposed through extensions otherwise it is not possible because this adds a new texture target ā€¦

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 does not add any new entrypoint, just relaxes power-of-two size limitations.

(ARB_texture_rectangle is not so great though)

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.

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.-

no one knows??

or maybe i didnā€™t explain good enoughā€¦ sorry but english is not my native languaje.

Carlos.

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ā€¦

And this is the unique way ??
Maybe it is not so fastā€¦ imagine you have width=256, height = 256 , and 50 transparent texturesā€¦ 2562563*50 = 9830400 iterations :s

Carlos.

Originally posted by <CarlosContreras>:
2562563*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.