Changeset 4046b51 in opengl-game
- Timestamp:
- Aug 9, 2017, 2:43:13 AM (7 years ago)
- Branches:
- feature/imgui-sdl, master, points-test
- Children:
- 237ec28
- Parents:
- 363d5ff
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pong.cpp
r363d5ff r4046b51 15 15 GLuint createArrayBuffer(GLuint points_vbo, GLuint colors_vbo); 16 16 17 GLfloat* createCirclePoints(unsigned int smoothness, GLfloat centerX, GLfloat centerY, GLfloat radius); 18 GLfloat* createCircleColors(unsigned int smoothness); 19 20 const double PI = 3.1415926535897; 17 21 const bool FULLSCREEN = false; 18 22 … … 83 87 // glFrontFace(GL_CW); 84 88 85 GLfloat points[] = { 86 0.0f, 0.5f, 0.5f, 87 -0.5f, -0.5f, 0.5f, 88 0.5f, -0.5f, 0.5f, 89 }; 90 91 GLfloat colors[] = { 92 1.0, 0.0, 0.0, 93 0.0, 0.0, 1.0, 94 0.0, 1.0, 0.0, 95 }; 89 unsigned int numBallPoints = 3; 90 91 GLfloat* points = createCirclePoints(numBallPoints, 0.0f, 0.0f, 0.2f); 92 GLfloat* colors = createCircleColors(numBallPoints); 96 93 97 94 GLfloat points_paddle[] = { … … 120 117 }; 121 118 122 GLuint ball_points_vbo = createDataBuffer( sizeof(points), points);123 GLuint ball_colors_vbo = createDataBuffer( sizeof(colors), colors);119 GLuint ball_points_vbo = createDataBuffer(numBallPoints*3*sizeof(GLfloat), points); 120 GLuint ball_colors_vbo = createDataBuffer(numBallPoints*3*sizeof(GLfloat), colors); 124 121 GLuint ball_vao = createArrayBuffer(ball_points_vbo, ball_colors_vbo); 125 122 … … 166 163 glDrawArrays(GL_TRIANGLES, 0, sizeof(points_paddle)/sizeof(GLfloat)/3); 167 164 168 model[12] = last_position + speed*elapsed_seconds; 165 // model[12] = last_position + speed*elapsed_seconds; 166 model[12] = 0.0f; 169 167 last_position = model[12]; 170 168 model[13] = 0.0f; … … 175 173 glEnableVertexAttribArray(1); 176 174 177 glDrawArrays(GL_TRIANGLES, 0, sizeof(points)/sizeof(GLfloat)/3);175 glDrawArrays(GL_TRIANGLES, 0, numBallPoints); 178 176 179 177 glfwPollEvents(); … … 198 196 199 197 glfwTerminate(); 198 199 delete points; 200 delete colors; 201 200 202 return 0; 201 203 } … … 246 248 return vao; 247 249 } 250 251 GLfloat* createCirclePoints(unsigned int smoothness, GLfloat centerX, GLfloat centerY, GLfloat radius) { 252 GLfloat* points = new GLfloat[smoothness*3]; 253 254 points[0] = 0.0f; 255 points[1] = 0.5f; 256 points[2] = 0.5f; 257 points[3] = -0.5f; 258 points[4] = -0.5f; 259 points[5] = 0.5f; 260 points[6] = 0.5f; 261 points[7] = -0.5f; 262 points[8] = 0.5f; 263 264 cout << "Sphere center: (" << centerX << ", " << centerY << ")" << endl; 265 266 smoothness *= 2; 267 for (unsigned int i=0; i<smoothness; i++) { 268 double radians = PI/2 + 2*PI * i/smoothness; 269 cout << radians << endl;; 270 GLfloat x = centerX + cos(radians)*radius; 271 GLfloat y = centerY + sin(radians)*radius; 272 cout << "point " << i << ": (" << x << ", " << y << ")" << endl; 273 } 274 275 return points; 276 } 277 278 GLfloat* createCircleColors(unsigned int smoothness) { 279 GLfloat* colors = new GLfloat[smoothness*3]; 280 281 for (unsigned int i=0; i<smoothness; i++) { 282 colors[i*3] = 0.0f; 283 colors[i*3+1] = 1.0f; 284 colors[i*3+2] = 0.0f; 285 } 286 colors[smoothness*3-3] = 0.0f; 287 colors[smoothness*3-2] = 0.0f; 288 colors[smoothness*3-1] = 1.0f; 289 290 return colors; 291 }
Note:
See TracChangeset
for help on using the changeset viewer.