fixed stupid jpg error

This commit is contained in:
Ben
2019-01-14 00:13:24 +00:00
parent 92390743bd
commit 81996a18e0
6 changed files with 9 additions and 2 deletions

View File

@@ -3,6 +3,7 @@ project(gl-cube)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} CMakeModules/)
cmake_policy(SET CMP0037 OLD)
set(CMAKE_BUILD_TYPE Debug)
set(executable cube.a)
set(SrcDIR ./src)
@@ -20,6 +21,7 @@ find_package(GLEW REQUIRED)
include_directories(${executable}
${SDL2_INCLUDE_DIR}
${SDL2_IMAGE_INCLUDE_DIR}
${PNG_INCLUDE_DIR}
${GLEW_INCLUDE_DIRS}
${IncludeDIR}
)
@@ -36,6 +38,7 @@ set_target_properties(${executable} PROPERTIES
)
target_link_libraries(${executable}
${PNG_LIBRARY}
SDL2
SDL2_image
PNG::PNG

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.5 KiB

View File

@@ -32,7 +32,9 @@ public:
int main(int argc, char** argv) {
Game* game = new Game();
SDL_Init(SDL_INIT_EVERYTHING);
IMG_Init(IMG_INIT_JPG | IMG_INIT_PNG);
SDL_GL_SetSwapInterval(0);
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
@@ -110,7 +112,9 @@ int main(int argc, char** argv) {
simpleShader.load("./resources/shaders/simple").attatch().link().use();
// Load texture from file
SDL_Surface* sur = IMG_Load("./resources/textures/dirtside.jpg");
SDL_Surface* sur = IMG_Load("./resources/textures/dirtside.png");
if (sur == NULL)
std::cerr << "Failed to load image: " << IMG_GetError() << std::endl;
// Set up a GL texture
GLuint tex;
glBindTexture(GL_TEXTURE_2D, tex);
@@ -118,7 +122,7 @@ int main(int argc, char** argv) {
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
// Passes SDL texture into the texture buffer for GL to use in shaders
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, sur->w, sur->h, 0, GL_RGB, GL_UNSIGNED_BYTE, sur->pixels);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, sur->w, sur->h, 0, GL_RGBA, GL_UNSIGNED_BYTE, sur->pixels);
GLint posAttrib = glGetAttribLocation(simpleShader.getProgram(), "position");
glEnableVertexAttribArray(posAttrib);