Page 1 of 1

Multiple texturing issues.

Posted: Wed Jun 22, 2011 12:06 am
by MadPumpkin
Having multitexturing issues. Been way to long since I've done this successfully...


Image Loading, uses SDL_Image and converts it to a GL texture, which works fine!!
BUT only with one texture.

Code: Select all

bool GL_LoadIMG(char *file)
{
    SDL_Surface *SDLTexture = LoadIMG(file);
    GLuint GLTexture;

	printf("\n");
    if(SDLTexture)
    {
		printf("OGL - Image loaded.\n");
        glGenTextures(1, &GLTexture);
        glBindTexture(GL_TEXTURE_2D, GLTexture);
        
		glTexImage2D(GL_TEXTURE_2D, 0, 3, SDLTexture->w, SDLTexture->h, 0, GL_BGRA_EXT, GL_UNSIGNED_BYTE, SDLTexture->pixels);

		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

        printf("OGL - Image optimized.\n");
        SDL_FreeSurface(SDLTexture);
    }
    else
    {
        printf("OGL - Image could not be loaded.\n");
		return false;
    }

    return true;
}
I believe it has something to do with the above, and this:

Code: Select all

menuTextures[1] = GL_LoadIMG("data\\textures\\homeicon.png");
printf("\n");
menuTextures[2] = GL_LoadIMG("data\\textures\\file.png");
printf("\n");
menuTextures[3] = GL_LoadIMG("data\\textures\\edit.png");
printf("\n");
menuTextures[4] = GL_LoadIMG("data\\textures\\mode.png");
printf("\n");
menuTextures[5] = GL_LoadIMG("data\\textures\\options.png");
printf("\n");
That's what loads the textures... well sort of. no matter what number I use in place of NUMBER it displays the last texture loaded:
glBindTexture(GL_TEXTURE_2D, menuTextures[NUMBER]);



EDIT: I take that back, depending on whether I put glBindTexture or GL_Begin first here: (I can access the first or last texture, but still none between)

Code: Select all

glBindTexture(GL_TEXTURE_2D, menuTextures[3]);
glBegin(GL_QUADS);
glTexCoord2f (0.0, 0.0);
glVertex3f (0.0, 0.0, 0.0);

glTexCoord2f (1.0, 0.0);
glVertex3f (50.0, 0.0, 0.0);

glTexCoord2f (1.0, 1.0);
glVertex3f (50.0, 50.0, 0.0);

glTexCoord2f (0.0, 1.0);
glVertex3f (0.0, 50.0, 0.0);
glEnd();

Re: Multiple texturing issues.

Posted: Wed Jun 22, 2011 12:52 am
by qpHalcy0n
Your load function is not returning the texture handle. It's returning true or false. You're then assigning this value to "menuTextures[x]" and attempting to bind either true or false as a texture object. :]

Re: Multiple texturing issues.

Posted: Wed Jun 22, 2011 12:58 am
by MadPumpkin
I'm just the god of stupid as shit mistakes today, I don't know what I would do without you qp xD

Re: Multiple texturing issues.

Posted: Wed Jun 22, 2011 2:30 pm
by GroundUpEngine
MadPumpkin wrote:I'm just the god of stupid as shit mistakes today, I don't know what I would do without you qp xD
Aha it happens... especially if you end up code till late at night like most programmers ;)

Re: Multiple texturing issues.

Posted: Thu Jun 23, 2011 1:54 pm
by MadPumpkin
GroundUpEngine wrote:
MadPumpkin wrote:I'm just the god of stupid as shit mistakes today, I don't know what I would do without you qp xD
Aha it happens... especially if you end up code till late at night like most programmers ;)
That's usually when I START coding xD