Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SDL2/SDL_events.h>
- #include <SDL2/SDL_render.h>
- #include <SDL2/SDL_video.h>
- #include <cstdio>
- #include <SDL2/SDL.h>
- #include <GL/glew.h>
- #include <SDL2/SDL_opengl.h>
- #include <GL/glut.h>
- const GLchar* vertexShaderSource[] ={
- "#version 460 core\nin vec3 pos; void main() {gl_Position = vec4(pos, 1.0); }"
- };
- const GLchar* fragShaderSource[] = {
- "#version 460 core\n out vec4 FragColor; void main() { FragColor = vec4(1.0);}"
- };
- int main(){
- bool running = true;
- SDL_GL_SetAttribute( SDL_GL_CONTEXT_MAJOR_VERSION, 3 );
- SDL_GL_SetAttribute( SDL_GL_CONTEXT_MINOR_VERSION, 1 );
- SDL_GL_SetAttribute( SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE );
- SDL_Window* window;
- SDL_Renderer* renderer;
- SDL_CreateWindowAndRenderer(600, 400, SDL_WINDOW_RESIZABLE, &window, &renderer);
- SDL_GLContext gl_context = SDL_GL_CreateContext(window);
- if (gl_context == NULL){
- printf("Failed to create OpenGL context\n");
- return -1;
- }
- glewExperimental = true;
- GLenum glewError = glewInit();
- if (glewError != GLEW_OK){
- printf("Failed to init glew\n");
- return -1;
- }
- GLuint vsShader = glCreateShader(GL_VERTEX_SHADER);
- glShaderSource(vsShader, 1, vertexShaderSource, NULL);
- glCompileShader(vsShader);
- GLuint fsShader = glCreateShader(GL_FRAGMENT_SHADER);
- glShaderSource(fsShader, 1, fragShaderSource, NULL);
- glCompileShader(fsShader);
- GLuint program = glCreateProgram();
- glAttachShader(program, vsShader);
- glAttachShader(program, fsShader);
- glLinkProgram(program);
- float vertices[] ={
- 0.0f, 0.5f, 0.0f,
- -0.5f, -0.5f, 0.0f,
- 0.5f, -0.5f, 0.0f,
- };
- GLuint VAO, VBO;
- glGenVertexArrays(1, &VAO);
- glGenBuffers(1, &VBO);
- glBindVertexArray(VAO);
- glBindBuffer(GL_ARRAY_BUFFER, VBO);
- glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
- glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*)0);
- glEnableVertexAttribArray(0);
- glClear(GL_COLOR_BUFFER_BIT);
- SDL_Event event;
- while(running){
- while(SDL_PollEvent(&event)){
- if (event.type == SDL_QUIT){
- running = false;
- }
- }
- //glClear(GL_COLOR_BUFFER_BIT);
- /*glDrawArrays(GL_TRIANGLES, 0, 9);*/
- SDL_GL_SwapWindow(window);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment