Hi all,
This is my first post here
Even if I did this multiple time with my new engine I have some problem with displaying textures…
My entire code is here: GitHub - newincpp/G_Rand: A tiny portable OpenGL (for now) library with minimal dependency at execution in the case the error don’t come from where I expect…
Well, here is what I did in my fragment shader (the interesting part):
layout(location = 8)uniform int textureAmount;
uniform sampler2D tex[8];
...
void main() {
int i = 0;
outColor = lighting();
while (i < textureAmount) {
outColor *= texture(tex[i], fUVCoord);
}
}
For my texture loading I use DevIL but because I had nothing displayed I use an hard coded texture instead to be sure it’s not a loading problem… Here is my code:
void GRand::Texture::load() noexcept {
if (!_textureId) {
glDeleteTextures(1, &_textureId);
_textureId = 0;
}
glGenTextures(1, &_textureId);
glBindTexture(GL_TEXTURE_2D, _textureId);
if (_filename.size() == 0) { // hardCoded texture part....
std::cout << "\e[33;1mno texture file name, using the default one\e[0m" << std::endl;
float pixels[] = {
.7f, .7f, .7f, .7f, .0f, .0f,
.7f, .0f, .0f, .7f, .7f, .7f
};
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 2, 2, 0, GL_RGB, GL_FLOAT, pixels);
return;
}
std::cout << "loading file: " << _filename << std::endl;
ilBindImage(_imgId);
ilEnable(IL_ORIGIN_SET);
ilOriginFunc(IL_ORIGIN_LOWER_LEFT);
if (!ilLoadImage(_filename.c_str())) {
std::cout << "\e[31;1mfailed to load: " << _filename << "\e[0m" << std::endl;
return;
}
ilConvertImage(IL_RGBA, IL_UNSIGNED_BYTE);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, ilGetInteger(IL_IMAGE_WIDTH), ilGetInteger(IL_IMAGE_HEIGHT), 0, GL_RGBA, GL_UNSIGNED_BYTE, ilGetData());
GLenum errCode;
if ((errCode = glGetError()) != GL_NO_ERROR) {
std::cout << _glErrorToString[errCode - GL_INVALID_ENUM] << std::endl;
}
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
//glGenerateMipmap(GL_TEXTURE_2D);
_loaded = true;
}
my bind function is pretty simple:
inline void bind(GLenum textureUnit_) const noexcept {
glActiveTexture(textureUnit_);
glBindTexture(GL_TEXTURE_2D, _textureId);
}
and To finish because here is how I use my textures:
void GRand::Material::use() const noexcept {
unsigned int i = 0;
for (decltype(_textures)::value_type t : _textures) { // _textures is a std::vector<const Texture*>
t->bind(GL_TEXTURE0 + i);
glUniform1i(glGetUniformLocation(_shaderProgram, _StexStringArray_[i]), 0);
}
_uTextureAmount.upload(); // _uTextureAmount is a representation of the uniform textureAmount on my fragment... upload it to syncronize it
glUseProgram(_shaderProgram);
}
I want to say that this is not a mapping problem because when I do this:
outColor = vec4(fUVCoord, 0,1);
In my fragment I can see my texture map like that:
[ATTACH=CONFIG]1118[/ATTACH]
If you want to download the code to test things you have to know it only work of linux right now and compile only with clang. the dependency are only libjpeg libpng libtiff liblGLU libXrandr libXi libGL libpthread liblX11 and libXxf86vm I’ve included the rest in the repo. (note: you will need sse sse2 and sse3…)