unfortunatly, have problems glbindtexture().
when try bind bitmap image skybox see white. tested other figures , not work. sure problem in engine class.
this engine.cpp, here load 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 class this:
engine::bindtexture(path); any ideas?
i see few possible problems.
- are sure load not compressed .bmp file, please check bfh.bicompression
- you can use gl_rgba if bih->bibitcount == 32, try use gl_rgb
- try use gl_unsigned_byte instead of gl_unsigned_int
- please check image size, think skybox should 128x128, 256x256, 512x512, i.e. power-of-2 texture size
- replace
fread(data, sizeof(data), 1, input);
on
fread(data, 1, bih->biwidth * bih->biheight * bih->bibitcount / 8, input);
Comments
Post a Comment