CSCI441 OpenGL Library 6.0.1.1
CS@Mines CSCI441 Computer Graphics Course Library
Loading...
Searching...
No Matches
objects.hpp
Go to the documentation of this file.
1
15#ifndef CSCI441_OBJECTS_HPP
16#define CSCI441_OBJECTS_HPP
17
18#include "constants.h"
19#include "objects_impl.hpp"
20#include "teapot.hpp" // for teapot()
21
22#ifdef CSCI441_USE_GLEW
23 #include <GL/glew.h>
24#else
25 #include <glad/gl.h>
26#endif
27
28#include <glm/gtc/constants.hpp>
29
30#include <cassert> // for assert()
31
33
38namespace CSCI441 {
47 void setVertexAttributeLocations( GLint positionLocation, GLint normalLocation = -1, GLint texCoordLocation = -1, GLint tangentLocation = -1 );
48
52 [[maybe_unused]] void deleteObjectVAOs();
53
57 [[maybe_unused]] void deleteObjectVBOs();
58
71 [[maybe_unused]] void drawSolidCone( GLfloat base, GLfloat height, GLint stacks, GLint slices );
84 [[maybe_unused]] void drawWireCone( GLfloat base, GLfloat height, GLint stacks, GLint slices );
85
91 [[maybe_unused]] void drawSolidCube( GLfloat sideLength );
98 void drawSolidCubeFlat( GLfloat sideLength );
105 void drawSolidCubeIndexed( GLfloat sideLength );
112 [[maybe_unused]] void drawSolidCubeTextured( GLfloat sideLength );
119 [[maybe_unused]] void drawWireCube( GLfloat sideLength );
120
127 [[maybe_unused]] void drawCubeMap( GLfloat sideLength );
128
142 [[maybe_unused]] void drawSolidCylinder( GLfloat base, GLfloat top, GLfloat height, GLint stacks, GLint slices );
156 [[maybe_unused]] void drawWireCylinder( GLfloat base, GLfloat top, GLfloat height, GLint stacks, GLint slices );
157
171 [[maybe_unused]] void drawSolidDisk( GLfloat inner, GLfloat outer, GLint slices, GLint rings );
185 [[maybe_unused]] void drawWireDisk( GLfloat inner, GLfloat outer, GLint slices, GLint rings );
186
204 [[maybe_unused]] void drawSolidPartialDisk( GLfloat inner, GLfloat outer, GLint slices, GLint rings, GLfloat start, GLfloat sweep );
222 [[maybe_unused]] void drawWirePartialDisk( GLfloat inner, GLfloat outer, GLint slices, GLint rings, GLfloat start, GLfloat sweep );
223
234 [[maybe_unused]] void drawSolidSphere( GLfloat radius, GLint stacks, GLint slices );
245 [[maybe_unused]] void drawWireSphere( GLfloat radius, GLint stacks, GLint slices );
246
257 [[maybe_unused]] void drawSolidHalfSphere( GLfloat radius, GLint stacks, GLint slices );
268 [[maybe_unused]] void drawWireHalfSphere( GLfloat radius, GLint stacks, GLint slices );
269
280 [[maybe_unused]] void drawSolidDome( GLfloat radius, GLint stacks, GLint slices );
291 [[maybe_unused]] void drawWireDome( GLfloat radius, GLint stacks, GLint slices );
292
299 [[maybe_unused]] void drawSolidTeapot( GLfloat unused = 0.0f );
306 [[maybe_unused]] void drawWireTeapot( GLfloat unused = 0.0f );
307
320 [[maybe_unused]] void drawSolidTorus( GLfloat innerRadius, GLfloat outerRadius, GLint sides, GLint rings );
333 [[maybe_unused]] void drawWireTorus( GLfloat innerRadius, GLfloat outerRadius, GLint sides, GLint rings );
334}
335
338// Outward facing function implementations
339
341 const GLint positionLocation,
342 const GLint normalLocation,
343 const GLint texCoordLocation,
344 const GLint tangentLocation
345) {
346 CSCI441_INTERNAL::_positionAttributeLocation = positionLocation;
347 CSCI441_INTERNAL::_normalAttributeLocation = normalLocation;
348 CSCI441_INTERNAL::_texCoordAttributeLocation = texCoordLocation;
349 CSCI441_INTERNAL::_tangentAttributeLocation = tangentLocation;
350 CSCI441_INTERNAL::setTeapotAttributeLocations(positionLocation, normalLocation, texCoordLocation, tangentLocation);
351}
352
353[[maybe_unused]]
355 CSCI441_INTERNAL::deleteObjectVAOs();
356}
357
358[[maybe_unused]]
360 CSCI441_INTERNAL::deleteObjectVBOs();
361}
362
363[[maybe_unused]]
365 const GLfloat base,
366 const GLfloat height,
367 const GLint stacks,
368 const GLint slices
369) {
370 assert( base > 0.0f );
371 assert( height > 0.0f );
372 assert( stacks > 0 );
373 assert( slices > 2 );
374
375 CSCI441_INTERNAL::drawCylinder( base, 0.0f, height, stacks, slices, GL_FILL );
376}
377
378[[maybe_unused]]
380 const GLfloat base,
381 const GLfloat height,
382 const GLint stacks,
383 const GLint slices
384) {
385 assert( base > 0.0f );
386 assert( height > 0.0f );
387 assert( stacks > 0 );
388 assert( slices > 2 );
389
390 CSCI441_INTERNAL::drawCylinder( base, 0.0f, height, stacks, slices, GL_LINE );
391}
392
393[[maybe_unused]]
395 const GLfloat sideLength
396) {
397 drawSolidCubeIndexed(sideLength);
398}
399
400[[maybe_unused]]
402 const GLfloat sideLength
403) {
404 drawSolidCubeFlat(sideLength);
405}
406
408 const GLfloat sideLength
409) {
410 assert( sideLength > 0.0f );
411
412 CSCI441_INTERNAL::drawCube( sideLength, GL_FILL );
413}
414
416 const GLfloat sideLength
417) {
418 assert( sideLength > 0.0f );
419
420 CSCI441_INTERNAL::drawCubeFlat( sideLength, GL_FILL );
421}
422
423[[maybe_unused]]
425 const GLfloat sideLength
426) {
427 assert( sideLength > 0.0f );
428
429 CSCI441_INTERNAL::drawCube( sideLength, GL_LINE );
430}
431
432[[maybe_unused]]
434 const GLfloat sideLength
435) {
436 assert(sideLength > 0.0f);
437
438 CSCI441_INTERNAL::drawCube( sideLength, GL_FILL );
439}
440
441[[maybe_unused]]
443 const GLfloat base,
444 const GLfloat top,
445 const GLfloat height,
446 const GLint stacks,
447 const GLint slices
448) {
449 assert( (base >= 0.0f && top > 0.0f) || (base > 0.0f && top >= 0.0f) );
450 assert( height > 0.0f );
451 assert( stacks > 0 );
452 assert( slices > 2 );
453
454 CSCI441_INTERNAL::drawCylinder( base, top, height, stacks, slices, GL_FILL );
455}
456
457[[maybe_unused]]
459 const GLfloat base,
460 const GLfloat top,
461 const GLfloat height,
462 const GLint stacks,
463 const GLint slices
464) {
465 assert( (base >= 0.0f && top > 0.0f) || (base > 0.0f && top >= 0.0f) );
466 assert( height > 0.0f );
467 assert( stacks > 0 );
468 assert( slices > 2 );
469
470 CSCI441_INTERNAL::drawCylinder( base, top, height, stacks, slices, GL_LINE );
471}
472
473[[maybe_unused]]
475 const GLfloat inner,
476 const GLfloat outer,
477 const GLint slices,
478 const GLint rings
479) {
480 assert( inner >= 0.0f );
481 assert( outer > 0.0f );
482 assert( outer > inner );
483 assert( slices > 2 );
484 assert( rings > 0 );
485
486 CSCI441_INTERNAL::drawPartialDisk( inner, outer, slices, rings, 0, glm::two_pi<GLfloat>(), GL_FILL );
487}
488
489[[maybe_unused]]
491 const GLfloat inner,
492 const GLfloat outer,
493 const GLint slices,
494 const GLint rings
495) {
496 assert( inner >= 0.0f );
497 assert( outer > 0.0f );
498 assert( outer > inner );
499 assert( slices > 2 );
500 assert( rings > 0 );
501
502 CSCI441_INTERNAL::drawPartialDisk( inner, outer, slices, rings, 0, glm::two_pi<GLfloat>(), GL_LINE );
503}
504
505[[maybe_unused]]
507 const GLfloat inner,
508 const GLfloat outer,
509 const GLint slices,
510 const GLint rings,
511 const GLfloat start,
512 const GLfloat sweep
513) {
514 assert( inner >= 0.0f );
515 assert( outer > 0.0f );
516 assert( outer > inner );
517 assert( slices > 2 );
518 assert( rings > 0 );
519 assert( start >= 0.0f && start <= 360.0f );
520 assert( sweep >= 0.0f && sweep <= 360.0f );
521
522 CSCI441_INTERNAL::drawPartialDisk( inner, outer, slices, rings, start * glm::pi<float>() / 180.0f, sweep * glm::pi<float>() / 180.0f, GL_FILL );
523}
524
525[[maybe_unused]]
527 const GLfloat inner,
528 const GLfloat outer,
529 const GLint slices,
530 const GLint rings,
531 const GLfloat start,
532 const GLfloat sweep
533) {
534 assert( inner >= 0.0f );
535 assert( outer > 0.0f );
536 assert( outer > inner );
537 assert( slices > 2 );
538 assert( rings > 0 );
539 assert( start >= 0.0f && start <= 360.0f );
540 assert( sweep >= 0.0f && sweep <= 360.0f );
541
542 CSCI441_INTERNAL::drawPartialDisk( inner, outer, slices, rings, start * glm::pi<float>() / 180.0f, sweep * glm::pi<float>() / 180.0f, GL_LINE );
543}
544
545[[maybe_unused]]
547 const GLfloat radius,
548 const GLint stacks,
549 const GLint slices
550) {
551 assert( radius > 0.0f );
552 assert( stacks > 1 );
553 assert( slices > 2 );
554
555 CSCI441_INTERNAL::drawSphere( radius, stacks, slices, GL_FILL );
556}
557
558[[maybe_unused]]
560 const GLfloat radius,
561 const GLint stacks,
562 const GLint slices
563) {
564 assert( radius > 0.0f );
565 assert( stacks > 1);
566 assert( slices > 2 );
567
568 CSCI441_INTERNAL::drawSphere( radius, stacks, slices, GL_LINE );
569}
570
571[[maybe_unused]]
573 const GLfloat radius,
574 const GLint stacks,
575 const GLint slices
576) {
577 assert( radius > 0.0f );
578 assert( stacks > 1 );
579 assert( slices > 2 );
580
581 CSCI441_INTERNAL::drawHalfSphere( radius, stacks, slices, GL_FILL );
582}
583
584[[maybe_unused]]
586 const GLfloat radius,
587 const GLint stacks,
588 const GLint slices
589) {
590 assert( radius > 0.0f );
591 assert( stacks > 1);
592 assert( slices > 2 );
593
594 CSCI441_INTERNAL::drawHalfSphere( radius, stacks, slices, GL_LINE );
595}
596
597[[maybe_unused]]
599 const GLfloat radius,
600 const GLint stacks,
601 const GLint slices
602) {
603 assert( radius > 0.0f );
604 assert( stacks > 1 );
605 assert( slices > 2 );
606
607 CSCI441_INTERNAL::drawDome( radius, stacks, slices, GL_FILL );
608}
609
610[[maybe_unused]]
612 const GLfloat radius,
613 const GLint stacks,
614 const GLint slices
615) {
616 assert( radius > 0.0f );
617 assert( stacks > 1);
618 assert( slices > 2 );
619
620 CSCI441_INTERNAL::drawDome( radius, stacks, slices, GL_LINE );
621}
622
623[[maybe_unused]]
625 [[maybe_unused]] const GLfloat unused
626) {
627 CSCI441_INTERNAL::drawTeapot(GL_FILL);
628}
629
630[[maybe_unused]]
632 [[maybe_unused]] const GLfloat unused
633) {
634 CSCI441_INTERNAL::drawTeapot(GL_LINE);
635}
636
637[[maybe_unused]]
639 const GLfloat innerRadius,
640 const GLfloat outerRadius,
641 const GLint sides,
642 const GLint rings
643) {
644 assert( innerRadius > 0.0f );
645 assert( outerRadius > 0.0f );
646 assert( sides > 2 );
647 assert( rings > 2 );
648
649 CSCI441_INTERNAL::drawTorus( innerRadius, outerRadius, sides, rings, GL_FILL );
650}
651
652[[maybe_unused]]
654 const GLfloat innerRadius,
655 const GLfloat outerRadius,
656 const GLint sides,
657 const GLint rings
658) {
659 assert( innerRadius > 0.0f );
660 assert( outerRadius > 0.0f );
661 assert( sides > 2 );
662 assert( rings > 2 );
663
664 CSCI441_INTERNAL::drawTorus( innerRadius, outerRadius, sides, rings, GL_LINE );
665}
666
667#endif // __CSCI441_OBJECTS_HPP__
CSCI441 Helper Functions for OpenGL.
Definition: ArcballCam.hpp:17
void drawWireTeapot(GLfloat unused=0.0f)
Draws a wireframe teapot.
Definition: objects.hpp:631
void drawSolidCube(GLfloat sideLength)
Calls through to drawSolidCubeIndexed()
Definition: objects.hpp:394
void drawSolidCylinder(GLfloat base, GLfloat top, GLfloat height, GLint stacks, GLint slices)
Draws a solid open-ended cylinder.
Definition: objects.hpp:442
void drawWireCube(GLfloat sideLength)
Draws a wireframe cube.
Definition: objects.hpp:424
void drawSolidPartialDisk(GLfloat inner, GLfloat outer, GLint slices, GLint rings, GLfloat start, GLfloat sweep)
Draws part of a solid disk.
Definition: objects.hpp:506
void drawSolidDome(GLfloat radius, GLint stacks, GLint slices)
Draws a solid dome.
Definition: objects.hpp:598
void deleteObjectVBOs()
deletes the VBOs stored for all object types
Definition: objects.hpp:359
void deleteObjectVAOs()
deletes the VAOs stored for all object types
Definition: objects.hpp:354
void drawWireTorus(GLfloat innerRadius, GLfloat outerRadius, GLint sides, GLint rings)
Draws a wireframe torus.
Definition: objects.hpp:653
void drawWireDome(GLfloat radius, GLint stacks, GLint slices)
Draws a wireframe dome.
Definition: objects.hpp:611
void drawSolidCone(GLfloat base, GLfloat height, GLint stacks, GLint slices)
Draws a solid cone.
Definition: objects.hpp:364
void drawWireHalfSphere(GLfloat radius, GLint stacks, GLint slices)
Draws a wireframe half sphere with a bottom.
Definition: objects.hpp:585
void drawSolidCubeTextured(GLfloat sideLength)
Draws a solid textured cube. Calls through to drawSolidCubeFlat()
Definition: objects.hpp:401
void drawSolidTorus(GLfloat innerRadius, GLfloat outerRadius, GLint sides, GLint rings)
Draws a solid torus.
Definition: objects.hpp:638
void drawSolidHalfSphere(GLfloat radius, GLint stacks, GLint slices)
Draws a solid half sphere with a bottom.
Definition: objects.hpp:572
void drawSolidTeapot(GLfloat unused=0.0f)
Draws a solid teapot.
Definition: objects.hpp:624
void drawSolidCubeFlat(GLfloat sideLength)
Draws a solid cube with normals aligned with cube face.
Definition: objects.hpp:415
void drawWireSphere(GLfloat radius, GLint stacks, GLint slices)
Draws a wireframe sphere.
Definition: objects.hpp:559
void drawSolidSphere(GLfloat radius, GLint stacks, GLint slices)
Draws a solid sphere.
Definition: objects.hpp:546
void drawWireCone(GLfloat base, GLfloat height, GLint stacks, GLint slices)
Draws a wireframe cone.
Definition: objects.hpp:379
void drawSolidDisk(GLfloat inner, GLfloat outer, GLint slices, GLint rings)
Draws a solid disk.
Definition: objects.hpp:474
void drawSolidCubeIndexed(GLfloat sideLength)
Draws a solid cube.
Definition: objects.hpp:407
void drawCubeMap(GLfloat sideLength)
Draws a cube with 3D Texture Coordinates to map a cube map texture to it.
Definition: objects.hpp:433
void setVertexAttributeLocations(GLint positionLocation, GLint normalLocation=-1, GLint texCoordLocation=-1, GLint tangentLocation=-1)
Sets the attribute locations for vertex positions, normals, and texture coordinates.
Definition: objects.hpp:340
void drawWireDisk(GLfloat inner, GLfloat outer, GLint slices, GLint rings)
Draws a wireframe disk.
Definition: objects.hpp:490
void drawWirePartialDisk(GLfloat inner, GLfloat outer, GLint slices, GLint rings, GLfloat start, GLfloat sweep)
Draws part of a wireframe disk.
Definition: objects.hpp:526
void drawWireCylinder(GLfloat base, GLfloat top, GLfloat height, GLint stacks, GLint slices)
Draws a wireframe open-ended cylinder.
Definition: objects.hpp:458
Helper functions to draw 3D OpenGL 3.0+ objects.
Helper functions to draw teapot with OpenGL 3.0+.