loader functions moved to external file
This commit is contained in:
Binary file not shown.
10
opengl-test-two/include/loaders.h
Normal file
10
opengl-test-two/include/loaders.h
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
#ifndef LOADERS_H
|
||||||
|
#define LOADERS_H
|
||||||
|
|
||||||
|
#define GLEW_STATIC
|
||||||
|
#include <GL/glew.h>
|
||||||
|
|
||||||
|
int InitLoaders();
|
||||||
|
GLuint LoadTexture(char *filename,int *textw,int *texth);
|
||||||
|
GLuint LoadShaders(const char * vertex_file_path,const char * fragment_file_path);
|
||||||
|
#endif // LOADERS_H
|
||||||
@@ -4,151 +4,9 @@
|
|||||||
#include <GL/glew.h>
|
#include <GL/glew.h>
|
||||||
#include <GLFW/glfw3.h>
|
#include <GLFW/glfw3.h>
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL2/SDL.h>
|
||||||
#include <SDL2/SDL_image.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <iostream>
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <vector>
|
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
#include "loaders.h"
|
||||||
GLuint LoadTexture(char *filename,int *textw,int *texth) {
|
|
||||||
SDL_Surface *surface;
|
|
||||||
GLuint textureid;
|
|
||||||
int mode;
|
|
||||||
surface = IMG_Load(filename);
|
|
||||||
// Or if you don't use SDL_image you can use SDL_LoadBMP here instead:
|
|
||||||
// surface = SDL_LoadBMP(filename);
|
|
||||||
|
|
||||||
// could not load filename
|
|
||||||
if (!surface) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// work out what format to tell glTexImage2D to use...
|
|
||||||
if (surface->format->BytesPerPixel == 3) { // RGB 24bit
|
|
||||||
mode = GL_RGB;
|
|
||||||
|
|
||||||
} else if (surface->format->BytesPerPixel == 4) { // RGBA 32bit
|
|
||||||
mode = GL_RGBA;
|
|
||||||
} else {
|
|
||||||
SDL_FreeSurface(surface);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
*textw=surface->w;
|
|
||||||
*texth=surface->h;
|
|
||||||
// create one texture name
|
|
||||||
glGenTextures(1, &textureid);
|
|
||||||
// tell opengl to use the generated texture name
|
|
||||||
glBindTexture(GL_TEXTURE_2D, textureid);
|
|
||||||
// this reads from the sdl surface and puts it into an opengl texture
|
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, mode, surface->w, surface->h, 0, mode, GL_UNSIGNED_BYTE, surface->pixels);
|
|
||||||
// these affect how this texture is drawn later on...glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
|
||||||
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);
|
|
||||||
// clean up
|
|
||||||
SDL_FreeSurface(surface);
|
|
||||||
return textureid;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
GLuint LoadShaders(const char * vertex_file_path,const char * fragment_file_path){
|
|
||||||
|
|
||||||
// Create the shaders
|
|
||||||
GLuint VertexShaderID = glCreateShader(GL_VERTEX_SHADER);
|
|
||||||
GLuint FragmentShaderID = glCreateShader(GL_FRAGMENT_SHADER);
|
|
||||||
|
|
||||||
// Read the Vertex Shader code from the file
|
|
||||||
std::string VertexShaderCode;
|
|
||||||
std::ifstream VertexShaderStream(vertex_file_path, std::ios::in);
|
|
||||||
if(VertexShaderStream.is_open()){
|
|
||||||
std::string Line = "";
|
|
||||||
while(getline(VertexShaderStream, Line))
|
|
||||||
VertexShaderCode += "\n" + Line;
|
|
||||||
VertexShaderStream.close();
|
|
||||||
}else{
|
|
||||||
printf("Impossible to open %s. Are you in the right directory ? Don't forget to read the FAQ !\n", vertex_file_path);
|
|
||||||
getchar();
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Read the Fragment Shader code from the file
|
|
||||||
std::string FragmentShaderCode;
|
|
||||||
std::ifstream FragmentShaderStream(fragment_file_path, std::ios::in);
|
|
||||||
if(FragmentShaderStream.is_open()){
|
|
||||||
std::string Line = "";
|
|
||||||
while(getline(FragmentShaderStream, Line))
|
|
||||||
FragmentShaderCode += "\n" + Line;
|
|
||||||
FragmentShaderStream.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
GLint Result = GL_FALSE;
|
|
||||||
int InfoLogLength;
|
|
||||||
|
|
||||||
|
|
||||||
// Compile Vertex Shader
|
|
||||||
printf("Compiling shader : %s\n", vertex_file_path);
|
|
||||||
char const * VertexSourcePointer = VertexShaderCode.c_str();
|
|
||||||
glShaderSource(VertexShaderID, 1, &VertexSourcePointer , NULL);
|
|
||||||
glCompileShader(VertexShaderID);
|
|
||||||
|
|
||||||
// Check Vertex Shader
|
|
||||||
glGetShaderiv(VertexShaderID, GL_COMPILE_STATUS, &Result);
|
|
||||||
glGetShaderiv(VertexShaderID, GL_INFO_LOG_LENGTH, &InfoLogLength);
|
|
||||||
if ( InfoLogLength > 0 ){
|
|
||||||
std::vector<char> VertexShaderErrorMessage(InfoLogLength+1);
|
|
||||||
glGetShaderInfoLog(VertexShaderID, InfoLogLength, NULL, &VertexShaderErrorMessage[0]);
|
|
||||||
printf("%s\n", &VertexShaderErrorMessage[0]);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Compile Fragment Shader
|
|
||||||
printf("Compiling shader : %s\n", fragment_file_path);
|
|
||||||
char const * FragmentSourcePointer = FragmentShaderCode.c_str();
|
|
||||||
glShaderSource(FragmentShaderID, 1, &FragmentSourcePointer , NULL);
|
|
||||||
glCompileShader(FragmentShaderID);
|
|
||||||
|
|
||||||
// Check Fragment Shader
|
|
||||||
glGetShaderiv(FragmentShaderID, GL_COMPILE_STATUS, &Result);
|
|
||||||
glGetShaderiv(FragmentShaderID, GL_INFO_LOG_LENGTH, &InfoLogLength);
|
|
||||||
if ( InfoLogLength > 0 ){
|
|
||||||
std::vector<char> FragmentShaderErrorMessage(InfoLogLength+1);
|
|
||||||
glGetShaderInfoLog(FragmentShaderID, InfoLogLength, NULL, &FragmentShaderErrorMessage[0]);
|
|
||||||
printf("%s\n", &FragmentShaderErrorMessage[0]);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Link the program
|
|
||||||
printf("Linking program\n");
|
|
||||||
GLuint ProgramID = glCreateProgram();
|
|
||||||
glAttachShader(ProgramID, VertexShaderID);
|
|
||||||
glAttachShader(ProgramID, FragmentShaderID);
|
|
||||||
glLinkProgram(ProgramID);
|
|
||||||
|
|
||||||
// Check the program
|
|
||||||
glGetProgramiv(ProgramID, GL_LINK_STATUS, &Result);
|
|
||||||
glGetProgramiv(ProgramID, GL_INFO_LOG_LENGTH, &InfoLogLength);
|
|
||||||
if ( InfoLogLength > 0 ){
|
|
||||||
std::vector<char> ProgramErrorMessage(InfoLogLength+1);
|
|
||||||
glGetProgramInfoLog(ProgramID, InfoLogLength, NULL, &ProgramErrorMessage[0]);
|
|
||||||
printf("%s\n", &ProgramErrorMessage[0]);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
glDetachShader(ProgramID, VertexShaderID);
|
|
||||||
glDetachShader(ProgramID, FragmentShaderID);
|
|
||||||
|
|
||||||
glDeleteShader(VertexShaderID);
|
|
||||||
glDeleteShader(FragmentShaderID);
|
|
||||||
|
|
||||||
return ProgramID;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int main(int argc, char* args[]) {
|
int main(int argc, char* args[]) {
|
||||||
GLFWwindow* window;
|
GLFWwindow* window;
|
||||||
@@ -179,16 +37,16 @@ int main(int argc, char* args[]) {
|
|||||||
GLenum error = glGetError();
|
GLenum error = glGetError();
|
||||||
if (error != GL_NO_ERROR)
|
if (error != GL_NO_ERROR)
|
||||||
{
|
{
|
||||||
std::cout << "OpenGL Error: " << error << std::endl;
|
printf("OpenGL Error: %d",error);
|
||||||
}
|
}
|
||||||
GLenum glewinit = glewInit();
|
GLenum glewinit = glewInit();
|
||||||
if (glewinit != GLEW_OK) {
|
if (glewinit != GLEW_OK) {
|
||||||
std::cout << "Glew not okay! " << glewinit;
|
printf("Glew not okay! %d",glewinit);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* SDL */
|
/* SDL */
|
||||||
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
|
if (InitLoaders() < 0) {
|
||||||
printf("SDL Error");
|
printf("SDL Error");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,6 +13,7 @@
|
|||||||
<Option compiler="gcc" />
|
<Option compiler="gcc" />
|
||||||
<Compiler>
|
<Compiler>
|
||||||
<Add option="-g" />
|
<Add option="-g" />
|
||||||
|
<Add directory="include" />
|
||||||
</Compiler>
|
</Compiler>
|
||||||
</Target>
|
</Target>
|
||||||
<Target title="Release">
|
<Target title="Release">
|
||||||
@@ -22,6 +23,7 @@
|
|||||||
<Option compiler="gcc" />
|
<Option compiler="gcc" />
|
||||||
<Compiler>
|
<Compiler>
|
||||||
<Add option="-O2" />
|
<Add option="-O2" />
|
||||||
|
<Add directory="include" />
|
||||||
</Compiler>
|
</Compiler>
|
||||||
<Linker>
|
<Linker>
|
||||||
<Add option="-s" />
|
<Add option="-s" />
|
||||||
@@ -44,7 +46,9 @@
|
|||||||
<Add library="SDL2_image" />
|
<Add library="SDL2_image" />
|
||||||
<Add directory="lib" />
|
<Add directory="lib" />
|
||||||
</Linker>
|
</Linker>
|
||||||
|
<Unit filename="include/loaders.h" />
|
||||||
<Unit filename="main.cpp" />
|
<Unit filename="main.cpp" />
|
||||||
|
<Unit filename="src/loaders.cpp" />
|
||||||
<Unit filename="trimap.fragmentshader" />
|
<Unit filename="trimap.fragmentshader" />
|
||||||
<Unit filename="trimap.vertexshader" />
|
<Unit filename="trimap.vertexshader" />
|
||||||
<Extensions>
|
<Extensions>
|
||||||
|
|||||||
@@ -368,3 +368,377 @@
|
|||||||
<OpenGL/glu.h>
|
<OpenGL/glu.h>
|
||||||
<GL/glu.h>
|
<GL/glu.h>
|
||||||
|
|
||||||
|
1473412967 source:d:\profile\ksy\eigene dateien\git\imanox-chroma-matting\opengl-test-two\main.cpp
|
||||||
|
<GL/glew.h>
|
||||||
|
<GLFW/glfw3.h>
|
||||||
|
<iostream>
|
||||||
|
<fstream>
|
||||||
|
<vector>
|
||||||
|
<stdexcept>
|
||||||
|
"loaders.h"
|
||||||
|
|
||||||
|
1473141855 d:\profile\ksy\eigene dateien\git\imanox-chroma-matting\opengl-test-two\include\gl\glew.h
|
||||||
|
<stddef.h>
|
||||||
|
<inttypes.h>
|
||||||
|
<stdint.h>
|
||||||
|
<inttypes.h>
|
||||||
|
<Availability.h>
|
||||||
|
<OpenGL/glu.h>
|
||||||
|
<GL/glu.h>
|
||||||
|
|
||||||
|
1473141855 d:\profile\ksy\eigene dateien\git\imanox-chroma-matting\opengl-test-two\include\glfw\glfw3.h
|
||||||
|
<stddef.h>
|
||||||
|
<stdint.h>
|
||||||
|
<OpenGL/gl3.h>
|
||||||
|
<OpenGL/gl3ext.h>
|
||||||
|
<OpenGL/gl.h>
|
||||||
|
<OpenGL/glu.h>
|
||||||
|
<GL/glcorearb.h>
|
||||||
|
<GLES/gl.h>
|
||||||
|
<GLES/glext.h>
|
||||||
|
<GLES2/gl2.h>
|
||||||
|
<GLES2/gl2ext.h>
|
||||||
|
<GLES3/gl3.h>
|
||||||
|
<GLES2/gl2ext.h>
|
||||||
|
<GLES3/gl31.h>
|
||||||
|
<GLES2/gl2ext.h>
|
||||||
|
<vulkan/vulkan.h>
|
||||||
|
<GL/gl.h>
|
||||||
|
<GL/glext.h>
|
||||||
|
<GL/glu.h>
|
||||||
|
|
||||||
|
1473141855 d:\profile\ksy\eigene dateien\git\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl.h
|
||||||
|
"SDL_main.h"
|
||||||
|
"SDL_stdinc.h"
|
||||||
|
"SDL_assert.h"
|
||||||
|
"SDL_atomic.h"
|
||||||
|
"SDL_audio.h"
|
||||||
|
"SDL_clipboard.h"
|
||||||
|
"SDL_cpuinfo.h"
|
||||||
|
"SDL_endian.h"
|
||||||
|
"SDL_error.h"
|
||||||
|
"SDL_events.h"
|
||||||
|
"SDL_filesystem.h"
|
||||||
|
"SDL_joystick.h"
|
||||||
|
"SDL_gamecontroller.h"
|
||||||
|
"SDL_haptic.h"
|
||||||
|
"SDL_hints.h"
|
||||||
|
"SDL_loadso.h"
|
||||||
|
"SDL_log.h"
|
||||||
|
"SDL_messagebox.h"
|
||||||
|
"SDL_mutex.h"
|
||||||
|
"SDL_power.h"
|
||||||
|
"SDL_render.h"
|
||||||
|
"SDL_rwops.h"
|
||||||
|
"SDL_system.h"
|
||||||
|
"SDL_thread.h"
|
||||||
|
"SDL_timer.h"
|
||||||
|
"SDL_version.h"
|
||||||
|
"SDL_video.h"
|
||||||
|
"begin_code.h"
|
||||||
|
"close_code.h"
|
||||||
|
|
||||||
|
1473141855 d:\profile\ksy\eigene dateien\git\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_main.h
|
||||||
|
"SDL_stdinc.h"
|
||||||
|
"begin_code.h"
|
||||||
|
"close_code.h"
|
||||||
|
|
||||||
|
1473141855 d:\profile\ksy\eigene dateien\git\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_stdinc.h
|
||||||
|
"SDL_config.h"
|
||||||
|
<sys/types.h>
|
||||||
|
<stdio.h>
|
||||||
|
<stdlib.h>
|
||||||
|
<stddef.h>
|
||||||
|
<stdarg.h>
|
||||||
|
<stdlib.h>
|
||||||
|
<malloc.h>
|
||||||
|
<stddef.h>
|
||||||
|
<stdarg.h>
|
||||||
|
<memory.h>
|
||||||
|
<string.h>
|
||||||
|
<strings.h>
|
||||||
|
<inttypes.h>
|
||||||
|
<stdint.h>
|
||||||
|
<ctype.h>
|
||||||
|
<math.h>
|
||||||
|
<float.h>
|
||||||
|
<iconv.h>
|
||||||
|
<sal.h>
|
||||||
|
"begin_code.h"
|
||||||
|
<alloca.h>
|
||||||
|
<malloc.h>
|
||||||
|
<malloc.h>
|
||||||
|
<malloc.h>
|
||||||
|
<stdlib.h>
|
||||||
|
"close_code.h"
|
||||||
|
|
||||||
|
1473141855 d:\profile\ksy\eigene dateien\git\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_config.h
|
||||||
|
"SDL_platform.h"
|
||||||
|
|
||||||
|
1473141855 d:\profile\ksy\eigene dateien\git\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_platform.h
|
||||||
|
"AvailabilityMacros.h"
|
||||||
|
"TargetConditionals.h"
|
||||||
|
<winapifamily.h>
|
||||||
|
"begin_code.h"
|
||||||
|
"close_code.h"
|
||||||
|
|
||||||
|
1473141855 d:\profile\ksy\eigene dateien\git\imanox-chroma-matting\opengl-test-two\include\sdl2\begin_code.h
|
||||||
|
|
||||||
|
1473141855 d:\profile\ksy\eigene dateien\git\imanox-chroma-matting\opengl-test-two\include\sdl2\close_code.h
|
||||||
|
|
||||||
|
1473141855 d:\profile\ksy\eigene dateien\git\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_assert.h
|
||||||
|
"SDL_config.h"
|
||||||
|
"begin_code.h"
|
||||||
|
<signal.h>
|
||||||
|
"close_code.h"
|
||||||
|
|
||||||
|
1473141855 d:\profile\ksy\eigene dateien\git\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_atomic.h
|
||||||
|
"SDL_stdinc.h"
|
||||||
|
"SDL_platform.h"
|
||||||
|
"begin_code.h"
|
||||||
|
<mbarrier.h>
|
||||||
|
"close_code.h"
|
||||||
|
|
||||||
|
1473141855 d:\profile\ksy\eigene dateien\git\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_audio.h
|
||||||
|
"SDL_stdinc.h"
|
||||||
|
"SDL_error.h"
|
||||||
|
"SDL_endian.h"
|
||||||
|
"SDL_mutex.h"
|
||||||
|
"SDL_thread.h"
|
||||||
|
"SDL_rwops.h"
|
||||||
|
"begin_code.h"
|
||||||
|
"close_code.h"
|
||||||
|
|
||||||
|
1473141855 d:\profile\ksy\eigene dateien\git\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_error.h
|
||||||
|
"SDL_stdinc.h"
|
||||||
|
"begin_code.h"
|
||||||
|
"close_code.h"
|
||||||
|
|
||||||
|
1473141855 d:\profile\ksy\eigene dateien\git\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_endian.h
|
||||||
|
"SDL_stdinc.h"
|
||||||
|
<endian.h>
|
||||||
|
"begin_code.h"
|
||||||
|
"close_code.h"
|
||||||
|
|
||||||
|
1473141855 d:\profile\ksy\eigene dateien\git\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_mutex.h
|
||||||
|
"SDL_stdinc.h"
|
||||||
|
"SDL_error.h"
|
||||||
|
"begin_code.h"
|
||||||
|
"close_code.h"
|
||||||
|
|
||||||
|
1473141855 d:\profile\ksy\eigene dateien\git\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_thread.h
|
||||||
|
"SDL_stdinc.h"
|
||||||
|
"SDL_error.h"
|
||||||
|
"SDL_atomic.h"
|
||||||
|
"SDL_mutex.h"
|
||||||
|
"begin_code.h"
|
||||||
|
<process.h>
|
||||||
|
"close_code.h"
|
||||||
|
|
||||||
|
1473141855 d:\profile\ksy\eigene dateien\git\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_rwops.h
|
||||||
|
"SDL_stdinc.h"
|
||||||
|
"SDL_error.h"
|
||||||
|
"begin_code.h"
|
||||||
|
"close_code.h"
|
||||||
|
|
||||||
|
1473141855 d:\profile\ksy\eigene dateien\git\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_clipboard.h
|
||||||
|
"SDL_stdinc.h"
|
||||||
|
"begin_code.h"
|
||||||
|
"close_code.h"
|
||||||
|
|
||||||
|
1473141855 d:\profile\ksy\eigene dateien\git\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_cpuinfo.h
|
||||||
|
"SDL_stdinc.h"
|
||||||
|
<intrin.h>
|
||||||
|
<intrin.h>
|
||||||
|
<altivec.h>
|
||||||
|
<mmintrin.h>
|
||||||
|
<mm3dnow.h>
|
||||||
|
<xmmintrin.h>
|
||||||
|
<emmintrin.h>
|
||||||
|
"begin_code.h"
|
||||||
|
"close_code.h"
|
||||||
|
|
||||||
|
1473141855 d:\profile\ksy\eigene dateien\git\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_events.h
|
||||||
|
"SDL_stdinc.h"
|
||||||
|
"SDL_error.h"
|
||||||
|
"SDL_video.h"
|
||||||
|
"SDL_keyboard.h"
|
||||||
|
"SDL_mouse.h"
|
||||||
|
"SDL_joystick.h"
|
||||||
|
"SDL_gamecontroller.h"
|
||||||
|
"SDL_quit.h"
|
||||||
|
"SDL_gesture.h"
|
||||||
|
"SDL_touch.h"
|
||||||
|
"begin_code.h"
|
||||||
|
"close_code.h"
|
||||||
|
|
||||||
|
1473141855 d:\profile\ksy\eigene dateien\git\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_video.h
|
||||||
|
"SDL_stdinc.h"
|
||||||
|
"SDL_pixels.h"
|
||||||
|
"SDL_rect.h"
|
||||||
|
"SDL_surface.h"
|
||||||
|
"begin_code.h"
|
||||||
|
"close_code.h"
|
||||||
|
|
||||||
|
1473141855 d:\profile\ksy\eigene dateien\git\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_pixels.h
|
||||||
|
"SDL_stdinc.h"
|
||||||
|
"begin_code.h"
|
||||||
|
"close_code.h"
|
||||||
|
|
||||||
|
1473141855 d:\profile\ksy\eigene dateien\git\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_rect.h
|
||||||
|
"SDL_stdinc.h"
|
||||||
|
"SDL_error.h"
|
||||||
|
"SDL_pixels.h"
|
||||||
|
"SDL_rwops.h"
|
||||||
|
"begin_code.h"
|
||||||
|
"close_code.h"
|
||||||
|
|
||||||
|
1473141855 d:\profile\ksy\eigene dateien\git\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_surface.h
|
||||||
|
"SDL_stdinc.h"
|
||||||
|
"SDL_pixels.h"
|
||||||
|
"SDL_rect.h"
|
||||||
|
"SDL_blendmode.h"
|
||||||
|
"SDL_rwops.h"
|
||||||
|
"begin_code.h"
|
||||||
|
"close_code.h"
|
||||||
|
|
||||||
|
1473141855 d:\profile\ksy\eigene dateien\git\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_blendmode.h
|
||||||
|
"begin_code.h"
|
||||||
|
"close_code.h"
|
||||||
|
|
||||||
|
1473141855 d:\profile\ksy\eigene dateien\git\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_keyboard.h
|
||||||
|
"SDL_stdinc.h"
|
||||||
|
"SDL_error.h"
|
||||||
|
"SDL_keycode.h"
|
||||||
|
"SDL_video.h"
|
||||||
|
"begin_code.h"
|
||||||
|
"close_code.h"
|
||||||
|
|
||||||
|
1473141855 d:\profile\ksy\eigene dateien\git\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_keycode.h
|
||||||
|
"SDL_stdinc.h"
|
||||||
|
"SDL_scancode.h"
|
||||||
|
|
||||||
|
1473141855 d:\profile\ksy\eigene dateien\git\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_scancode.h
|
||||||
|
"SDL_stdinc.h"
|
||||||
|
|
||||||
|
1473141855 d:\profile\ksy\eigene dateien\git\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_mouse.h
|
||||||
|
"SDL_stdinc.h"
|
||||||
|
"SDL_error.h"
|
||||||
|
"SDL_video.h"
|
||||||
|
"begin_code.h"
|
||||||
|
"close_code.h"
|
||||||
|
|
||||||
|
1473141855 d:\profile\ksy\eigene dateien\git\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_joystick.h
|
||||||
|
"SDL_stdinc.h"
|
||||||
|
"SDL_error.h"
|
||||||
|
"begin_code.h"
|
||||||
|
"close_code.h"
|
||||||
|
|
||||||
|
1473141855 d:\profile\ksy\eigene dateien\git\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_gamecontroller.h
|
||||||
|
"SDL_stdinc.h"
|
||||||
|
"SDL_error.h"
|
||||||
|
"SDL_rwops.h"
|
||||||
|
"SDL_joystick.h"
|
||||||
|
"begin_code.h"
|
||||||
|
"close_code.h"
|
||||||
|
|
||||||
|
1473141855 d:\profile\ksy\eigene dateien\git\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_quit.h
|
||||||
|
"SDL_stdinc.h"
|
||||||
|
"SDL_error.h"
|
||||||
|
|
||||||
|
1473141855 d:\profile\ksy\eigene dateien\git\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_gesture.h
|
||||||
|
"SDL_stdinc.h"
|
||||||
|
"SDL_error.h"
|
||||||
|
"SDL_video.h"
|
||||||
|
"SDL_touch.h"
|
||||||
|
"begin_code.h"
|
||||||
|
"close_code.h"
|
||||||
|
|
||||||
|
1473141855 d:\profile\ksy\eigene dateien\git\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_touch.h
|
||||||
|
"SDL_stdinc.h"
|
||||||
|
"SDL_error.h"
|
||||||
|
"SDL_video.h"
|
||||||
|
"begin_code.h"
|
||||||
|
"close_code.h"
|
||||||
|
|
||||||
|
1473141855 d:\profile\ksy\eigene dateien\git\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_filesystem.h
|
||||||
|
"SDL_stdinc.h"
|
||||||
|
"begin_code.h"
|
||||||
|
"close_code.h"
|
||||||
|
|
||||||
|
1473141855 d:\profile\ksy\eigene dateien\git\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_haptic.h
|
||||||
|
"SDL_stdinc.h"
|
||||||
|
"SDL_error.h"
|
||||||
|
"SDL_joystick.h"
|
||||||
|
"begin_code.h"
|
||||||
|
"close_code.h"
|
||||||
|
|
||||||
|
1473141855 d:\profile\ksy\eigene dateien\git\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_hints.h
|
||||||
|
"SDL_stdinc.h"
|
||||||
|
"begin_code.h"
|
||||||
|
"close_code.h"
|
||||||
|
|
||||||
|
1473141855 d:\profile\ksy\eigene dateien\git\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_loadso.h
|
||||||
|
"SDL_stdinc.h"
|
||||||
|
"SDL_error.h"
|
||||||
|
"begin_code.h"
|
||||||
|
"close_code.h"
|
||||||
|
|
||||||
|
1473141855 d:\profile\ksy\eigene dateien\git\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_log.h
|
||||||
|
"SDL_stdinc.h"
|
||||||
|
"begin_code.h"
|
||||||
|
"close_code.h"
|
||||||
|
|
||||||
|
1473141855 d:\profile\ksy\eigene dateien\git\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_messagebox.h
|
||||||
|
"SDL_stdinc.h"
|
||||||
|
"SDL_video.h"
|
||||||
|
"begin_code.h"
|
||||||
|
"close_code.h"
|
||||||
|
|
||||||
|
1473141855 d:\profile\ksy\eigene dateien\git\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_power.h
|
||||||
|
"SDL_stdinc.h"
|
||||||
|
"begin_code.h"
|
||||||
|
"close_code.h"
|
||||||
|
|
||||||
|
1473141855 d:\profile\ksy\eigene dateien\git\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_render.h
|
||||||
|
"SDL_stdinc.h"
|
||||||
|
"SDL_rect.h"
|
||||||
|
"SDL_video.h"
|
||||||
|
"begin_code.h"
|
||||||
|
"close_code.h"
|
||||||
|
|
||||||
|
1473141855 d:\profile\ksy\eigene dateien\git\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_system.h
|
||||||
|
"SDL_stdinc.h"
|
||||||
|
"SDL_keyboard.h"
|
||||||
|
"SDL_render.h"
|
||||||
|
"SDL_video.h"
|
||||||
|
"begin_code.h"
|
||||||
|
"close_code.h"
|
||||||
|
|
||||||
|
1473141855 d:\profile\ksy\eigene dateien\git\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_timer.h
|
||||||
|
"SDL_stdinc.h"
|
||||||
|
"SDL_error.h"
|
||||||
|
"begin_code.h"
|
||||||
|
"close_code.h"
|
||||||
|
|
||||||
|
1473141855 d:\profile\ksy\eigene dateien\git\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_version.h
|
||||||
|
"SDL_stdinc.h"
|
||||||
|
"begin_code.h"
|
||||||
|
"close_code.h"
|
||||||
|
|
||||||
|
1473141855 d:\profile\ksy\eigene dateien\git\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_image.h
|
||||||
|
"SDL.h"
|
||||||
|
"SDL_version.h"
|
||||||
|
"begin_code.h"
|
||||||
|
"close_code.h"
|
||||||
|
|
||||||
|
1473412852 d:\profile\ksy\eigene dateien\git\imanox-chroma-matting\opengl-test-two\include\loaders.h
|
||||||
|
<GL/glew.h>
|
||||||
|
|
||||||
|
1473412967 source:d:\profile\ksy\eigene dateien\git\imanox-chroma-matting\opengl-test-two\src\loaders.cpp
|
||||||
|
<SDL2/SDL.h>
|
||||||
|
<SDL2/SDL_image.h>
|
||||||
|
<fstream>
|
||||||
|
<vector>
|
||||||
|
"loaders.h"
|
||||||
|
|
||||||
|
|||||||
146
opengl-test-two/src/loaders.cpp
Normal file
146
opengl-test-two/src/loaders.cpp
Normal file
@@ -0,0 +1,146 @@
|
|||||||
|
#include <SDL2/SDL.h>
|
||||||
|
#include <SDL2/SDL_image.h>
|
||||||
|
#include <fstream>
|
||||||
|
#include <vector>
|
||||||
|
#include "loaders.h"
|
||||||
|
|
||||||
|
int InitLoaders(){
|
||||||
|
return SDL_Init(SDL_INIT_VIDEO);
|
||||||
|
}
|
||||||
|
|
||||||
|
GLuint LoadTexture(char *filename,int *textw,int *texth) {
|
||||||
|
SDL_Surface *surface;
|
||||||
|
GLuint textureid;
|
||||||
|
int mode;
|
||||||
|
surface = IMG_Load(filename);
|
||||||
|
// Or if you don't use SDL_image you can use SDL_LoadBMP here instead:
|
||||||
|
// surface = SDL_LoadBMP(filename);
|
||||||
|
|
||||||
|
// could not load filename
|
||||||
|
if (!surface) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// work out what format to tell glTexImage2D to use...
|
||||||
|
if (surface->format->BytesPerPixel == 3) { // RGB 24bit
|
||||||
|
mode = GL_RGB;
|
||||||
|
|
||||||
|
} else if (surface->format->BytesPerPixel == 4) { // RGBA 32bit
|
||||||
|
mode = GL_RGBA;
|
||||||
|
} else {
|
||||||
|
SDL_FreeSurface(surface);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
*textw=surface->w;
|
||||||
|
*texth=surface->h;
|
||||||
|
// create one texture name
|
||||||
|
glGenTextures(1, &textureid);
|
||||||
|
// tell opengl to use the generated texture name
|
||||||
|
glBindTexture(GL_TEXTURE_2D, textureid);
|
||||||
|
// this reads from the sdl surface and puts it into an opengl texture
|
||||||
|
glTexImage2D(GL_TEXTURE_2D, 0, mode, surface->w, surface->h, 0, mode, GL_UNSIGNED_BYTE, surface->pixels);
|
||||||
|
// these affect how this texture is drawn later on...glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
||||||
|
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);
|
||||||
|
// clean up
|
||||||
|
SDL_FreeSurface(surface);
|
||||||
|
return textureid;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
GLuint LoadShaders(const char * vertex_file_path,const char * fragment_file_path){
|
||||||
|
|
||||||
|
// Create the shaders
|
||||||
|
GLuint VertexShaderID = glCreateShader(GL_VERTEX_SHADER);
|
||||||
|
GLuint FragmentShaderID = glCreateShader(GL_FRAGMENT_SHADER);
|
||||||
|
|
||||||
|
// Read the Vertex Shader code from the file
|
||||||
|
std::string VertexShaderCode;
|
||||||
|
std::ifstream VertexShaderStream(vertex_file_path, std::ios::in);
|
||||||
|
if(VertexShaderStream.is_open()){
|
||||||
|
std::string Line = "";
|
||||||
|
while(getline(VertexShaderStream, Line))
|
||||||
|
VertexShaderCode += "\n" + Line;
|
||||||
|
VertexShaderStream.close();
|
||||||
|
}else{
|
||||||
|
printf("Impossible to open %s. Are you in the right directory ? Don't forget to read the FAQ !\n", vertex_file_path);
|
||||||
|
getchar();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read the Fragment Shader code from the file
|
||||||
|
std::string FragmentShaderCode;
|
||||||
|
std::ifstream FragmentShaderStream(fragment_file_path, std::ios::in);
|
||||||
|
if(FragmentShaderStream.is_open()){
|
||||||
|
std::string Line = "";
|
||||||
|
while(getline(FragmentShaderStream, Line))
|
||||||
|
FragmentShaderCode += "\n" + Line;
|
||||||
|
FragmentShaderStream.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
GLint Result = GL_FALSE;
|
||||||
|
int InfoLogLength;
|
||||||
|
|
||||||
|
|
||||||
|
// Compile Vertex Shader
|
||||||
|
printf("Compiling shader : %s\n", vertex_file_path);
|
||||||
|
char const * VertexSourcePointer = VertexShaderCode.c_str();
|
||||||
|
glShaderSource(VertexShaderID, 1, &VertexSourcePointer , NULL);
|
||||||
|
glCompileShader(VertexShaderID);
|
||||||
|
|
||||||
|
// Check Vertex Shader
|
||||||
|
glGetShaderiv(VertexShaderID, GL_COMPILE_STATUS, &Result);
|
||||||
|
glGetShaderiv(VertexShaderID, GL_INFO_LOG_LENGTH, &InfoLogLength);
|
||||||
|
if ( InfoLogLength > 0 ){
|
||||||
|
std::vector<char> VertexShaderErrorMessage(InfoLogLength+1);
|
||||||
|
glGetShaderInfoLog(VertexShaderID, InfoLogLength, NULL, &VertexShaderErrorMessage[0]);
|
||||||
|
printf("%s\n", &VertexShaderErrorMessage[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Compile Fragment Shader
|
||||||
|
printf("Compiling shader : %s\n", fragment_file_path);
|
||||||
|
char const * FragmentSourcePointer = FragmentShaderCode.c_str();
|
||||||
|
glShaderSource(FragmentShaderID, 1, &FragmentSourcePointer , NULL);
|
||||||
|
glCompileShader(FragmentShaderID);
|
||||||
|
|
||||||
|
// Check Fragment Shader
|
||||||
|
glGetShaderiv(FragmentShaderID, GL_COMPILE_STATUS, &Result);
|
||||||
|
glGetShaderiv(FragmentShaderID, GL_INFO_LOG_LENGTH, &InfoLogLength);
|
||||||
|
if ( InfoLogLength > 0 ){
|
||||||
|
std::vector<char> FragmentShaderErrorMessage(InfoLogLength+1);
|
||||||
|
glGetShaderInfoLog(FragmentShaderID, InfoLogLength, NULL, &FragmentShaderErrorMessage[0]);
|
||||||
|
printf("%s\n", &FragmentShaderErrorMessage[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Link the program
|
||||||
|
printf("Linking program\n");
|
||||||
|
GLuint ProgramID = glCreateProgram();
|
||||||
|
glAttachShader(ProgramID, VertexShaderID);
|
||||||
|
glAttachShader(ProgramID, FragmentShaderID);
|
||||||
|
glLinkProgram(ProgramID);
|
||||||
|
|
||||||
|
// Check the program
|
||||||
|
glGetProgramiv(ProgramID, GL_LINK_STATUS, &Result);
|
||||||
|
glGetProgramiv(ProgramID, GL_INFO_LOG_LENGTH, &InfoLogLength);
|
||||||
|
if ( InfoLogLength > 0 ){
|
||||||
|
std::vector<char> ProgramErrorMessage(InfoLogLength+1);
|
||||||
|
glGetProgramInfoLog(ProgramID, InfoLogLength, NULL, &ProgramErrorMessage[0]);
|
||||||
|
printf("%s\n", &ProgramErrorMessage[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
glDetachShader(ProgramID, VertexShaderID);
|
||||||
|
glDetachShader(ProgramID, FragmentShaderID);
|
||||||
|
|
||||||
|
glDeleteShader(VertexShaderID);
|
||||||
|
glDeleteShader(FragmentShaderID);
|
||||||
|
|
||||||
|
return ProgramID;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user