Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "menu.h"
- struct button *btn_new_game;
- void init_menu ( )
- {
- btn_new_game = calloc ( 1, sizeof ( struct button ) );
- button_init ( btn_new_game );
- button_set_percent ( btn_new_game, 10, 10 );
- button_set_text ( btn_new_game, L"Новая игра" );
- button_set_pos ( btn_new_game, 10, 400 );
- button_set_color ( btn_new_game, 0x2c2c2cff, 0x00002cff, 0xffe301 );
- }
- void render_menu ( )
- {
- button_render ( btn_new_game );
- }
- button_set_color выглядит так.
- void button_set_color ( struct button *btn, unsigned int color, unsigned int bcolor, unsigned int tcolor )
- {
- btn->tcolor = tcolor;
- box_set_color ( btn->box, color, bcolor );
- font_free_texture ( btn->font );
- font_set_text ( btn->font, btn->text, btn->font_size, 1, 1, 4, btn->tcolor );
- }
- void box_set_color ( struct box *box, unsigned int color, unsigned int bcolor )
- {
- box->color = color;
- box->bcolor = bcolor;
- for ( int y = 0, i = 0; y < box->height; y++ ) {
- for ( int x = 0; x < box->width; x++, i += 4 ) {
- if ( x == 0 || x == box->width - 1 || y == 0 || y == box->height - 1 ) {
- box->color_box[i + 0] = ( box->bcolor >> 24 & 0xff ) / 255.0f;
- box->color_box[i + 1] = ( box->bcolor >> 16 & 0xff ) / 255.0f;
- box->color_box[i + 2] = ( box->bcolor >> 8 & 0xff ) / 255.0f;
- box->color_box[i + 3] = ( box->bcolor >> 0 & 0xff ) / 255.0f;
- continue;
- }
- box->color_box[i + 0] = ( box->color >> 24 & 0xff ) / 255.0f;
- box->color_box[i + 1] = ( box->color >> 16 & 0xff ) / 255.0f;
- box->color_box[i + 2] = ( box->color >> 8 & 0xff ) / 255.0f;
- box->color_box[i + 3] = ( box->color >> 0 & 0xff ) / 255.0f;
- }
- }
- }
- void box_init ( struct box *box )
- {
- glm_clear_matrix4x4 ( &box->ortho[0] );
- glm_clear_matrix4x4 ( &box->translate[0] );
- box->program = global.programs[POINTS];
- int width = global.width;
- int height = global.height;
- glm_ortho ( &box->ortho[0], 0.0f, width, 0.0f, height, 0.0f, 1.0f );
- box->vertex_box = NULL;
- box->color_box = NULL;
- box->color = 0x000000ff;
- box->bcolor = 0xffffffff;
- box->x = 0;
- box->y = 0;
- glUseProgram ( box->program );
- box->translate_location = glGetUniformLocation ( box->program, "transform" );
- box->ortho_location = glGetUniformLocation ( box->program, "ortho" );
- }
- void box_render ( struct box *box )
- {
- glUseProgram ( box->program );
- glUniformMatrix4fv ( box->translate_location, 1, GL_FALSE, &box->translate[0][0] );
- glUniformMatrix4fv ( box->ortho_location, 1, GL_FALSE, &box->ortho[0][0] );
- glEnableVertexAttribArray ( 0 );
- glEnableVertexAttribArray ( 1 );
- glVertexAttribPointer ( 0, 2, GL_FLOAT, GL_FALSE, 0, box->vertex_box );
- glVertexAttribPointer ( 1, 4, GL_FLOAT, GL_FALSE, 0, box->color_box );
- glDrawArrays ( GL_POINTS, 0, box->max_render );
- glDisableVertexAttribArray ( 0 );
- glDisableVertexAttribArray ( 1 );
- }
- {
- const char *vshader =
- "#version 300 esn"
- "layout(location = 0) in vec2 position;n"
- "layout(location = 1) in vec4 color;n"
- "uniform mat4 transform;n"
- "uniform mat4 ortho;n"
- "out vec4 v_color;n"
- "void main ( )n"
- "{n"
- " gl_Position = ortho * transform * vec4 ( position, 0.0, 1.0 );n"
- " v_color = color;n"
- "}";
- const char *fshader =
- "#version 300 esn"
- "precision mediump float;n"
- "in vec4 v_color;n"
- "out vec4 frag_color;n"
- "void main ( )n"
- "{n"
- " frag_color = v_color;n"
- "}";
- GLuint program = loadProgram ( vshader, fshader );
- global.programs[POINTS] = program;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement