Okay still having a few problems with it, this is what I have so far:
Bitmap Display::m_HeightMap;
unsigned int Display:: textures;
My initialise method:
glEnable(GL_TEXTURE_2D);
Bitmap image[2];
GLuint *textures = new GLuint[2];
glGenTextures(1, textures);
glGenTextures(2, textures);
image[0].loadBMP("myTexture.bmp");
image[1].loadBMP("myOtherTexture.bmp");
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE , GL_MODULATE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
gluBuild2DMipmaps(GL_TEXTURE_2D, 3, image.width, image.height, GL_RGB, GL_UNSIGNED_BYTE, image.data);
The above line gives an error: left of .data must have class/struct/ union
glDisable(GL_TEXTURE_2D);
Draw Method:
void Draw()
{
glEnable(GL_TEXTURE_2D);
glBegin(GL_QUADS); //TOP
glBindTexture(GL_TEXTURE_2D, textures[0]);
glNormal3f(0,1,0);
glColor4f(1,1,1,0);
//glColor3d(0.5,0.40,0.05);
glTexCoord2f(0.0f,0.0f);
glVertex3f(-4.5, 0.3, 2);//bottom left
glTexCoord2f(1.0f,0.0f);
glVertex3f(-4.5, 0.3, 2.5);//bottom right
glTexCoord2f(1.0f,1.0f);
glVertex3f(4.5, 0.3, 2.5);//top right
glTexCoord2f(0.0f,1.0f);
glVertex3f(4.5, 0.3, 2);//top left
glEnd();
glDisable(GL_TEXTURE_2D);
}
Only problem here is that texture is undefined.
One last thing hopefully!
void loadTexture(GLuint texture, const char* filename)
{
Bitmap image;
Bitmap image[2];
image[0].loadBMP("myTexture.bmp"); <=== error
image[1].loadBMP("myTexture2.bmp"); <=== error
glBindTexture(GL_TEXTURE_2D, texture);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE , GL_MODULATE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
gluBuild2DMipmaps(GL_TEXTURE_2D, 3, image.width, image.height, GL_RGB, GL_UNSIGNED_BYTE,
image.data); }
When I try and load multiple bitmaps I get 7 errors,
error C2040: image:'Bitmap [2]' differs in level of indirection of 'Bitmap'
error C2088: '[' illegal for class (twice)
error C2228: left of .BMP must have class/struct/union (twice)
no operator "[]" matches these operands (twice)
So.
glGenTextures
takes two parameters. Anint
, and aGLuint*
. Theint
tells GL how many textures to generate, and theGLuint*
is an array ofGLuint
s (where to generate the textures). The reason you do the following...is because you only have one texture. If you have more than one, you would do this:
This way, you are telling GL I want to generate n textures, and here's an array with allocated space for at least that many textures.
Say you want to use both of them in your draw loop, you would implement that like this:
Make sure to
delete textures;
at the end of your program to properly clean up after allocating that space.There are also ways to not have to bind separate textures. You can use what's called a "texture atlas". Basically, this is one bitmap that contains multiple sub-images. So you just generate and bind one bitmap, and use separate parts of it.
To deal with multiple bitmaps, do this:
Then follow the process to generate one bitmap for both bitmaps.
Everything below this line is responding to your updated question.
This should pretty much do what you're trying to do.
Some of the issues you are pointing out aren't exactly OpenGL related, they are more C/C++ related. I know this isn't the answer you're looking for, but it would probably help you out a lot to learn about C functions, pointers, arrays, etc, and spend a solid month working closely with functions/pointers/arrays before moving on to something like OpenGL, which requires a pretty moderate understanding of C.
I assume you mean you want to generate multiple textures and store the id's in an array? You can do that like this:
Once you've done that, just loop through your textures and for each one, bind it, set parameters, load in image data, etc.
You may want to create your texture array on the heap so you can access the texture IDs later:
Just make sure to delete the array later:
const GLsizei n = (number of textures here);
GLuint textureIDs = new GLuint[ n ];
glGenTextures( n, textureIDs );