OpenGL/Utah teapot: Difference between revisions

m
m (→‎{{header|Phix}}: syntax coloured, marked p2js incompatible)
m (→‎{{header|Wren}}: Minor tidy)
 
(3 intermediate revisions by 2 users not shown)
Line 10:
 
This implementation sticks to the task requirements and only shows the teapot, it's rotating, so you can enjoy it's magnificence from all possible viewpoints and perspectives.
<syntaxhighlight lang="c">
<lang C>
#include<gl/freeglut.h>
 
Line 60:
return 0;
}
</syntaxhighlight>
</lang>
 
=={{header|FreeBASIC}}==
<syntaxhighlight lang="freebasic">#include "fbgfx.bi"
#include once "GL/glut.bi"
 
Dim Shared As Double rot = 0.0
 
Sub onIdle Cdecl ()
rot += 0.01
glutPostRedisplay()
End Sub
 
Sub display Cdecl ()
Dim matCol(0 To 3) As Const GLfloat = {1, 0, 0, 0}
glClear GL_COLOR_BUFFER_BIT Or GL_DEPTH_BUFFER_BIT
glPushMatrix()
glRotatef(30, 1, 1, 0)
glRotatef(rot, 0, 1, 1)
glMaterialfv GL_FRONT, GL_DIFFUSE, @matCol(0)
glutWireTeapot(0.5)
glPopMatrix()
glFlush()
End Sub
 
Sub init Cdecl ()
Dim white(0 To 3) As Const GLfloat = {1, 1, 1, 0}
Dim shini(1) As Const GLfloat = {70}
glClearColor(0.5, 0.5, 0.5, 0)
glShadeModel(GL_SMOOTH)
glLightfv(GL_LIGHT0, GL_AMBIENT, @white(0))
glLightfv(GL_LIGHT0, GL_DIFFUSE, @white(0))
glMaterialfv(GL_FRONT, GL_SHININESS, @shini(0))
glEnable(GL_LIGHTING)
glEnable(GL_LIGHT0)
glEnable(GL_DEPTH_TEST)
End Sub
 
Var argc = Cint(0)
glutInit(0, Strptr( " " ))
glutInitDisplayMode GLUT_SINGLE Or GLUT_RGB Or GLUT_DEPTH
glutInitWindowSize(900, 700)
glutCreateWindow("Utah Teapot")
glutIdleFunc(@onIdle)
glutDisplayFunc(@display)
init()
glutMainLoop()</syntaxhighlight>
 
=={{header|Go}}==
Line 67 ⟶ 113:
<br>
Although there are a number of third party Go bindings for OpenGL, the following uses 'cgo' to interface directly with the C libraries.
<langsyntaxhighlight lang="go">package main
 
/*
Line 137 ⟶ 183:
C.glutMainLoop()
C.free(unsafe.Pointer(tlc))
}</langsyntaxhighlight>
 
=={{header|J}}==
Line 144 ⟶ 190:
<br>
Direct translation from C.
<langsyntaxhighlight Jlang="j">NB. Teapot using freeglut
require '~Projects/freeglut/gldefs.ijs'
 
Line 209 ⟶ 255:
glutMainLoop void
void
)</langsyntaxhighlight>
 
=={{header|Julia}}==
Makie implements OpenGL shading graphics as part of its plotting functionality. The files are from the University of Utah site.
<langsyntaxhighlight Julialang="julia">using Makie, FileIO, InfoZIP
 
if stat("newell_teaset/teapot.obj").size == 0
Line 224 ⟶ 270:
rotate!(scene, Quaternion(0.6, 0.2, 0.2, 4.0))
display(scene)
</syntaxhighlight>
</lang>
 
=={{header|Kotlin}}==
Line 238 ⟶ 284:
</pre>
You then need to compile the following Kotlin program, linking against opengl.klib, and run the resulting .kexe file to view the rotating teapot.
<langsyntaxhighlight lang="scala">// Kotlin Native v0.6
 
import kotlinx.cinterop.*
Line 288 ⟶ 334:
glutIdleFunc(staticCFunction(::onIdle))
glutMainLoop()
}</langsyntaxhighlight>
 
=={{header|Nim}}==
Line 294 ⟶ 340:
{{libheader|OpenGL}}
{{libheader|Nim bindings for OpenGL}}
<langsyntaxhighlight Nimlang="nim">import opengl, opengl/glut
 
var
Line 322 ⟶ 368:
glutDisplayFunc(display)
loadExtensions()
glutMainLoop()</langsyntaxhighlight>
 
=={{header|Ol}}==
{{libheader|GL}}{{libheader|GLU}}
<langsyntaxhighlight lang="lisp">
; initial data:
(define vertices '(
Line 441 ⟶ 487:
(for-each render Handle:)
(for-each render Spout:))
</syntaxhighlight>
</lang>
 
=={{header|Phix}}==
{{trans|C}}
<!--<langsyntaxhighlight Phixlang="phix">(notonline)-->
<span style="color: #008080;">without</span> <span style="color: #008080;">js</span> <span style="color: #000080;font-style:italic;">-- (freeglut, allocate, poke, OpenGL 1.0)</span>
<span style="color: #008080;">include</span> <span style="color: #000000;">GL</span><span style="color: #0000FF;">/</span><span style="color: #000000;">gl</span><span style="color: #0000FF;">.</span><span style="color: #000000;">e</span>
Line 512 ⟶ 558:
<span style="color: #000000;">main</span><span style="color: #0000FF;">()</span>
<!--</langsyntaxhighlight>-->
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}}
<syntaxhighlight lang="raku" perl6line># 20210524 Raku programming solution
 
use NativeCall;
Line 593 ⟶ 639:
glutIdleFunc(&onIdle);
glutMainLoop();
</syntaxhighlight>
</lang>
 
Output: [https://drive.google.com/file/d/1XdLJhCRZ79cwDBPD7XDoRFeNFKc94-kp/view (Offsite Media file) ]
Line 601 ⟶ 647:
{{libheader|FreeGLUT}}
As it's not currently possible for Wren-cli to access OpenGL directly, we embed a Wren script in a C application to complete this task. See the [[OpenGL#Wren]] task for some of the issues involved here.
<langsyntaxhighlight ecmascriptlang="wren">/* utah_teapotOpenGL_Utah_teapot.wren */
 
var Rot = 0
Line 703 ⟶ 749:
Glut.displayFunc("GLCallbacks", "display()")
Glut.idleFunc("GLCallbacks", "onIdle()")
Glut.setOption(GLUT_ACTION_ON_WINDOW_CLOSE, GLUT_ACTION_GLUTMAINLOOP_RETURNS)</langsyntaxhighlight>
<br>
We now embed this Wren script in the following C program, compile and run it.
<langsyntaxhighlight lang="c">#include <stdlib.h>
#include <stdio.h>
#include <string.h>
Line 919 ⟶ 965:
vm = wrenNewVM(&config);
const char* module = "main";
const char* fileName = "utah_teapotOpenGL_Utah_teapot.wren";
char *script = readFile(fileName);
WrenInterpretResult result = wrenInterpret(vm, module, script);
Line 936 ⟶ 982:
free(script);
return 0;
}</langsyntaxhighlight>
 
{{out}}
9,485

edits