Why aren't my textures being shown? (OpenGL)

This is a discussion on Why aren't my textures being shown? (OpenGL) within the Game Programming forums, part of the General Programming Boards category; I have looked over this program and compared it to other ones that had textures working but can't seem to ...

  1. #1
    Ethernal Noob
    Join Date
    Nov 2001
    Posts
    1,901

    Why aren't my textures being shown? (OpenGL)

    I have looked over this program and compared it to other ones that had textures working but can't seem to find the problem. It basically draws different sized quads from triangles and they all have a raindrop texture applied to them, but it doesn't work. Did I miss something here. Here is the setup and rendering parts of my code.

    Code:
    void ParticleScene::setupView(int width, int height)
    {
        glViewport(0, 0, width,height);
    
        float ratio = static_cast<float>(width)/static_cast<float>(height);
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        gluPerspective(42, ratio, 0, 100);
    
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();
    }
    
    
    void ParticleScene::initialize()
    {
        glDisable(GL_DEPTH_TEST);
        glDepthFunc(GL_LEQUAL);
        glClearColor(0.0, 0.0, 0.0, 0.0);
    
        glEnable(GL_BLEND);
        glBlendFunc(GL_SRC_ALPHA, GL_ONE);
    
        //load the raindrop textures
        glEnable(GL_TEXTURE_2D);
        glGenTextures(1, &rainTexture);
    
        image.Load("Data/star.tga");
        glBindTexture(GL_TEXTURE_2D, rainTexture);
        gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA, image.GetWidth(), image.GetHeight(),
                                GL_RGBA, GL_UNSIGNED_BYTE, image.GetImage());
        image.Release();
    /////
    Code:
    void ParticleScene::render()
    {
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
        glLoadIdentity();
        gluLookAt(0, 0, 80,
                  0, 0, -1,
                  0, 1, 0);
    
        //just lines to indicate bundary of rainfall
        glBegin(GL_LINES);
            glColor3f(1.0, 0.0, 0.0);
            glVertex3f(-40, STARTING_HEIGHT, 0);
            glVertex3f(40, STARTING_HEIGHT, 0);
    
            glColor3f(0.0, 1.0, 0.0);
            glVertex3f(-40, ENDING_HEIGHT, 0);
            glVertex3f(40, ENDING_HEIGHT, 0);
        glEnd();
    
        
        glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
        for(size_t i = 0; i < MAX_PARTICLES; ++i)
        {
            if(raindrops[i].alive == true)
            {
                float sz = raindrops[i].size;
                float x = raindrops[i].xPos;
                float y = raindrops[i].yPos;
                float z = raindrops[i].zPos;
    
                glBindTexture(GL_TEXTURE_2D, rainTexture);
                glBegin(GL_TRIANGLE_STRIP);
                    glColor4f(0.0, 0.0, raindrops[i].blue, raindrops[i].alpha);
                    glTexCoord2i(1, 1); glVertex3f(x + sz, y + sz, z);
                    glTexCoord2i(0, 1); glVertex3f(x - sz, y + sz, z);
                    glTexCoord2i(1, 0); glVertex3f(x + sz, y - sz, z);
                    glTexCoord2i(0, 0); glVertex3f(x - sz, y - sz, z);
                glEnd();


    the "raindrops" show as blocks with the attributes in their structures but neither the alpha or the textures seem to be enabled
    Attached Images Attached Images  
    Last edited by indigo0086; 07-03-2007 at 07:11 AM.

  2. #2
    Massively Single Player AverageSoftware's Avatar
    Join Date
    May 2007
    Location
    Buffalo, NY
    Posts
    141
    I'd guess it's one of two things:

    You're doing something wrong when creating the texture. This would be in your image.Load() call, which I can't see.

    Or, you need to glEnable(GL_TEXTURE_2D); before you draw the texture mapped objects.
    There is no greater sign that a computing technology is worthless than the association of the word "solution" with it.

  3. #3
    Ethernal Noob
    Join Date
    Nov 2001
    Posts
    1,901
    well the image.Load function works correctly, I got the CTargaImage class from the OpenGL book I'm reading and it works. I also enabled GL_TEXTURE_2D correctly. I have it all in the code posted.

  4. #4
    Massively Single Player AverageSoftware's Avatar
    Join Date
    May 2007
    Location
    Buffalo, NY
    Posts
    141
    I might not have expressed that clearly enough, I meant to enable texturing here:

    Code:
        glEnable(GL_TEXTURE_2D); //<--RIGHT HERE
        glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
        for(size_t i = 0; i < MAX_PARTICLES; ++i)
        {
            if(raindrops[i].alive == true)
            {
                float sz = raindrops[i].size;
                float x = raindrops[i].xPos;
                float y = raindrops[i].yPos;
                float z = raindrops[i].zPos;
    
                glBindTexture(GL_TEXTURE_2D, rainTexture);
                glBegin(GL_TRIANGLE_STRIP);
                    glColor4f(0.0, 0.0, raindrops[i].blue, raindrops[i].alpha);
                    glTexCoord2i(1, 1); glVertex3f(x + sz, y + sz, z);
                    glTexCoord2i(0, 1); glVertex3f(x - sz, y + sz, z);
                    glTexCoord2i(1, 0); glVertex3f(x + sz, y - sz, z);
                    glTexCoord2i(0, 0); glVertex3f(x - sz, y - sz, z);
                glEnd();
    
    You may also want to move the glBindTexture() call outside of the loop, since all your particles use the same texture. Minor efficiency thing.

    You may also want to try it as a quad first, just to see if your triangle coords might be messed up.
    There is no greater sign that a computing technology is worthless than the association of the word "solution" with it.

  5. #5
    Ethernal Noob
    Join Date
    Nov 2001
    Posts
    1,901
    Tried everything you said, still didn't work. Tried different winding of the vertexes, still didn't work. My programs like texture crippled.

  6. #6
    Massively Single Player AverageSoftware's Avatar
    Join Date
    May 2007
    Location
    Buffalo, NY
    Posts
    141
    OK, here's one that catches a lot of people.

    The dimensions of OpenGL textures must be powers of 2.

    What are the dimensions of your texture?
    There is no greater sign that a computing technology is worthless than the association of the word "solution" with it.

  7. #7
    Ethernal Noob
    Join Date
    Nov 2001
    Posts
    1,901
    ok I found the problem.

    I'm using GLFW for my display and you aren't supposed to enable any OpenGL states before you use glfwOpenWindow(). I guess it resets the OpenGL state machine when it uses the openwindow function.

    And with gluBuild2dMipMaps it scales the texture to a power of 2.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Multiple textures in OpenGL...
    By yaya in forum Game Programming
    Replies: 1
    Last Post: 02-12-2008, 07:24 AM
  2. OpenGL; Using TGA Textures
    By cboard_member in forum Game Programming
    Replies: 6
    Last Post: 12-19-2005, 01:01 PM
  3. OpenGL Window
    By Morgul in forum Game Programming
    Replies: 1
    Last Post: 05-15-2005, 12:34 PM
  4. OpenGL, loading BMP Textures?
    By Zeusbwr in forum Game Programming
    Replies: 12
    Last Post: 12-09-2004, 04:16 PM
  5. OpenGL / Moveing textures?
    By Oluf in forum Game Programming
    Replies: 7
    Last Post: 06-08-2004, 01:26 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21