Jump to content

OpenGL/Utah teapot: Difference between revisions

added Raku programming solution
(added Raku programming solution)
Line 476:
main()</lang>
To run this, you will need the freeglut package from [http://phix.x10.mx/pmwiki/pmwiki.php?n=Main.Freeglut-TheFreeOpenglUtilityToolkit PCAN]
 
=={{header|Raku}}==
{{trans|C}}
<lang perl6># 20210524 Raku programming solution
 
use NativeCall;
 
constant $lib = 'glut';
 
my $rot = 0e0;
# https://www.khronos.org/opengl/wiki/OpenGL_Type
enum GLenum (
GL_SMOOTH => 0x1D01, GL_LIGHT0 => 0x4000, GL_AMBIENT => 0x1200,
GL_DIFFUSE => 0x1201, GL_FRONT => 0x0404, GL_SHININESS => 0x1601,
GL_LIGHTING => 0x0B50, GL_DEPTH_TEST => 0x0B71,
);
enum GLbitfield ( GL_COLOR_BUFFER_BIT => 0x00004000, GL_DEPTH_BUFFER_BIT => 0x00000100, );
enum GLUTdisplay_mode ( GLUT_RGB => 0x0000, GLUT_SINGLE => 0x0000, GLUT_DEPTH => 0x0010, );
 
 
sub glutInit(CArray[uint32], CArray[Str]) is native($lib) {*};
sub glutInitDisplayMode(uint32 $mode) is native($lib) {*};
sub glutInitWindowSize(int32 $width, int32 $height) is native($lib) {*};
sub glutCreateWindow(Str $str) is native($lib) {*};
sub glClearColor(num32 $red, num32 $green, num32 $blue, num32 $alpha) is native($lib) {*};
sub glShadeModel(int32) is native($lib) {*};
sub glEnable(int32) is native($lib) {*};
sub glClear(int32) is native($lib) {*};
sub glutDisplayFunc(&func ()) is native($lib) {*};
sub glPushMatrix() is native($lib) {*};
sub glRotatef(num32 $angle, num32 $x, num32 $y, num32 $z) is native($lib) {*};
sub glutWireTeapot(num64 $size) is native($lib) {*};
sub glPopMatrix() is native($lib) {*};
sub glFlush() is native($lib) {*};
sub glutIdleFunc(&func ()) is native($lib) {*};
sub glutPostRedisplay() is native($lib) {*};
sub glutMainLoop() is native($lib) {*};
 
# Pitifully couldn't get the 'pointer to array' to work properly so omitted
sub glLightfv (int32, int32, Pointer[CArray[num32]] is rw) is native($lib) {*};
sub glMaterialfv(int32, int32, Pointer[CArray[num32]] is rw) is native($lib) {*};
 
 
sub init {
glClearColor(.5e0,.5e0,.5e0,0e0);
glShadeModel(GL_SMOOTH);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_DEPTH_TEST);
}
 
sub display {
glClear(GL_COLOR_BUFFER_BIT+|GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glRotatef(30e0,1e0,1e0,0e0);
glRotatef($rot,0e0,1e0,1e0);
glutWireTeapot(.5e0);
glPopMatrix();
glFlush();
}
 
sub onIdle {
$rot += 0.1e0; # changed from 0.01 for faster rotation rate
glutPostRedisplay();
}
 
 
glutInit(CArray[uint32].new,CArray[Str].new);
glutInitDisplayMode(GLUT_SINGLE+|GLUT_RGB+|GLUT_DEPTH);
glutInitWindowSize(900,700);
glutCreateWindow("The Amazing, Rotating Utah Teapot brought to you in OpenGL via freeglut.");
init();
glutDisplayFunc(&display);
glutIdleFunc(&onIdle);
glutMainLoop();
</lang>
 
Output: [https://drive.google.com/file/d/1WMyxdjDT-EV1UqZ-LF2O2xymXXpI-fGy/view (Offsite Media file) ]
354

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.