Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include GLEW_INCLUDE
- #include <SDL.h>
- int w=800, h=600;
- float vertexData[] = {
- 0, 1, 0, 0, 0, 1, 0, 1, 0, 0,
- 1, 0, 0, 0, 0, 1, 1, 0, 0, 0,
- 0, 0, 0, 0, 0, 1, 0, 0, 0, 0,
- };
- int indexData[] = {
- 0, 1, 2
- };
- const char* vertSrc =
- "#version 400\n"
- "in vec3 os_Position;\n"
- "void main() {\n"
- " gl_Position = vec4(os_Position, 1.0);\n"
- "}\n";
- const char* fragSrc =
- "#version 400\n"
- "out vec4 Output0;\n"
- "void main() {\n"
- " Output0 = vec4(1.0);\n"
- "}\n";
- int main() {
- SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 4);
- SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
- SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
- SDL_Window* win = SDL_CreateWindow("SSCCE", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, w, h, SDL_WINDOW_OPENGL);
- SDL_GLContext ctx = SDL_GL_CreateContext(win);
- glewInit();
- unsigned prog = glCreateProgram();
- unsigned vert = glCreateShader(GL_VERTEX_SHADER);
- int vertSrcLen = strlen(vertSrc);
- glShaderSource(vert, 1, (const GLchar**)&vertSrc, &vertSrcLen);
- glCompileShader(vert);
- glAttachShader(prog, vert);
- unsigned frag = glCreateShader(GL_FRAGMENT_SHADER);
- int fragSrcLen = strlen(fragSrc);
- glShaderSource(frag, 1, (const GLchar**)&fragSrc, &fragSrcLen);
- glCompileShader(frag);
- glAttachShader(prog, frag);
- glBindFragDataLocation(prog, 0, "Output0");
- glLinkProgram(prog);
- glUseProgram(prog);
- glViewport(0, 0, w, h);
- glClearColor(0, 0, 0, 0);
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- unsigned vao = 0;
- glGenVertexArrays(1, &vao);
- glBindVertexArray(vao);
- unsigned vbo = 0;
- glGenBuffers(1, &vbo);
- glBindBuffer(GL_ARRAY_BUFFER, vbo);
- glBufferData(GL_ARRAY_BUFFER, sizeof(vertexData), vertexData, GL_STATIC_DRAW);
- int stride = sizeof(float) * (3 + 3 + 4);
- int attrib = glGetAttribLocation(prog, "os_Position");
- printf("attrib = %d\n", attrib);
- glEnableVertexAttribArray(attrib);
- glVertexAttribPointer(attrib, 3, GL_FLOAT, true, stride, (void*)0);
- unsigned ibo = 0;
- glGenBuffers(1, &ibo);
- glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo);
- glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indexData), indexData, GL_STATIC_DRAW);
- glDrawElements(GL_TRIANGLES, sizeof(indexData) / sizeof(indexData[0]), GL_UNSIGNED_INT, 0);
- SDL_GL_SwapWindow(win);
- SDL_Delay(1000);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement