[Issue] Trying to fix black textures.

This commit is contained in:
Quentin Bazin 2014-12-20 12:59:59 +01:00
parent f69b2e9580
commit d638c7067c
7 changed files with 13 additions and 18 deletions

View File

@ -28,7 +28,7 @@ LIBS += -framework OpenGL
#---------------------------------------------------------------------------------
else
#---------------------------------------------------------------------------------
LIBS += -lGLEW -lGL
LIBS += -lGL
#---------------------------------------------------------------------------------
endif
#---------------------------------------------------------------------------------

View File

@ -19,7 +19,7 @@
#define OPENGL_HPP_
#ifdef __APPLE__
#include <OpenGL/glew.h>
#include <OpenGL/gl.h>
#else
#ifdef __MINGW32__
#include <GL/glew.h>

View File

@ -26,10 +26,10 @@
class Texture {
public:
Texture();
Texture(std::string filename);
Texture(const std::string &filename);
~Texture();
void load(std::string filename);
void load(const std::string &filename);
static void bind(const Texture *texture);
@ -43,8 +43,6 @@ class Texture {
u16 m_height;
GLuint m_texture;
u8 m_paletteID;
};
#endif // TEXTURE_HPP_

View File

@ -20,8 +20,6 @@
#include <vector>
#include <SFML/Graphics/Texture.hpp>
#include "Shader.hpp"
#include "Texture.hpp"
#include "VertexBuffer.hpp"

View File

@ -30,7 +30,8 @@ void SDLManager::init() {
sdlInitialized = true;
}
if(!IMG_Init(IMG_INIT_PNG) & IMG_INIT_PNG) {
int imgFlags = IMG_INIT_PNG;
if(!IMG_Init(imgFlags) & imgFlags) {
EXCEPTION("SDL image init error:", SDL_GetError());
} else {
imgInitialized = true;

View File

@ -22,14 +22,14 @@
Texture::Texture() {
}
Texture::Texture(std::string filename) {
Texture::Texture(const std::string &filename) {
load(filename);
}
Texture::~Texture() {
}
void Texture::load(std::string filename) {
void Texture::load(const std::string &filename) {
SDL_Surface *surface = IMG_Load(filename.c_str());
if(!surface) {
throw EXCEPTION("Failed to load texture:", filename);
@ -45,17 +45,15 @@ void Texture::load(std::string filename) {
bind(this);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, m_width, m_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, surface->pixels);
//glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);
GLenum format = (surface->format->BytesPerPixel == 4) ? GL_RGBA : GL_RGB;
glTexImage2D(GL_TEXTURE_2D, 0, format, m_width, m_height, 0, format, GL_UNSIGNED_BYTE, surface->pixels);
bind(nullptr);
SDL_FreeSurface(surface);
m_paletteID = 0;
}
void Texture::bind(const Texture *texture) {

View File

@ -200,10 +200,10 @@ void Chunk::update() {
}
void Chunk::draw(Shader &shader) {
//if(m_changed) update();
if(m_changed) {
int truc = GameClock::getTicks(true);
//if(m_changed) update();
update();
DEBUG("Chunk", m_x, m_y, m_z, "| Vertices:", m_vertices.size(), "| Update time:", GameClock::getTicks(true) - truc, "ms");