diff options
Diffstat (limited to 'graph.c')
-rw-r--r-- | graph.c | 37 |
1 files changed, 10 insertions, 27 deletions
@@ -6,23 +6,6 @@ #include"graph.h" #include"tex.h" -#define GLSL(...)"#version 330 core\n"#__VA_ARGS__ -_ IM C shader_tex_vert[]=GLSL( - layout (location=0) in vec3 pos; - layout (location=1) in vec3 col; - layout (location=2) in vec2 tex; - out vec3 Col; - out vec2 Tex; - void main(){gl_Position=vec4(pos,1.0);Col=col;Tex=tex;}); - -_ IM C shader_tex_frag[]=GLSL( - out vec4 Frag; - in vec3 Col; - in vec2 Tex; - uniform sampler2D tex_buf; - void main(){Frag=texture(tex_buf,Tex);}); - -U32 graph_shader_tex; U32 graph_win_w=1280,graph_win_h=720; _ SDL_Window*win; @@ -40,8 +23,7 @@ V graph_init(V){SDL_version sdl_vh,sdl_vl; N(ctx=SDL_GL_CreateContext(win),on_err("create OpenGL context")) N(gladLoadGLLoader(SDL_GL_GetProcAddress),on_err("load GL")) SDL_GL_SetSwapInterval(1); - q_init(), - graph_shader_tex=graph_shader_create(shader_tex_vert,shader_tex_frag); + q_init(); SDL_VERSION(&sdl_vh)SDL_GetVersion(&sdl_vl); fprintf(stderr, "Graphics initialization successful!\n" @@ -86,13 +68,7 @@ _ V q_init(V){ glVertexAttribPointer(2,2,GL_FLOAT,GL_FALSE,8*SZ(F32),(V*)(6*SZ(F32))), glEnableVertexAttribArray(2), glBindVertexArray(0);} -V graph_quad(U32 tex){//F32 t,g;I l; - /*t=SDL_GetTicks(), - g=sinf(sinf(t/255)/2)+0.5, - l=glGetUniformLocation(solid_shader,"col"), - glUniform3f(l,0,0,g),*/ - glBindTexture(GL_TEXTURE_2D,tex), - glUseProgram(graph_shader_tex), +V graph_quad(){ glBindVertexArray(q_vao), glDrawElements(GL_TRIANGLES,6,GL_UNSIGNED_INT,0), glBindVertexArray(0);} @@ -107,13 +83,20 @@ U32 graph_shader_create(IM C*vert,IM C*frag){I ok;C info[512];U32 v,f,p; glDeleteShader(v),glDeleteShader(f); R p;} +V graph_shader_use(U32 s){glUseProgram(s);} +V graph_shader_seti(IM C*s,I i){I p;glGetIntegerv(GL_CURRENT_PROGRAM,&p), + glUniform1i(glGetUniformLocation(p,s),i);} + U32 graph_tex_create(IM C*f){Tex tex;U32 t; glGenTextures(1,&t); glBindTexture(GL_TEXTURE_2D,t), glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST_MIPMAP_NEAREST), glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); tex=tex_load(f); - glTexImage2D(GL_TEXTURE_2D,0,GL_RGB,tex.w,tex.h,0,GL_RGB,GL_UNSIGNED_BYTE,tex.d), + glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,tex.w,tex.h,0,GL_RGBA,GL_UNSIGNED_BYTE,tex.d), glGenerateMipmap(GL_TEXTURE_2D), tex_free(tex); R t;} +V graph_tex_use(U32 tex,U8 i){ + glActiveTexture(GL_TEXTURE0+i); + glBindTexture(GL_TEXTURE_2D,tex);} |