Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4320936
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T08:41:17+00:00 2026-05-21T08:41:17+00:00

Okay still having a few problems with it, this is what I have so

  • 0

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)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T08:41:18+00:00Added an answer on May 21, 2026 at 8:41 am

    So. glGenTextures takes two parameters. An int, and a GLuint*. The int tells GL how many textures to generate, and the GLuint* is an array of GLuints (where to generate the textures). The reason you do the following…

    GLuint m_TextureID
    glGenTextures(1, &m_TextureID)
    

    is because you only have one texture. If you have more than one, you would do this:

    // Substitute 'n' for some const number
    GLuint *textures = new GLuint[n];
    glGenTextures(n, textures);
    

    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:

    void draw()
    {
       glBindTexture(GL_TEXTURE_2D, textures[0]); // Tell GL to use the first texture
       // Any drawing here will use first texture
    
       glBindTexture(GL_TEXTURE_2D, textures[1]); // Tell GL to use the second textures
       // Any drawing here will use second texture
    
       glBindTexture(GL_TEXTURE_2D, 0); // Set the GL texture to NULL, standard cleanup
    }
    

    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:

    Bitmap image[2];
    image[0].loadBMP("myTexture.bmp");
    image[1].loadBMP("myOtherTexture.bmp");
    

    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.

    // Global variable
    GLuint textures[2];
    
    // init function
    void init()
    {
       textures = new GLuint[2]; 
       glGenTextures(2, textures);
    
       loadTexture(textures[0], "texture1.bmp");
       loadTexture(textures[1], "texture2.bmp");
    
    }
    
    void loadTexture(GLuint texture, const char* filename)
    {
       Bitmap image; 
       image.loadBMP(filename); 
    
       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);
    }
    
    // draw function
    void draw()
    {
       glBegin(GL_QUADS); //TOP
       glBindTexture(GL_TEXTURE_2D, textures[0]);
       glNormal3f(0,1,0);
       glColor4f(1,1,1,0);
       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();
    }
    
    // cleanup function
    void cleanup()
    {
       delete textures;
    }
    

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Okay this is my 4th question today on Scheme, still pretty new to Scheme,
Okay I have updated my code a little, but I am still not exactly
Okay this question is very simple: I have a facebook page, and a website.
Okay, I feel a bit foolish for having to ask this but I guess
Okay - I have a dilemma. So far my script converts page titles into
Okay, so I have searched this site and found many tutorials on how to
Okay, I'm having a bit of a mental block today/this week, so I'm probably
Okay well I apologize for how sloppy this code is, but I still cant
Okay, I am stumped with this one. I have a table in my database
Website Link Okay, I'm having trouble with IE issues, go figure. I'm still novice

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.