46 asc_dprintf("GL debug: %.*s", (int)buf.length, buf.ptr); |
46 asc_dprintf("GL debug: %.*s", (int)buf.length, buf.ptr); |
47 } |
47 } |
48 cx_strfree(&buf); |
48 cx_strfree(&buf); |
49 } |
49 } |
50 |
50 |
51 static void asc_shader_initialize_predefined(AscGLContext *ctx) { |
51 static int asc_shader_initialize_predefined(AscGLContext *ctx) { |
52 // TODO: deal with different working dirs |
52 int ret = 0; |
53 AscShaderSprite *sprite = &ctx->shader.sprite; |
53 ret |= asc_shader_sprite_init(&ctx->shader.sprite); |
54 AscShaderCodes codes; |
54 return ret; |
55 if (asc_shader_load_code_files((AscShaderCodeFiles){ |
|
56 .vtx = "./shader/sprite_vtx.glsl", |
|
57 .frag = "./shader/sprite_frag.glsl" |
|
58 }, &codes)) { |
|
59 asc_error("Loading sprite shader failed."); |
|
60 return; |
|
61 } |
|
62 sprite->program = asc_shader_program_create(codes); |
|
63 sprite->depth = glGetUniformLocation(sprite->program.id, "depth"); |
|
64 sprite->tex = glGetUniformLocation(sprite->program.id, "texture"); |
|
65 asc_shader_free_codes(codes); |
|
66 } |
55 } |
67 |
56 |
68 static void asc_shader_destroy_predefined(AscGLContext *ctx) { |
57 static void asc_shader_destroy_predefined(AscGLContext *ctx) { |
69 asc_shader_program_destroy(ctx->shader.sprite.program); |
58 asc_shader_program_destroy(&ctx->shader.sprite.program); |
70 } |
59 } |
71 |
60 |
72 bool asc_gl_context_initialize( |
61 bool asc_gl_context_initialize( |
73 AscGLContext *ctx, |
62 AscGLContext *ctx, |
74 SDL_Window *window, |
63 SDL_Window *window, |
96 asc_error("Creating primitive meshes failed"); |
85 asc_error("Creating primitive meshes failed"); |
97 SDL_GL_DeleteContext(ctx->glctx); |
86 SDL_GL_DeleteContext(ctx->glctx); |
98 return false; |
87 return false; |
99 } |
88 } |
100 |
89 |
101 asc_shader_initialize_predefined(ctx); |
90 if (asc_shader_initialize_predefined(ctx)) { |
|
91 SDL_GL_DeleteContext(ctx->glctx); |
|
92 return false; |
|
93 } |
102 |
94 |
103 return true; |
95 return true; |
104 } else { |
96 } else { |
105 asc_error(glewGetErrorString(err)); |
97 asc_error(glewGetErrorString(err)); |
106 SDL_GL_DeleteContext(ctx->glctx); |
98 SDL_GL_DeleteContext(ctx->glctx); |