Advertisement
Guest User

Untitled

a guest
Oct 13th, 2016
75
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <SDL.h>
  2. #include <glad/glad.h>
  3. #include <cstdio>
  4. #include <memory>
  5.  
  6. const char* shaderSource = R"(
  7. #version 330 core
  8.  
  9. #pragma x x x/x/x/x.x
  10.  
  11. out vec4 fragColor;
  12. void main() {
  13.    fragColor = vec4(1.0);
  14. }
  15. )";
  16.  
  17. int main(int argc, char** args) {
  18.     // Window
  19.     if(SDL_Init(SDL_INIT_VIDEO) < 0) {
  20.         printf("SDL_Init failed! - '%s'\n", SDL_GetError()); return 1;
  21.     }
  22.     SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
  23.     SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3);
  24.     SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
  25.  
  26.     int width = 1600, height = 900;
  27.     Uint32 flags = SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN;
  28.     SDL_Window* mSDLWindow = SDL_CreateWindow("test", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width, height, flags);
  29.     if(mSDLWindow == nullptr) {
  30.         printf("SDL_CreateWindow failed! - '%s'\n", SDL_GetError()); return 1;
  31.     }
  32.  
  33.     SDL_GLContext mSDLGLContext = SDL_GL_CreateContext(mSDLWindow);
  34.     if(mSDLGLContext == 0) {
  35.         printf("SDL_GL_CreateContext failed! - '%s'\n", SDL_GetError()); return 1;
  36.     }
  37.  
  38.     if(!gladLoadGLLoader((GLADloadproc)SDL_GL_GetProcAddress)) {
  39.         printf("Failed to initialize GLAD! - '%s'\n", SDL_GetError()); return 1;
  40.     }
  41.  
  42.     GLuint shader = glCreateShader(GL_FRAGMENT_SHADER);
  43.     glShaderSource(shader, 1, &shaderSource, nullptr);
  44.  
  45.     GLint compileStatus;
  46.     glCompileShader(shader);
  47.     glGetShaderiv(shader, GL_COMPILE_STATUS, &compileStatus);
  48.     if(compileStatus == GL_FALSE){
  49.         GLint logLength;
  50.         glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &logLength);
  51.         std::unique_ptr<GLchar> shaderLog(new GLchar[logLength]);
  52.         glGetShaderInfoLog(shader, logLength, nullptr, shaderLog.get());
  53.         printf("shader compile failed: %s", shaderLog.get()); return 1;
  54.     }
  55.     printf("No one shall see me.\n");
  56.  
  57.     SDL_DestroyWindow(mSDLWindow);
  58.  
  59.     return 0;
  60. }
Advertisement
RAW Paste Data Copied
Advertisement