Has anyone a really stripped down but complete 2d triangle using ortho projection and shaders?
using GLES2/gl2.h, EGL/egl.h and EGL/eglext.h
This process is already fairly complex and it will be helpful to have simple examples,
Code: Select all
#include <GLES2/gl2.h>
GLfloat data[] = { -.5f, -.5f, -.5f, .5f, .5f, .5f };
void init() {
const GLchar *vertex_shader_code = "attribute vec4 pos; void main(void) { gl_Position = pos; }";
const GLchar *fragment_shader_code = "void main(void) { gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0); }";
GLuint vs, fs, program;
GLint pos;
vs = glCreateShader(GL_VERTEX_SHADER);
glShaderSource(vs, 1, &vertex_shader_code, 0);
glCompileShader(vs);
fs = glCreateShader(GL_FRAGMENT_SHADER);
glShaderSource(fs, 1, &fragment_shader_code, 0);
glCompileShader(fs);
program = glCreateProgram();
glAttachShader(program, vs);
glAttachShader(program, fs);
glLinkProgram(program);
pos = glGetAttribLocation(program, "pos");
glUseProgram(program);
glEnableVertexAttribArray(pos);
glVertexAttribPointer(pos, 2, GL_FLOAT, GL_FALSE, 0, data);
}
void display() {
glClear(GL_COLOR_BUFFER_BIT);
glDrawArrays(GL_TRIANGLES, 0, 3);
}Code: Select all
#define SHADER(x) #x
const GLchar *vertex_shader = SHADER(
attribute vec4 pos;
void main(void)
{
gl_Position = pos;
}
);Code: Select all
int w,h,n;
unsigned char *data = stbi_load(filename, &w, &h, &n, 4);
stbi_image_free(data);