Skip to content

Instantly share code, notes, and snippets.

@stelonix
Last active February 25, 2016 21:34
Show Gist options
  • Save stelonix/d02c4c1dc8b03684fb40 to your computer and use it in GitHub Desktop.
Save stelonix/d02c4c1dc8b03684fb40 to your computer and use it in GitHub Desktop.
#version 450 core //lower your version if GLSL 4.5 is not supported by your GPU
layout (location = 0) in vec3 VertexPosition;
uniform mat4x4 a;
void main()
{
gl_Position = a * vec4(VertexPosition, 1.0);
}
varying vec4 v_color;
void main() {
gl_FragColor = v_color;
}
int main() {
glViewport(0,0,800,600);
glEnable(GL_DEPTH_TEST);
auto projection = glm::ortho( 0.f, 800.f, 0.f, 600.f, 1.f, -1.f );
glm::mat4 view = glm::lookAt(
glm::vec3(0.f,0.f,0.f),
glm::vec3(0.f,0.f,0.f),
glm::vec3(0.f,0.f,0.f)
);
glm::mat4 model = glm::mat4(1.0f);
glm::mat4 MVP = projection*view * model;
auto program = glCreateProgram();
auto asdf = shaders["basic.glsl"].c_str();
auto fdsa = shaders["fragment.glsl"].c_str();
GLuint vs = glCreateShader (GL_VERTEX_SHADER);
glShaderSource(vs, 1, &asdf, NULL);
glCompileShader(vs);
int result;
glGetShaderiv(vs, GL_COMPILE_STATUS, &result);
if (result != GL_TRUE) {
printf("shader fail\n");
exit(1);
}
glAttachShader(program, vs);
glLinkProgram(program);
unsigned int vao;
unsigned int vbo;
glGenVertexArrays(1, &vao);
glBindVertexArray(vao);
float vertices[][3] ={
{0.0f, 0.0f, 0.0f}, {100.0f, 0.0f, 0.0f}, {0.0f, 100.0f, 0.0f}
};
glGenBuffers(1, &vbo);
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glBufferData(GL_ARRAY_BUFFER, sizeof(float) * 3 * sizeof(vertices), &vertices[0], GL_STATIC_DRAW);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(float) * 3, (void*)0);
while (1) {
poll();
if (done) {
glXMakeCurrent(display, None, NULL);
glXDestroyContext(display, ctx);
XDestroyWindow(display, win);
XFreeColormap(display, cmap);
XCloseDisplay(display);
return 0;
}
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClearColor(1.0, 0.3, 0.3, 1.0);
glUseProgram(program);
auto projection_Location = glGetUniformLocation(program, "a");
printf("\nLocation: %d\n", projection_Location);
glUniformMatrix4fv(projection_Location, 1, GL_FALSE, glm::value_ptr(MVP));
glBindVertexArray(vao);
glDrawArrays(GL_TRIANGLES, 0, 3);
glXSwapBuffers(display, win);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment