Unfortunatly, I have some problems with glBindTexture().
When I try to bind a bitmap image to my skybox I only see some white. I tested it with other figures and also that does not work. I am sure the problem is in the Engine class.
This is my engine.cpp, here I load the bitmap et cetra:
#include <windows.h>
#include <gl/GL.h>
#include <iostream>
#include "engine.h"
unsigned char* Engine::getImageContents(char path[], BITMAPINFOHEADER* bih) {
FILE* input; fopen_s(&input, path, "rb");
if (input != NULL) {
BITMAPFILEHEADER bfh;
fread(&bfh, sizeof(bfh), 1, input);
fread(&bih, sizeof(bih), 1, input);
unsigned char* data =
new unsigned char[bih->biWidth * bih->biHeight * bih->biBitCount / 8];
fread(data, sizeof(data), 1, input);
fclose(input);
return data;
} else {
return NULL;
}
}
void Engine::bindTexture(char path[]) {
this->bindTexture(this->getTextureId(path));
}
void Engine::bindTexture(unsigned int id) {
if (id != this->boundTexture) {
glBindTexture(GL_TEXTURE_2D, id);
this->boundTexture = id;
}
}
unsigned int Engine::getTextureId(char path[]) {
if (this->textureMap.find(path) != this->textureMap.end()) {
return this->textureMap[path];
} else {
unsigned int id; glGenTextures(1, &id);
BITMAPINFOHEADER bih;
unsigned char* data = this->getImageContents(path, &bih);
this->setupTexture(data, id, bih.biWidth, bih.biHeight);
this->textureMap.insert(std::pair<char*, unsigned int>(path, id));
return id;
}
}
void Engine::setupTexture(unsigned char* data, unsigned int id, long width, long height) {
this->setupTexture(data, id, width, height, false);
}
void Engine::setupTexture(unsigned char* data, unsigned int id, long width, long height, bool clamp) {
std::cout << height << std::endl;
this->bindTexture(id);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, clamp ? GL_CLAMP : GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, clamp ? GL_CLAMP : GL_REPEAT);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_INT, data);
}
I use the class like this:
Engine::bindTexture(path);
Any ideas?
I see few possible problems.