PDA

View Full Version : Basics of TEXTURE MAPPING



IlovePascal
23-08-2007, 10:42 PM
System: Windows XP
Compiler/IDE: Lazarus (latest update)
API: OpenGL

Hey all,

I need some serious help. :roll:
For a long time I thought games didn't need to look realistic to be good games, so everything I made was made of cubes and triangles, coloured with the very simple glColor3f(r,b,g) call.

Then I realised on the many forums in this website that people do truly stunningly realistic things using textures. So I read about bumpmapping, mipmapping, megatextures and many more techniques which made me NEED to learn how to do all of that. :P

A few months ago, I went through two tutorials on the internet about texture mapping (including Nehe's 6th tutorial on that topic) but I never managed to get a single picture on my screen, and had so many problems that I gave up.
Some of the problems I had can be found on this thread:
http://www.pascalgamedevelopment.com/viewtopic.php?t=4326&postdays=0&postorder=asc&start=0 (look at the last posts rather than the early ones)
which I started thinking I'd find a solution.

I have decided now to resume my efforts and learn about texture mapping, which I believe is the first step to the other more complex techniques of mapping.

I would like to ask all of you
- if you know tutorials on the subject, on the internet, which DO work
- if you know, after reading the thread given above, what I did wrong in my previous attempts
- if you have a simple and well commented program which I could learn from

In short, if you can please help me out learning about texture mapping and/or other better techniques to fill polygons with pictures. :D

Thanks a lot!

User137
24-08-2007, 03:01 PM
I'll list phases you're going to need in order to use textures with OpenGL (as it's seen on GLEngine http://www.freewebs.com/loknar/ You can find data loading functions for BMP, PNG, JPG and GIF there):


- glEnable(GL_TEXTURE_2D);
- Allocate memory for texture data (array that contains pixel data for example RGB format)
- glGenTextures(1,@TextureIndex);
- glBindTexture(GL_TEXTURE_2D,TextureIndex);
- glTexParameteri(GL_TEXTURE_2D,
GL_TEXTURE_MAG_FILTER,TextureQuality);
(where TextureQuality can be either GL_LINEAR or GL_NEAREST)
- glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTE R,
TextureQuality)
- glTexImage2D(GL_TEXTURE_2D, 0, n, tex.sizeX, tex.sizeY, 0,
Format, GL_UNSIGNED_BYTE, tex.Data)
(where format can be for example GL_RGB or GL_RGBA
and n meaning number of values per pixel)
- Free texture memory
- Enjoy :wink:
- Call glBindTexture(GL_TEXTURE_2D,TextureIndex);
to recall your texture or value 0 to not use any.

Edit: Also, texture sizes matter to graphics card! Image of 500x500 may show white completely where 128x512 or 1024x1024 will show as they are power of 2. Scrap glaux unit for being severely outdated.. aand finally use glTexCoord2f for each vertex to actually see the image.

andygfx
24-08-2007, 10:42 PM
Look on my page, just now I porting of my Final3D engine, he has finished class for working with texture. Class has a lot of function for load, store and bind to face as simple Bind or for Multitexture bind to face.

I use DevIL lib with a lot of picture file formats like this:

Supports loading of:
.bmp;.cut;.dcx;.dds;.ico;.gif;.jpg;.lbm;.lif;.mdl; .pcd;.pcx;.pic;.png;.pnm;.sd;.psp;.raw;.sgi;.tga;. tif;.wal;.act;.pal;.hdr;

Supports saving of:
.bmp;.dds;.jpg;.pcx;.png;.pnm;.raw;.sgi;.tga;.tif; .pal;.hdr;;

http://openil.sourceforge.net/download.php

Traveler
24-08-2007, 11:02 PM
Andygfx, IlovePascal asked for help, not for you to advertise about the countless in- and export possibilities of your engine.

andygfx
24-08-2007, 11:14 PM
Andygfx, IlovePascal asked for help, not for you to advertise about the countless in- and export possibilities of your engine.

Sorry, it's not ADRVERTISE of my engine, i know from my experiencies that best way for learning is reading other working code. My code is FREE.

IlovePascal: .... " - if you have a simple and well commented program which I could learn from " ....

Traveler
25-08-2007, 11:24 AM
I'm sorry but I did not get that from your reply. Perhaps next time you could mention the units and/or functions, within your engine, that he should look into.

In any case, perhaps the lessons and samples from www.sulaco.co.za (http://www.sulaco.co.za/opengl.htm) are more helpfull. The Transparent TGA files and Fog example on the first page should get you on your way real quick.

IlovePascal
26-08-2007, 05:53 PM
cool, ill have a read through all of this
cheers