gles running
This commit is contained in:
parent
9cbcd7acca
commit
75dc9659dd
2 changed files with 146 additions and 103 deletions
107
main.c
107
main.c
|
|
@ -99,11 +99,18 @@ GLuint compile_shader(GLuint type, const char *src) {
|
|||
}
|
||||
|
||||
const char *vertex_shader_src =
|
||||
"attribute vec4 vPosition; \n"
|
||||
"void main() \n"
|
||||
"{ \n"
|
||||
" gl_Position = vPosition; \n"
|
||||
"} \n";
|
||||
//"attribute vec4 vPosition; \n"
|
||||
//"void main() \n"
|
||||
//"{ \n"
|
||||
//" gl_Position = vPosition; \n"
|
||||
//"} \n";
|
||||
"#version 320 es\n"
|
||||
"\n"
|
||||
"layout(location = 0) in vec2 aPos;\n"
|
||||
"\n"
|
||||
"void main() {\n"
|
||||
" gl_Position = vec4(aPos, 0.0, 1.0);\n"
|
||||
"}\n";
|
||||
|
||||
/// returns 0 if failed.
|
||||
GLuint create_shader(const char *fragment_src) {
|
||||
|
|
@ -137,20 +144,20 @@ GLuint load_shader(const char *path) {
|
|||
|
||||
GLuint shader = create_shader(string);
|
||||
|
||||
if (shader == 0) {
|
||||
// print file
|
||||
int line_count = 1;
|
||||
printf("%i\t", line_count);
|
||||
line_count++;
|
||||
for (int i = 0; i < length; i++) {
|
||||
printf("%c", string[i]);
|
||||
if (string[i] == '\n') {
|
||||
printf("%i\t", line_count);
|
||||
line_count++;
|
||||
}
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
//if (shader == 0) {
|
||||
// // print file
|
||||
// int line_count = 1;
|
||||
// printf("%i\t", line_count);
|
||||
// line_count++;
|
||||
// for (int i = 0; i < length; i++) {
|
||||
// printf("%c", string[i]);
|
||||
// if (string[i] == '\n') {
|
||||
// printf("%i\t", line_count);
|
||||
// line_count++;
|
||||
// }
|
||||
// }
|
||||
// printf("\n");
|
||||
//}
|
||||
|
||||
free(string);
|
||||
return shader;
|
||||
|
|
@ -208,6 +215,41 @@ SDL_Log("GL_RENDERER: %s", renderer);
|
|||
|
||||
GLuint shader = load_shader("fragment.glsl"); //create_shader(fragment_shader_source);
|
||||
|
||||
|
||||
// buffers
|
||||
// Load the vertex data
|
||||
GLfloat vertices[] = {
|
||||
-1.0, 1.0,
|
||||
-1.0, -1.0,
|
||||
1.0, -1.0,
|
||||
|
||||
1.0, -1.0,
|
||||
1.0, 1.0,
|
||||
-1.0, 1.0,
|
||||
};
|
||||
GLuint vao, vbo;
|
||||
glGenVertexArrays(1, &vao);
|
||||
glBindVertexArray(vao);
|
||||
glGenBuffers(1, &vbo);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, vbo);
|
||||
glBufferData(GL_ARRAY_BUFFER,
|
||||
sizeof(vertices),
|
||||
vertices,
|
||||
GL_STATIC_DRAW);
|
||||
|
||||
glEnableVertexAttribArray(0);
|
||||
glVertexAttribPointer(
|
||||
0, // location
|
||||
2, // vec2
|
||||
GL_FLOAT,
|
||||
GL_FALSE,
|
||||
0,
|
||||
(void *)0
|
||||
);
|
||||
|
||||
|
||||
|
||||
|
||||
int w, h;
|
||||
double time;
|
||||
while (running) {
|
||||
|
|
@ -227,23 +269,20 @@ SDL_Log("GL_RENDERER: %s", renderer);
|
|||
|
||||
// Shader parameters.
|
||||
glUseProgram(shader);
|
||||
|
||||
//int uniform_WindowSize = glGetUniformLocation(shader, "WindowSize");
|
||||
//glUniform2f(uniform_WindowSize, w, h);
|
||||
|
||||
//time = time_since_start();
|
||||
//int uniform_time = glGetUniformLocation(shader, "time");
|
||||
//glUniform1f(uniform_time, (float)time);
|
||||
int uniform_WindowSize = glGetUniformLocation(shader, "WindowSize");
|
||||
glUniform2f(uniform_WindowSize, w, h);
|
||||
|
||||
// Load the vertex data
|
||||
GLfloat vVertices[] = {
|
||||
0.0f, 0.5f, 0.0f,
|
||||
-0.5f, -0.5f, 0.0f,
|
||||
0.5f, -0.5f, 0.0f
|
||||
};
|
||||
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, vVertices);
|
||||
glEnableVertexAttribArray(0);
|
||||
glDrawArrays(GL_TRIANGLES, 0, 3);
|
||||
time = time_since_start();
|
||||
int uniform_time = glGetUniformLocation(shader, "time");
|
||||
glUniform1f(uniform_time, (float)time);
|
||||
|
||||
//glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, vVertices);
|
||||
//glEnableVertexAttribArray(0);
|
||||
//glDrawArrays(GL_TRIANGLES, 0, 6);
|
||||
|
||||
glBindVertexArray(vao);
|
||||
glDrawArrays(GL_TRIANGLES, 0, 6);
|
||||
|
||||
SDL_GL_SwapWindow(window);
|
||||
checkGlError();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue