Changeset eeece4e in opengl-game


Ignore:
Timestamp:
Aug 8, 2017, 1:11:28 AM (7 years ago)
Author:
Dmitry Portnoy <dmp1488@…>
Branches:
feature/imgui-sdl, master, points-test
Children:
363d5ff
Parents:
9e81839
Message:

In the pong game, allow shapes to be composed of multiple triangles and create a stationary red paddle on the left side of the screen.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pong.cpp

    r9e81839 reeece4e  
    9696
    9797   GLfloat points_paddle[] = {
    98        0.0f, -0.5f,  0.0f,
    99        0.5f,  0.5f,  0.0f,
    100       -0.5f,  0.5f,  0.0f,
     98      -1.0f,  1.0f,  0.0f,
     99      -1.0f,  0.7f,  0.0f,
     100      -0.9f,  0.7f,  0.0f,
     101      -1.0f,  1.0f,  0.0f,
     102      -0.9f,  0.7f,  0.0f,
     103      -0.9f,  1.0f,  0.0f,
    101104   };
    102105
    103106   GLfloat colors_paddle[] = {
    104107      1.0, 0.0, 0.0,
    105       0.0, 0.0, 1.0,
    106       0.0, 1.0, 0.0,
     108      1.0, 0.0, 0.0,
     109      1.0, 0.0, 0.0,
     110      1.0, 0.0, 0.0,
     111      1.0, 0.0, 0.0,
     112      1.0, 0.0, 0.0,
    107113   };
    108114
     
    111117     0.0f, 1.0f, 0.0f, 0.0f, // column 2
    112118     0.0f, 0.0f, 1.0f, 0.0f, // column 3
    113      0.5f, 0.0f, 0.0f, 1.0f, // column 4
     119     0.0f, 0.0f, 0.0f, 1.0f, // column 4
    114120   };
    115121
     
    130136
    131137   glLinkProgram(shader_program);
     138   glUseProgram(shader_program);
    132139
    133140   GLint location = glGetUniformLocation(shader_program, "model");
     
    146153      }
    147154
     155      glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
     156
     157      model[12] = 0.0f;
     158      glUniformMatrix4fv(location, 1, GL_FALSE, model);
     159
     160      glBindVertexArray(paddle_vao);
     161      glEnableVertexAttribArray(0);
     162      glEnableVertexAttribArray(1);
     163
     164      glDrawArrays(GL_TRIANGLES, 0, sizeof(points_paddle)/sizeof(GLfloat)/3);
     165
    148166      model[12] = last_position + speed*elapsed_seconds;
    149167      last_position = model[12];
    150       glUseProgram(shader_program);
    151168      glUniformMatrix4fv(location, 1, GL_FALSE, model);
    152 
    153       glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    154169
    155170      glBindVertexArray(ball_vao);
     
    157172      glEnableVertexAttribArray(1);
    158173
    159       glDrawArrays(GL_TRIANGLES, 0, 3);
    160 
    161       glBindVertexArray(paddle_vao);
    162       glEnableVertexAttribArray(0);
    163       glEnableVertexAttribArray(1);
    164 
    165       glDrawArrays(GL_TRIANGLES, 0, 3);
     174      glDrawArrays(GL_TRIANGLES, 0, sizeof(points)/sizeof(GLfloat)/3);
    166175
    167176      glfwPollEvents();
Note: See TracChangeset for help on using the changeset viewer.