this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Added GPU_Sector() and GPU_SectorFilled().

+221 -4
+153
SDL_gpu/GL_common/SDL_gpuShapes_GL_common.inl
··· 364 364 SET_INDEXED_VERTEX(1); // first point 365 365 } 366 366 367 + static void Sector(GPU_Renderer* renderer, GPU_Target* target, float x, float y, float inner_radius, float outer_radius, float startAngle, float endAngle, SDL_Color color) 368 + { 369 + if(inner_radius < 0.0f) 370 + inner_radius = 0.0f; 371 + if(outer_radius < 0.0f) 372 + outer_radius = 0.0f; 373 + 374 + if(inner_radius > outer_radius) 375 + { 376 + float s = inner_radius; 377 + inner_radius = outer_radius; 378 + outer_radius = s; 379 + } 380 + 381 + if(inner_radius == outer_radius) 382 + { 383 + Arc(renderer, target, x, y, inner_radius, startAngle, endAngle, color); 384 + return; 385 + } 386 + 387 + // Composited shape... But that means error codes may be confusing. :-/ 388 + float dx1, dy1, dx2, dy2, dx3, dy3, dx4, dy4; 389 + Arc(renderer, target, x, y, inner_radius, startAngle, endAngle, color); 390 + 391 + dx1 = inner_radius*cos(endAngle*RADPERDEG); 392 + dy1 = inner_radius*sin(endAngle*RADPERDEG); 393 + dx2 = outer_radius*cos(endAngle*RADPERDEG); 394 + dy2 = outer_radius*sin(endAngle*RADPERDEG); 395 + Line(renderer, target, x+dx1, y+dy1, x+dx2, y+dy2, color); 396 + 397 + Arc(renderer, target, x, y, outer_radius, startAngle, endAngle, color); 398 + 399 + dx3 = inner_radius*cos(startAngle*RADPERDEG); 400 + dy3 = inner_radius*sin(startAngle*RADPERDEG); 401 + dx4 = outer_radius*cos(startAngle*RADPERDEG); 402 + dy4 = outer_radius*sin(startAngle*RADPERDEG); 403 + Line(renderer, target, x+dx3, y+dy3, x+dx4, y+dy4, color); 404 + } 405 + 406 + static void SectorFilled(GPU_Renderer* renderer, GPU_Target* target, float x, float y, float inner_radius, float outer_radius, float startAngle, float endAngle, SDL_Color color) 407 + { 408 + if(inner_radius < 0.0f) 409 + inner_radius = 0.0f; 410 + if(outer_radius < 0.0f) 411 + outer_radius = 0.0f; 412 + 413 + if(inner_radius > outer_radius) 414 + { 415 + float s = inner_radius; 416 + inner_radius = outer_radius; 417 + outer_radius = s; 418 + } 419 + 420 + if(inner_radius == outer_radius) 421 + { 422 + Arc(renderer, target, x, y, inner_radius, startAngle, endAngle, color); 423 + return; 424 + } 425 + 426 + 427 + if(startAngle > endAngle) 428 + { 429 + float swapa = endAngle; 430 + endAngle = startAngle; 431 + startAngle = swapa; 432 + } 433 + if(startAngle == endAngle) 434 + return; 435 + 436 + if(endAngle - startAngle >= 360) 437 + endAngle = startAngle + 360; 438 + 439 + 440 + float t = startAngle; 441 + float dt = ((endAngle - startAngle)/360)*(1.25f/sqrtf(outer_radius)) * DEGPERRAD; // s = rA, so dA = ds/r. ds of 1.25*sqrt(radius) is good, use A in degrees. 442 + float dx, dy; 443 + 444 + int numSegments = fabs(endAngle - startAngle)/dt; 445 + if(numSegments == 0) 446 + return; 447 + 448 + 449 + BEGIN_UNTEXTURED("GPU_SectorFilled", GL_TRIANGLES, 3 + (numSegments-1) + 1, 3 + (numSegments-1)*3 + 3); 450 + 451 + Uint8 use_inner = 0; // Switches between the radii for the next point 452 + 453 + // First triangle 454 + dx = inner_radius*cos(t*RADPERDEG); 455 + dy = inner_radius*sin(t*RADPERDEG); 456 + SET_UNTEXTURED_VERTEX(x+dx, y+dy, r, g, b, a); 457 + 458 + dx = outer_radius*cos(t*RADPERDEG); 459 + dy = outer_radius*sin(t*RADPERDEG); 460 + SET_UNTEXTURED_VERTEX(x+dx, y+dy, r, g, b, a); 461 + t += dt; 462 + dx = inner_radius*cos(t*RADPERDEG); 463 + dy = inner_radius*sin(t*RADPERDEG); 464 + SET_UNTEXTURED_VERTEX(x+dx, y+dy, r, g, b, a); 465 + t += dt; 466 + 467 + int i; 468 + for(i = 2; i < numSegments+1; i++) 469 + { 470 + SET_INDEXED_VERTEX(i-1); 471 + SET_INDEXED_VERTEX(i); 472 + if(use_inner) 473 + { 474 + dx = inner_radius*cos(t*RADPERDEG); 475 + dy = inner_radius*sin(t*RADPERDEG); 476 + } 477 + else 478 + { 479 + dx = outer_radius*cos(t*RADPERDEG); 480 + dy = outer_radius*sin(t*RADPERDEG); 481 + } 482 + SET_UNTEXTURED_VERTEX(x+dx, y+dy, r, g, b, a); // new point 483 + t += dt; 484 + use_inner = !use_inner; 485 + } 486 + 487 + // Last quad 488 + t = endAngle; 489 + if(use_inner) 490 + { 491 + dx = inner_radius*cos(t*RADPERDEG); 492 + dy = inner_radius*sin(t*RADPERDEG); 493 + } 494 + else 495 + { 496 + dx = outer_radius*cos(t*RADPERDEG); 497 + dy = outer_radius*sin(t*RADPERDEG); 498 + } 499 + SET_INDEXED_VERTEX(i-1); 500 + SET_INDEXED_VERTEX(i); 501 + SET_UNTEXTURED_VERTEX(x+dx, y+dy, r, g, b, a); // new point 502 + use_inner = !use_inner; 503 + i++; 504 + 505 + if(use_inner) 506 + { 507 + dx = inner_radius*cos(t*RADPERDEG); 508 + dy = inner_radius*sin(t*RADPERDEG); 509 + } 510 + else 511 + { 512 + dx = outer_radius*cos(t*RADPERDEG); 513 + dy = outer_radius*sin(t*RADPERDEG); 514 + } 515 + SET_INDEXED_VERTEX(i-1); 516 + SET_INDEXED_VERTEX(i); 517 + SET_UNTEXTURED_VERTEX(x+dx, y+dy, r, g, b, a); // new point 518 + } 519 + 367 520 static void Tri(GPU_Renderer* renderer, GPU_Target* target, float x1, float y1, float x2, float y2, float x3, float y3, SDL_Color color) 368 521 { 369 522 BEGIN_UNTEXTURED("GPU_Tri", GL_LINES, 3, 6);
+2
SDL_gpu/GL_common/SDL_gpu_GL_common.inl
··· 5210 5210 renderer->ArcFilled = &ArcFilled; \ 5211 5211 renderer->Circle = &Circle; \ 5212 5212 renderer->CircleFilled = &CircleFilled; \ 5213 + renderer->Sector = &Sector; \ 5214 + renderer->SectorFilled = &SectorFilled; \ 5213 5215 renderer->Tri = &Tri; \ 5214 5216 renderer->TriFilled = &TriFilled; \ 5215 5217 renderer->Rectangle = &Rectangle; \
+30
SDL_gpu/SDL_gpu.h
··· 688 688 /*! \see GPU_CircleFilled() */ 689 689 void (*CircleFilled)(GPU_Renderer* renderer, GPU_Target* target, float x, float y, float radius, SDL_Color color); 690 690 691 + /*! \see GPU_Sector() */ 692 + void (*Sector)(GPU_Renderer* renderer, GPU_Target* target, float x, float y, float inner_radius, float outer_radius, float startAngle, float endAngle, SDL_Color color); 693 + 694 + /*! \see GPU_SectorFilled() */ 695 + void (*SectorFilled)(GPU_Renderer* renderer, GPU_Target* target, float x, float y, float inner_radius, float outer_radius, float startAngle, float endAngle, SDL_Color color); 696 + 691 697 /*! \see GPU_Tri() */ 692 698 void (*Tri)(GPU_Renderer* renderer, GPU_Target* target, float x1, float y1, float x2, float y2, float x3, float y3, SDL_Color color); 693 699 ··· 1228 1234 * \param color The color of the shape to render 1229 1235 */ 1230 1236 void GPU_CircleFilled(GPU_Target* target, float x, float y, float radius, SDL_Color color); 1237 + 1238 + /*! Renders a colored annular sector outline (ring segment). 1239 + * \param target The destination render target 1240 + * \param x x-coord of center point 1241 + * \param y y-coord of center point 1242 + * \param inner_radius The inner radius of the ring 1243 + * \param outer_radius The outer radius of the ring 1244 + * \param startAngle The angle to start from, in degrees. Measured clockwise from the positive x-axis. 1245 + * \param endAngle The angle to end at, in degrees. Measured clockwise from the positive x-axis. 1246 + * \param color The color of the shape to render 1247 + */ 1248 + void GPU_Sector(GPU_Target* target, float x, float y, float inner_radius, float outer_radius, float startAngle, float endAngle, SDL_Color color); 1249 + 1250 + /*! Renders a colored filled annular sector (ring segment). 1251 + * \param target The destination render target 1252 + * \param x x-coord of center point 1253 + * \param y y-coord of center point 1254 + * \param inner_radius The inner radius of the ring 1255 + * \param outer_radius The outer radius of the ring 1256 + * \param startAngle The angle to start from, in degrees. Measured clockwise from the positive x-axis. 1257 + * \param endAngle The angle to end at, in degrees. Measured clockwise from the positive x-axis. 1258 + * \param color The color of the shape to render 1259 + */ 1260 + void GPU_SectorFilled(GPU_Target* target, float x, float y, float inner_radius, float outer_radius, float startAngle, float endAngle, SDL_Color color); 1231 1261 1232 1262 /*! Renders a colored triangle outline. 1233 1263 * \param target The destination render target
+18
SDL_gpu/SDL_gpuShapes.c
··· 79 79 return; 80 80 81 81 renderer->CircleFilled(renderer, target, x, y, radius, color); 82 + } 83 + 84 + void GPU_Sector(GPU_Target* target, float x, float y, float inner_radius, float outer_radius, float startAngle, float endAngle, SDL_Color color) 85 + { 86 + CHECK_RENDERER(); 87 + if(renderer->Sector == NULL) 88 + return; 89 + 90 + renderer->Sector(renderer, target, x, y, inner_radius, outer_radius, startAngle, endAngle, color); 91 + } 92 + 93 + void GPU_SectorFilled(GPU_Target* target, float x, float y, float inner_radius, float outer_radius, float startAngle, float endAngle, SDL_Color color) 94 + { 95 + CHECK_RENDERER(); 96 + if(renderer->SectorFilled == NULL) 97 + return; 98 + 99 + renderer->SectorFilled(renderer, target, x, y, inner_radius, outer_radius, startAngle, endAngle, color); 82 100 } 83 101 84 102 void GPU_Tri(GPU_Target* target, float x1, float y1, float x2, float y2, float x3, float y3, SDL_Color color)
+18 -4
demos/shapes/main.c
··· 23 23 long frameCount = 0; 24 24 25 25 int shapeType = 0; 26 - int numShapeTypes = 14; 26 + int numShapeTypes = 16; 27 27 28 28 int i; 29 29 ··· 100 100 int numArcs = numColors; 101 101 int ax[numArcs]; 102 102 int ay[numArcs]; 103 - float ar[numArcs]; 103 + float ar[numArcs]; 104 + float ar2[numArcs]; 104 105 float aa1[numArcs]; 105 106 float aa2[numArcs]; 106 107 for(i = 0; i < numArcs; i++) 107 108 { 108 109 ax[i] = rand()%screen->w; 109 110 ay[i] = rand()%screen->h; 110 - ar[i] = (rand()%screen->h)/10.0f; 111 + ar[i] = (rand()%screen->h)/10.0f; 112 + ar2[i] = ((rand()%101)/100.0f)*ar[i]; 111 113 aa1[i] = rand()%360; 112 114 aa2[i] = rand()%360; 113 115 } ··· 259 261 } 260 262 break; 261 263 case 12: 264 + for(i = 0; i < numArcs; i++) 265 + { 266 + GPU_Sector(screen, ax[i], ay[i], ar[i], ar2[i], aa1[i], aa2[i], colors[i]); 267 + } 268 + break; 269 + case 13: 270 + for(i = 0; i < numArcs; i++) 271 + { 272 + GPU_SectorFilled(screen, ax[i], ay[i], ar[i], ar2[i], aa1[i], aa2[i], colors[i]); 273 + } 274 + break; 275 + case 14: 262 276 for(i = 0; i < numPolys; i++) 263 277 { 264 278 GPU_Polygon(screen, pn[i], pv[i], colors[i]); 265 279 } 266 280 break; 267 - case 13: 281 + case 15: 268 282 for(i = 0; i < numPolys; i++) 269 283 { 270 284 GPU_PolygonFilled(screen, pn[i], pv[i], colors[i]);