Frag Shader:
#version 400
uniform sampler2D Texture0 ;
in vec2 out_MultiTextureCoord1;
in vec4 ex_Color;
out vec4 out_Color;
void main(void)
{
out_Color = texture(Texture0, out_MultiTextureCoord1);
}Vert Shader:
#version 400
layout(location=0) in vec4 in_Position;
layout(location=1) in vec4 in_Color;
layout(location=2) in vec4 in_Normal;
layout(location=3) in vec2 in_MultiTextureCoord1;
uniform mat4 ViewMatrix;
uniform mat4 ProjectionMatrix;
uniform mat4 WorldMatrix;
out vec2 out_MultiTextureCoord1;
out vec4 ex_Color;
void main(void)
{
gl_Position = (ProjectionMatrix * ViewMatrix * WorldMatrix) * in_Position;
ex_Color = in_Color;
out_MultiTextureCoord1 = in_MultiTextureCoord1;
}Texture Loading Code:
GLuint CResourceManager::LoadTexture(std::string fileName)
{
ILuint imageID; // Create an image ID as a ULuint
GLuint textureID; // Create a texture ID as a GLuint
ILboolean success; // Create a flag to keep track of success/failure
ILenum error; // Create a flag to keep track of the IL error state
ilGenImages(1, &imageID); // Generate the image ID
ilBindImage(imageID); // Bind the image
success = ilLoadImage(fileName.c_str()); // Load the image file
// If we managed to load the image, then we can start to do things with it...
if (success)
{
// If the image is flipped (i.e. upside-down and mirrored, flip it the right way up!)
ILinfo ImageInfo;
iluGetImageInfo(&ImageInfo);
if (ImageInfo.Origin == IL_ORIGIN_UPPER_LEFT)
{
iluFlipImage();
}
// Convert the image into a suitable format to work with
// NOTE: If your image contains alpha channel you can replace IL_RGB with IL_RGBA
success = ilConvertImage(IL_RGB, IL_UNSIGNED_BYTE);
// Quit out if we failed the conversion
if (!success)
{
error = ilGetError();
std::cout << "Image conversion failed - IL reports error: " << error << " - " << iluErrorString(error) << std::endl;
exit(-1);
}
// Generate a new texture
glGenTextures(1, &textureID);
// Bind the texture to a name
glBindTexture(GL_TEXTURE_2D, textureID);
glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
// Set texture clamping method
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
// Set texture interpolation method to the highest visual quality it can be:
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glGenerateMipmap(GL_TEXTURE_2D); // Note: This requires OpenGL 3.0 or higher
// Specify the texture specification
glTexImage2D(GL_TEXTURE_2D, // Type of texture
0, // Pyramid level (for mip-mapping) - 0 is the top level
ilGetInteger(IL_IMAGE_BPP), // Image colour depth
ilGetInteger(IL_IMAGE_WIDTH), // Image width
ilGetInteger(IL_IMAGE_HEIGHT), // Image height
0, // Border width in pixels (can either be 1 or 0)
ilGetInteger(IL_IMAGE_FORMAT), // Image format (i.e. RGB, RGBA, BGR etc.)
GL_UNSIGNED_BYTE, // Image data type
ilGetData()); // The actual image data itself
}
else // If we failed to open the image file in the first place...
{
error = ilGetError();
std::cout << "Image load failed - IL reports error: " << error << " - " << iluErrorString(error) << std::endl;
exit(-1);
}
ilDeleteImages(1, &imageID); // Because we have already copied image data into texture data we can release memory used by image.
std::cout << "Texture creation successful." << std::endl;
return textureID; // Return the GLuint to the texture so you can use it!
}Render code:
CMatrixManager::GetInstance()->SetShaderMatrices(m_Shader);
glUseProgram(m_Shader);
for(int x = 0; x < m_MeshCount; ++x)
{
glUniform1i(glGetUniformLocation(m_Shader, "Texture0"), 0);
glActiveTexture( GL_TEXTURE0 );
glBindTexture(GL_TEXTURE_2D, m_Meshes[x].m_Textures[0]);
glUseProgram(m_Shader);
//CRenderingSystem::GetInstance()->RenderMesh(&m_Meshes[x]);
glBindVertexArray(m_Meshes[x].m_VertexArrayID);
glDrawElements(m_Meshes[x].m_RenderType, m_Meshes[x].m_PrimitiveCount, GL_UNSIGNED_INT, 0);
}If there is any other part of the code that may be causing the problem please tell me so I can post it
Thank you,
David






