Could someone take a look at this

This is a discussion on Could someone take a look at this within the Game Programming forums, part of the General Programming Boards category; This is annoying me no end. I'm working on the tile loader modules of this little thing I'm writing - ...

  1. #1
    Supermassive black hole cboard_member's Avatar
    Join Date
    Jul 2005
    Posts
    1,709

    Could someone take a look at this

    This is annoying me no end. I'm working on the tile loader modules of this little thing I'm writing - it all seems to work find except the texture isn't actually displayed. I don't know if it's something to do with my drawing code or the way the tile textures are shared via a static std::vector in a class.

    It runs fine, loads the textures fine, but just displays a blank tile. If someone could look at this I'd really appreciate it.

    http://www.ahluka.co.uk/strat.rar ~3 MB
    Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife.

    - Mike McShaffry

  2. #2
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    Post the texture gen and render code. Are the texture dimensions a power of 2?

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,855
    > http://www.ahluka.co.uk/strat.rar ~3 MB
    I'm not downloading 3MB of compressed source code.
    Much less from some non-standard compressor.

  4. #4
    Supermassive black hole cboard_member's Avatar
    Join Date
    Jul 2005
    Posts
    1,709
    Quote Originally Posted by Perspective
    Post the texture gen and render code. Are the texture dimensions a power of 2?
    Yep they're 32x32.
    The reason the archive is so big is because of the IntelliSense database MSVC builds. I think.

    It'd be easier if I just post up the entire classes:

    CTextureCache: The idea was to keep a static std::vector containing the textures for use anywhere since only ~20 textures are ever going to be used.

    Code:
    // CTextureCache.h
    #pragma once
    #include "stdafx.h"
    
    const ILstring  textureNames[] = { "water.jpg",
                                       "grass.jpg"
                                     };
    
    class CTextureCache {
            static std::vector<GLuint>     texture;
    
            const unsigned NUM_TEXTURES;
            const unsigned LIM_WIDTH;
            const unsigned LIM_HEIGHT;
            ILuint  currentTexID;
     
    public:
            CTextureCache ();
            ~CTextureCache ();
    
            void    Init ();
            void    Load ();
            GLuint  GetByID (char id);
    };
    
    // CTextureCache.cpp
    #include "StdAfx.h"
    #include ".\texturecache.h"
    
    std::vector<GLuint> CTextureCache::texture;
    
    CTextureCache::CTextureCache () 
            :NUM_TEXTURES (2), 
            LIM_WIDTH (32), 
            LIM_HEIGHT (32)
    {
    }
    
    CTextureCache::~CTextureCache ()
    {
    }
    
    // Init
    //
    void CTextureCache::Init ()
    {
            for (unsigned i = 0; i < NUM_TEXTURES; i++)
                    texture.push_back (0);
    }
    
    // Load
    //
    void CTextureCache::Load ()
    {
            unsigned        i;
    
            for (i = 0; i < NUM_TEXTURES; i++) {
                    ilGenImages (NUM_TEXTURES, &currentTexID);
                    ilBindImage (currentTexID);
    
                    if (! ilLoadImage (textureNames[i]))
                            reportErr (true, "Unable to load texture '%s'", textureNames[i]);
    
                    if ((ilGetInteger (IL_IMAGE_WIDTH) != LIM_WIDTH) ||
                        (ilGetInteger (IL_IMAGE_HEIGHT) != LIM_HEIGHT))
                    {
                            reportErr (true, "'%s', Image dimensions out of bounds [%d, %d]",
                                       textureNames[i],
                                       ilGetInteger (IL_IMAGE_WIDTH),
                                       ilGetInteger (IL_IMAGE_HEIGHT));
                    }
    
    
                    ilConvertImage (IL_RGBA, IL_UNSIGNED_BYTE);
                    glGenTextures (1, &texture[i]);
                    glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
                    glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
                    glTexImage2D (GL_TEXTURE_2D, 0, ilGetInteger (IL_IMAGE_BPP), ilGetInteger (IL_IMAGE_WIDTH),
                                  ilGetInteger (IL_IMAGE_HEIGHT), 0, ilGetInteger (IL_IMAGE_FORMAT),
                                  GL_UNSIGNED_BYTE, ilGetData ());
                    ilDeleteImages (1, &currentTexID);
            }
    }
    
    // GetByID
    //
    GLuint CTextureCache::GetByID (char id)
    {
            switch (id) {
                    case 'w':
                            return texture[0];
                    case 'g':
                            return texture[1];
    
                    default:
                            reportErrBox (true, "Invalid texture ID [%c]", id);
            }
    
            return 0;
    }
    CTile:
    Code:
    // CTile.h
    #pragma once
    
    class CTile {
            GLuint  texture;
    
    public:
            CTile (void);
            ~CTile (void);
    
            void    SetTexture (char id);
            void    Draw ();
    
            // Debug
            GLuint  Texture () const
            {
                    return texture;
            }
    };
    
    // CTile.cpp
    #include "StdAfx.h"
    #include ".\tile.h"
    #include "TextureCache.h"
    
    CTile::CTile (void)
    {
    }
    
    CTile::~CTile (void)
    {
    }
    
    // SetTexture
    //      Gets specified texture from the texture cache
    void CTile::SetTexture (char id)
    {
            CTextureCache*  tcache = new CTextureCache ();
    
            texture = tcache->GetByID (id);
            delete tcache;
    }
    
    // Draw
    //
    void CTile::Draw ()
    {
            glBindTexture (GL_TEXTURE_2D, texture);
            glEnable (GL_TEXTURE_2D);
            glBegin (GL_QUADS);
                    glTexCoord2i (1, 0);
                    glVertex2i (32, 0);
                    glTexCoord2i (1, 1);
                    glVertex2i (32, 32);
                    glTexCoord2i (0, 1);
                    glVertex2i (0, 32);
                    glTexCoord2i (0, 0);
                    glVertex2i (0, 0);
            glEnd ();
            glDisable (GL_TEXTURE_2D);
    }
    Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife.

    - Mike McShaffry

  5. #5
    Supermassive black hole cboard_member's Avatar
    Join Date
    Jul 2005
    Posts
    1,709
    I truly am a moron. I wasn't pushing the GLuint's into the vector.
    Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife.

    - Mike McShaffry

  6. #6
    The Right Honourable psychopath's Avatar
    Join Date
    Mar 2004
    Location
    Where circles begin.
    Posts
    1,070
    Ouch. That is definatly the most annoying thing ever, when the answer to your problem is somthing simple you've overlooked. Happens to me all the time.
    Memorial University of Newfoundland
    Computer Science

    Mac and OpenGL evangelist.

  7. #7
    Supermassive black hole cboard_member's Avatar
    Join Date
    Jul 2005
    Posts
    1,709
    Taken the link down.
    Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife.

    - Mike McShaffry

Popular pages Recent additions subscribe to a feed

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