Advertisement
Guest User

Untitled

a guest
Jun 27th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.22 KB | None | 0 0
  1. #include "menu.h"
  2.  
  3. struct button *btn_new_game;
  4.  
  5. void init_menu ( )
  6. {
  7. btn_new_game = calloc ( 1, sizeof ( struct button ) );
  8. button_init ( btn_new_game );
  9. button_set_percent ( btn_new_game, 10, 10 );
  10. button_set_text ( btn_new_game, L"Новая игра" );
  11. button_set_pos ( btn_new_game, 10, 400 );
  12. button_set_color ( btn_new_game, 0x2c2c2cff, 0x00002cff, 0xffe301 );
  13. }
  14.  
  15. void render_menu ( )
  16. {
  17. button_render ( btn_new_game );
  18. }
  19. button_set_color выглядит так.
  20. void button_set_color ( struct button *btn, unsigned int color, unsigned int bcolor, unsigned int tcolor )
  21. {
  22. btn->tcolor = tcolor;
  23. box_set_color ( btn->box, color, bcolor );
  24. font_free_texture ( btn->font );
  25. font_set_text ( btn->font, btn->text, btn->font_size, 1, 1, 4, btn->tcolor );
  26. }
  27.  
  28. void box_set_color ( struct box *box, unsigned int color, unsigned int bcolor )
  29. {
  30. box->color = color;
  31. box->bcolor = bcolor;
  32. for ( int y = 0, i = 0; y < box->height; y++ ) {
  33. for ( int x = 0; x < box->width; x++, i += 4 ) {
  34. if ( x == 0 || x == box->width - 1 || y == 0 || y == box->height - 1 ) {
  35. box->color_box[i + 0] = ( box->bcolor >> 24 & 0xff ) / 255.0f;
  36. box->color_box[i + 1] = ( box->bcolor >> 16 & 0xff ) / 255.0f;
  37. box->color_box[i + 2] = ( box->bcolor >> 8 & 0xff ) / 255.0f;
  38. box->color_box[i + 3] = ( box->bcolor >> 0 & 0xff ) / 255.0f;
  39. continue;
  40. }
  41. box->color_box[i + 0] = ( box->color >> 24 & 0xff ) / 255.0f;
  42. box->color_box[i + 1] = ( box->color >> 16 & 0xff ) / 255.0f;
  43. box->color_box[i + 2] = ( box->color >> 8 & 0xff ) / 255.0f;
  44. box->color_box[i + 3] = ( box->color >> 0 & 0xff ) / 255.0f;
  45. }
  46. }
  47. }
  48.  
  49. void box_init ( struct box *box )
  50. {
  51. glm_clear_matrix4x4 ( &box->ortho[0] );
  52. glm_clear_matrix4x4 ( &box->translate[0] );
  53.  
  54. box->program = global.programs[POINTS];
  55. int width = global.width;
  56. int height = global.height;
  57. glm_ortho ( &box->ortho[0], 0.0f, width, 0.0f, height, 0.0f, 1.0f );
  58.  
  59. box->vertex_box = NULL;
  60. box->color_box = NULL;
  61. box->color = 0x000000ff;
  62. box->bcolor = 0xffffffff;
  63. box->x = 0;
  64. box->y = 0;
  65.  
  66. glUseProgram ( box->program );
  67. box->translate_location = glGetUniformLocation ( box->program, "transform" );
  68. box->ortho_location = glGetUniformLocation ( box->program, "ortho" );
  69. }
  70.  
  71. void box_render ( struct box *box )
  72. {
  73. glUseProgram ( box->program );
  74. glUniformMatrix4fv ( box->translate_location, 1, GL_FALSE, &box->translate[0][0] );
  75. glUniformMatrix4fv ( box->ortho_location, 1, GL_FALSE, &box->ortho[0][0] );
  76.  
  77. glEnableVertexAttribArray ( 0 );
  78. glEnableVertexAttribArray ( 1 );
  79.  
  80. glVertexAttribPointer ( 0, 2, GL_FLOAT, GL_FALSE, 0, box->vertex_box );
  81. glVertexAttribPointer ( 1, 4, GL_FLOAT, GL_FALSE, 0, box->color_box );
  82.  
  83. glDrawArrays ( GL_POINTS, 0, box->max_render );
  84.  
  85. glDisableVertexAttribArray ( 0 );
  86. glDisableVertexAttribArray ( 1 );
  87. }
  88.  
  89. {
  90. const char *vshader =
  91. "#version 300 esn"
  92. "layout(location = 0) in vec2 position;n"
  93. "layout(location = 1) in vec4 color;n"
  94. "uniform mat4 transform;n"
  95. "uniform mat4 ortho;n"
  96. "out vec4 v_color;n"
  97. "void main ( )n"
  98. "{n"
  99. " gl_Position = ortho * transform * vec4 ( position, 0.0, 1.0 );n"
  100. " v_color = color;n"
  101. "}";
  102. const char *fshader =
  103. "#version 300 esn"
  104. "precision mediump float;n"
  105. "in vec4 v_color;n"
  106. "out vec4 frag_color;n"
  107. "void main ( )n"
  108. "{n"
  109. " frag_color = v_color;n"
  110. "}";
  111. GLuint program = loadProgram ( vshader, fshader );
  112. global.programs[POINTS] = program;
  113. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement