OpenGL: Difference between revisions

Content added Content deleted
m (→‎{{header|JavaScript}} (WebGL): Library doesn't go in header)
m (syntax highlighting fixup automation)
Line 14: Line 14:


opengl.adb:
opengl.adb:
<lang Ada>with Lumen.Window;
<syntaxhighlight lang="ada">with Lumen.Window;
with Lumen.Events;
with Lumen.Events;
with Lumen.Events.Animate;
with Lumen.Events.Animate;
Line 134: Line 134:
when Program_Exit =>
when Program_Exit =>
null; -- normal termination
null; -- normal termination
end OpenGL;</lang>
end OpenGL;</syntaxhighlight>


=={{header|AutoHotkey}}==
=={{header|AutoHotkey}}==
<lang AutoHotkey>hOpenGL32 := DllCall("LoadLibrary", "Str", "opengl32")
<syntaxhighlight lang="autohotkey">hOpenGL32 := DllCall("LoadLibrary", "Str", "opengl32")
Gui, +LastFound +Resize
Gui, +LastFound +Resize
hDC := DllCall("GetDC", "uInt", WinExist())
hDC := DllCall("GetDC", "uInt", WinExist())
Line 197: Line 197:
DllCall("ReleaseDC", "uInt", hDC)
DllCall("ReleaseDC", "uInt", hDC)
DllCall("FreeLibrary", "uInt", hOpenGL32)
DllCall("FreeLibrary", "uInt", hOpenGL32)
ExitApp</lang>
ExitApp</syntaxhighlight>


=={{header|BaCon}}==
=={{header|BaCon}}==
BaCon allows embedding C code. This is an example with GLUT.
BaCon allows embedding C code. This is an example with GLUT.
<lang qbasic>PRAGMA INCLUDE <GL/gl.h> <GL/freeglut.h>
<syntaxhighlight lang="qbasic">PRAGMA INCLUDE <GL/gl.h> <GL/freeglut.h>
PRAGMA LDFLAGS GL glut
PRAGMA LDFLAGS GL glut


Line 234: Line 234:


glutDisplayFunc(Triangle)
glutDisplayFunc(Triangle)
glutMainLoop()</lang>
glutMainLoop()</syntaxhighlight>


=={{header|BBC BASIC}}==
=={{header|BBC BASIC}}==
{{works with|BBC BASIC for Windows}}
{{works with|BBC BASIC for Windows}}
<lang bbcbasic> *FLOAT64
<syntaxhighlight lang="bbcbasic"> *FLOAT64
SYS "LoadLibrary", "OPENGL32.DLL" TO opengl%
SYS "LoadLibrary", "OPENGL32.DLL" TO opengl%
Line 319: Line 319:
ghRC% += 0 : IF ghRC% SYS `wglDeleteContext`, ghRC% : ghRC% = 0
ghRC% += 0 : IF ghRC% SYS `wglDeleteContext`, ghRC% : ghRC% = 0
ghDC% += 0 : IF ghDC% SYS "ReleaseDC", @hwnd%, ghDC% : ghDC% = 0
ghDC% += 0 : IF ghDC% SYS "ReleaseDC", @hwnd%, ghDC% : ghDC% = 0
ENDPROC</lang>
ENDPROC</syntaxhighlight>


=={{header|C}}==
=={{header|C}}==
Line 326: Line 326:
In this example, we use [[:Category:GLUT|GLUT]] to create a window and handle the main loop in a portable way. Windowing systems like MS Windows and X11 have their own platform-specific ways of handling these things.
In this example, we use [[:Category:GLUT|GLUT]] to create a window and handle the main loop in a portable way. Windowing systems like MS Windows and X11 have their own platform-specific ways of handling these things.


<lang c>#include <stdlib.h>
<syntaxhighlight lang="c">#include <stdlib.h>
#include <GL/gl.h>
#include <GL/gl.h>
#include <GL/glut.h>
#include <GL/glut.h>
Line 373: Line 373:


return EXIT_SUCCESS;
return EXIT_SUCCESS;
}</lang>
}</syntaxhighlight>


=={{header|C sharp|C#}}==
=={{header|C sharp|C#}}==
C# example using the [http://www.opentk.com/ OpenTK] library, which is multiplatform and provides C# OpenGL bindings for .Net and Mono. This code creates its own window and draws the triangle into it.
C# example using the [http://www.opentk.com/ OpenTK] library, which is multiplatform and provides C# OpenGL bindings for .Net and Mono. This code creates its own window and draws the triangle into it.


<lang csharp>using OpenTK;
<syntaxhighlight lang="csharp">using OpenTK;
using OpenTK.Graphics;
using OpenTK.Graphics;
namespace OpenGLTest
namespace OpenGLTest
Line 421: Line 421:
}
}
}
}
}</lang>
}</syntaxhighlight>


=={{header|Clojure}}==
=={{header|Clojure}}==
Line 427: Line 427:


In this example, we use [http://github.com/ztellman/penumbra Penumbra], which is an idiomatic wrapper for OpenGL.
In this example, we use [http://github.com/ztellman/penumbra Penumbra], which is an idiomatic wrapper for OpenGL.
<lang lisp>(use 'penumbra.opengl)
<syntaxhighlight lang="lisp">(use 'penumbra.opengl)
(require '[penumbra.app :as app])
(require '[penumbra.app :as app])


Line 448: Line 448:
(color 0 0 1) (vertex 0 30)))
(color 0 0 1) (vertex 0 30)))


(app/start {:display display, :reshape reshape, :init init} {})</lang>
(app/start {:display display, :reshape reshape, :init init} {})</syntaxhighlight>


=={{header|Common Lisp}}==
=={{header|Common Lisp}}==
Line 457: Line 457:
{{libheader|Lispbuilder-SDL}}
{{libheader|Lispbuilder-SDL}}


<lang lisp>(defun draw-triangle (x y &key (z 0) (type 'right))
<syntaxhighlight lang="lisp">(defun draw-triangle (x y &key (z 0) (type 'right))
(case type
(case type
(right
(right
Line 523: Line 523:
(setup-gl w h)
(setup-gl w h)
(setf (sdl:frame-rate) 2)
(setf (sdl:frame-rate) 2)
(main-loop)))</lang>
(main-loop)))</syntaxhighlight>


=={{header|D}}==
=={{header|D}}==
Line 532: Line 532:
{{libheader|dglut}}
{{libheader|dglut}}
opengl_sample.d:
opengl_sample.d:
<lang d>module opengl_sample; // file name + directory
<syntaxhighlight lang="d">module opengl_sample; // file name + directory
import dglut.core, dglut.window, dglut.opengl;
import dglut.core, dglut.window, dglut.opengl;


Line 563: Line 563:
}
}
loop;
loop;
}</lang>
}</syntaxhighlight>
=={{header|Delphi}}==
=={{header|Delphi}}==
{{libheader| System.Classes}}
{{libheader| System.Classes}}
Line 570: Line 570:
{{libheader| System.UITypes}}
{{libheader| System.UITypes}}
Thanks Neslib for libraries FastMath [https://github.com/neslib/FastMath], DelphiStb [https://github.com/neslib/DelphiStb] and Samples codes [https://github.com/neslib/DelphiLearnOpenGL] to abstract openGl functions and window creation.
Thanks Neslib for libraries FastMath [https://github.com/neslib/FastMath], DelphiStb [https://github.com/neslib/DelphiStb] and Samples codes [https://github.com/neslib/DelphiLearnOpenGL] to abstract openGl functions and window creation.
<syntaxhighlight lang="delphi">
<lang Delphi>
program OpenGLTriangle;
program OpenGLTriangle;


Line 642: Line 642:
begin
begin
RunApp(TTriangleApp, 640, 480, 'OpenGL Triangle');
RunApp(TTriangleApp, 640, 480, 'OpenGL Triangle');
end.</lang>
end.</syntaxhighlight>


=={{header|eC}}==
=={{header|eC}}==
{{libheader|Ecere}}
{{libheader|Ecere}}


<lang C>#include <GL/gl.h>
<syntaxhighlight lang="c">#include <GL/gl.h>
import "ecere"
import "ecere"


Line 681: Line 681:
}
}


GLTriangle window {};</lang>
GLTriangle window {};</syntaxhighlight>


=={{header|Euphoria}}==
=={{header|Euphoria}}==
{{works with|OpenEuphoria < 4.0}}
{{works with|OpenEuphoria < 4.0}}
Adapted from NeHe tutorial #3 nehe.gamedev.net
Adapted from NeHe tutorial #3 nehe.gamedev.net
<lang euphoria>
<syntaxhighlight lang="euphoria">
include get.e
include get.e
include dll.e
include dll.e
Line 979: Line 979:


WinMain()
WinMain()
</syntaxhighlight>
</lang>


=={{header|Factor}}==
=={{header|Factor}}==
Translated from C
Translated from C
<lang factor>USING: kernel math math.rectangles opengl.gl sequences ui
<syntaxhighlight lang="factor">USING: kernel math math.rectangles opengl.gl sequences ui
ui.gadgets ui.render ;
ui.gadgets ui.render ;
IN: rosettacode.opengl
IN: rosettacode.opengl
Line 1,016: Line 1,016:
[ triangle-gadget new "Triangle" open-window ] with-ui ;
[ triangle-gadget new "Triangle" open-window ] with-ui ;
MAIN: triangle-window
MAIN: triangle-window
</syntaxhighlight>
</lang>


=={{header|Forth}}==
=={{header|Forth}}==
Line 1,023: Line 1,023:
{{libheader|Theseus}}
{{libheader|Theseus}}
triangle.fs:
triangle.fs:
<lang forth>import glconst import float
<syntaxhighlight lang="forth">import glconst import float
glconst also float also opengl also</lang>
glconst also float also opengl also</syntaxhighlight>


triangle.m:
triangle.m:
<lang forth>#! xbigforth
<syntaxhighlight lang="forth">#! xbigforth
\ automatic generated code
\ automatic generated code
\ do not edit
\ do not edit
Line 1,080: Line 1,080:
$1 0 ?DO stop LOOP bye ;
$1 0 ?DO stop LOOP bye ;
script? [IF] main [THEN]
script? [IF] main [THEN]
previous previous previous</lang>
previous previous previous</syntaxhighlight>


=={{header|FreeBASIC}}==
=={{header|FreeBASIC}}==
This is adapted from example OpenGL code that's included with FreeBASIC distributions.
This is adapted from example OpenGL code that's included with FreeBASIC distributions.


<lang FreeBASIC>#include "fbgfx.bi"
<syntaxhighlight lang="freebasic">#include "fbgfx.bi"
#include once "GL/gl.bi"
#include once "GL/gl.bi"
#include once "GL/glu.bi"
#include once "GL/glu.bi"
Line 1,122: Line 1,122:
flip
flip


loop while inkey = ""</lang>
loop while inkey = ""</syntaxhighlight>


=={{header|Go}}==
=={{header|Go}}==
Line 1,130: Line 1,130:
<br>
<br>
This program was also tested on Windows 10 but ''may'' only work if you comment out the marked line. This is because gl.Init() may produce an initialization error which is non-critical as far as this program is concerned. The reason for this error is unknown (see [[https://rosettacode.org/wiki/Talk:OpenGL Talk page]]).
This program was also tested on Windows 10 but ''may'' only work if you comment out the marked line. This is because gl.Init() may produce an initialization error which is non-critical as far as this program is concerned. The reason for this error is unknown (see [[https://rosettacode.org/wiki/Talk:OpenGL Talk page]]).
<lang go>package main
<syntaxhighlight lang="go">package main


import (
import (
Line 1,220: Line 1,220:


gl.Flush()
gl.Flush()
}</lang>
}</syntaxhighlight>


=={{header|Haskell}}==
=={{header|Haskell}}==
<lang haskell>import Graphics.Rendering.OpenGL
<syntaxhighlight lang="haskell">import Graphics.Rendering.OpenGL
import Graphics.UI.GLUT
import Graphics.UI.GLUT


Line 1,247: Line 1,247:
corner r g b x y = do color (Color3 r g b :: Color3 GLfloat)
corner r g b x y = do color (Color3 r g b :: Color3 GLfloat)
vertex (Vertex2 x y :: Vertex2 GLfloat)</lang>
vertex (Vertex2 x y :: Vertex2 GLfloat)</syntaxhighlight>


=={{header|J}}==
=={{header|J}}==
Line 1,255: Line 1,255:
Additionally, if you are using 64 bit windows, to get opengl working on J602 you will need to copy jzopengl_win.ijs to jzopengl_win_64.ijs in system/classes/opengl/.
Additionally, if you are using 64 bit windows, to get opengl working on J602 you will need to copy jzopengl_win.ijs to jzopengl_win_64.ijs in system/classes/opengl/.


<lang J>coclass 'example'
<syntaxhighlight lang="j">coclass 'example'
(coinsert[require) 'jzopengl'
(coinsert[require) 'jzopengl'


Line 1,285: Line 1,285:
)
)


conew~'example'</lang>
conew~'example'</syntaxhighlight>


Note: OpenGL's initial state is well defined by the OpenGL standard.
Note: OpenGL's initial state is well defined by the OpenGL standard.
Line 1,291: Line 1,291:
=={{header|Java}}==
=={{header|Java}}==
This example uses [http://lwjgl.org/ LWJGL], a game library which has an OpenGL binding for Java
This example uses [http://lwjgl.org/ LWJGL], a game library which has an OpenGL binding for Java
<lang Java>import org.lwjgl.LWJGLException;
<syntaxhighlight lang="java">import org.lwjgl.LWJGLException;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;
import org.lwjgl.opengl.DisplayMode;
Line 1,349: Line 1,349:
}
}


</syntaxhighlight>
</lang>


=={{header|JavaScript}}==
=={{header|JavaScript}}==
Line 1,359: Line 1,359:
In the interest of brevity and not depending on an external matrix library, this example ''omits matrix operations entirely'', as OpenGL ES requires you to add those features yourself if you want them. Examples which show how to implement the classic OpenGL matrix stack are available at [http://learningwebgl.com/blog/?page_id=1217 Learning WebGL] (which this code was derived from).
In the interest of brevity and not depending on an external matrix library, this example ''omits matrix operations entirely'', as OpenGL ES requires you to add those features yourself if you want them. Examples which show how to implement the classic OpenGL matrix stack are available at [http://learningwebgl.com/blog/?page_id=1217 Learning WebGL] (which this code was derived from).


<lang html><html style="margin: 0;">
<syntaxhighlight lang="html"><html style="margin: 0;">
<head>
<head>
<title>Minimal WebGL Example</title>
<title>Minimal WebGL Example</title>
Line 1,474: Line 1,474:
</script>
</script>
</body>
</body>
</html></lang>
</html></syntaxhighlight>


=={{header|Julia}}==
=={{header|Julia}}==
Julia's Makie plotting package uses OpenGL as its backend. This example is from the Makie documentation.
Julia's Makie plotting package uses OpenGL as its backend. This example is from the Makie documentation.
<lang julia>using Makie
<syntaxhighlight lang="julia">using Makie


mesh([(0.0, 0.0), (0.5, 1.0), (1.0, 0.0)], color = [:red, :green, :blue], shading = false)
mesh([(0.0, 0.0), (0.5, 1.0), (1.0, 0.0)], color = [:red, :green, :blue], shading = false)
</syntaxhighlight>
</lang>


=={{header|Kotlin}}==
=={{header|Kotlin}}==
Line 1,487: Line 1,487:
{{libheader|GLUT}}
{{libheader|GLUT}}
{{Works with|Ubuntu 14.04}}
{{Works with|Ubuntu 14.04}}
<lang scala>// Kotlin Native version 0.3
<syntaxhighlight lang="scala">// Kotlin Native version 0.3


import kotlinx.cinterop.*
import kotlinx.cinterop.*
Line 1,534: Line 1,534:
glutMainLoop()
glutMainLoop()
}</lang>
}</syntaxhighlight>


{{output}}
{{output}}
Line 1,542: Line 1,542:


=={{header|Liberty BASIC}}==
=={{header|Liberty BASIC}}==
<lang lb>nomainwin
<syntaxhighlight lang="lb">nomainwin
struct rect, x as long, y as long, x2 as long, y2 as long
struct rect, x as long, y as long, x2 as long, y2 as long
struct PFD, Size as word, Version as word, Flags as long,_
struct PFD, Size as word, Version as word, Flags as long,_
Line 1,592: Line 1,592:
close #glu
close #glu
close #gl
close #gl
end</lang>
end</syntaxhighlight>


=={{header|Lingo}}==
=={{header|Lingo}}==
{{libheader|RavOpenGL xtra}}
{{libheader|RavOpenGL xtra}}
<lang Lingo>global gOpenGL -- RavOpenGL xtra instance
<syntaxhighlight lang="lingo">global gOpenGL -- RavOpenGL xtra instance
global GL -- OpenGL constants
global GL -- OpenGL constants


Line 1,653: Line 1,653:
-- Show the window
-- Show the window
_movie.stage.visible = TRUE
_movie.stage.visible = TRUE
end</lang>
end</syntaxhighlight>


=={{header|Lua}}==
=={{header|Lua}}==
Line 1,661: Line 1,661:
Note that GL functions that take constants in LuaGL can take either the numbers representing those flags (ie. gl.XXX + gl.YYY) or a comma-separated string of those flags (ie. "XXX,YYY"). This example uses strings.
Note that GL functions that take constants in LuaGL can take either the numbers representing those flags (ie. gl.XXX + gl.YYY) or a comma-separated string of those flags (ie. "XXX,YYY"). This example uses strings.


<lang lua>local gl = require "luagl"
<syntaxhighlight lang="lua">local gl = require "luagl"
local iup = require "iuplua"
local iup = require "iuplua"
require "iupluagl"
require "iupluagl"
Line 1,703: Line 1,703:


iup.MainLoop()
iup.MainLoop()
</syntaxhighlight>
</lang>


=={{header|Mathematica}} / {{header|Wolfram Language}}==
=={{header|Mathematica}} / {{header|Wolfram Language}}==
Non-Windows only:
Non-Windows only:
<lang Mathematica>Style[Graphics3D[{Polygon[{{-1, 0, 0}, {1, 0, 0}, {0, Sqrt[3], 0.5}},
<syntaxhighlight lang="mathematica">Style[Graphics3D[{Polygon[{{-1, 0, 0}, {1, 0, 0}, {0, Sqrt[3], 0.5}},
VertexColors -> {Red, Green, Blue}]}, Boxed -> False],
VertexColors -> {Red, Green, Blue}]}, Boxed -> False],
RenderingOptions -> {"3DRenderingEngine" -> "OpenGL"}]</lang>
RenderingOptions -> {"3DRenderingEngine" -> "OpenGL"}]</syntaxhighlight>


=={{header|MAXScript}}==
=={{header|MAXScript}}==
The choice of OpenGL or D3D in MAX is a user configuration setting. All MAXScript code is platform independent.
The choice of OpenGL or D3D in MAX is a user configuration setting. All MAXScript code is platform independent.
<lang maxscript>newMesh = mesh numVerts:3 numFaces:1
<syntaxhighlight lang="maxscript">newMesh = mesh numVerts:3 numFaces:1
setMesh newMesh vertices:#([-100, -100, 0], [100, -100, 0], [-100, 100, 0]) faces:#([1, 2, 3])
setMesh newMesh vertices:#([-100, -100, 0], [100, -100, 0], [-100, 100, 0]) faces:#([1, 2, 3])
defaultVCFaces newMesh
defaultVCFaces newMesh
Line 1,723: Line 1,723:
viewport.setType #view_top
viewport.setType #view_top
max tool maximize
max tool maximize
viewport.SetRenderLevel #smoothhighlights</lang>
viewport.SetRenderLevel #smoothhighlights</syntaxhighlight>


=={{header|Mercury}}==
=={{header|Mercury}}==
Line 1,729: Line 1,729:
{{libheader|mercury_opengl}}
{{libheader|mercury_opengl}}
Translated from C.
Translated from C.
<lang>:- module opengl.
<syntaxhighlight lang="text">:- module opengl.
:- interface.
:- interface.


Line 1,774: Line 1,774:
mogl.load_identity(!IO),
mogl.load_identity(!IO),
mogl.ortho(-30.0, 30.0, -30.0, 30.0, -30.0, 30.0, !IO),
mogl.ortho(-30.0, 30.0, -30.0, 30.0, -30.0, 30.0, !IO),
mogl.matrix_mode(modelview, !IO).</lang>
mogl.matrix_mode(modelview, !IO).</syntaxhighlight>


=={{header|Nim}}==
=={{header|Nim}}==
{{libheader|OpenGL}}
{{libheader|OpenGL}}
{{libheader|Nim bindings for OpenGL}}
{{libheader|Nim bindings for OpenGL}}
<lang nim>import opengl, opengl/glut
<syntaxhighlight lang="nim">import opengl, opengl/glut


proc paint() {.cdecl.} =
proc paint() {.cdecl.} =
Line 1,817: Line 1,817:
glutReshapeFunc(reshape)
glutReshapeFunc(reshape)


glutMainLoop()</lang>
glutMainLoop()</syntaxhighlight>


=={{header|OCaml}}==
=={{header|OCaml}}==
{{libheader|glMLite}}
{{libheader|glMLite}}
<lang ocaml>open GL
<syntaxhighlight lang="ocaml">open GL
open Glut
open Glut


Line 1,862: Line 1,862:


glutMainLoop();
glutMainLoop();
;;</lang>
;;</syntaxhighlight>


=={{header|Ol}}==
=={{header|Ol}}==
Line 1,868: Line 1,868:
OpenGL window works in background (as coroutine) and allow user to call any functions, including OpenGL, in REPL simultaneously with window rendering process.
OpenGL window works in background (as coroutine) and allow user to call any functions, including OpenGL, in REPL simultaneously with window rendering process.


<lang scheme>
<syntaxhighlight lang="scheme">
(import (lib gl))
(import (lib gl))
(gl:set-window-title "Rosettacode OpenGL example")
(gl:set-window-title "Rosettacode OpenGL example")
Line 1,896: Line 1,896:
(glEnd)
(glEnd)
))
))
</syntaxhighlight>
</lang>


=={{header|OxygenBasic}}==
=={{header|OxygenBasic}}==
<lang oxygenbasic>
<syntaxhighlight lang="oxygenbasic">
title="Rotating Triangle"
title="Rotating Triangle"
include "OpenglSceneFrame.inc"
include "OpenglSceneFrame.inc"
Line 1,942: Line 1,942:
end sub
end sub


</syntaxhighlight>
</lang>


=={{header|Pascal}}==
=={{header|Pascal}}==
Line 1,950: Line 1,950:
{{libheader|GLUT}}
{{libheader|GLUT}}
Ported from the C example.
Ported from the C example.
<lang pascal>Program OpenGLDemo;
<syntaxhighlight lang="pascal">Program OpenGLDemo;


uses
uses
Line 2,000: Line 2,000:
end.
end.


</syntaxhighlight>
</lang>


=={{header|Perl}}==
=={{header|Perl}}==
<lang perl>use OpenGL;
<syntaxhighlight lang="perl">use OpenGL;


sub triangle {
sub triangle {
Line 2,026: Line 2,026:
glpFlush;
glpFlush;


glpMainLoop;</lang>
glpMainLoop;</syntaxhighlight>


==={{libheader|Perl/SDL}}===
==={{libheader|Perl/SDL}}===
<lang perl>use SDL::App;
<syntaxhighlight lang="perl">use SDL::App;
use SDL::Event;
use SDL::Event;
use SDL::OpenGL;
use SDL::OpenGL;
Line 2,057: Line 2,057:
$app->loop ({
$app->loop ({
SDL_QUIT() => sub { exit; },
SDL_QUIT() => sub { exit; },
});</lang>
});</syntaxhighlight>


=={{header|Phix}}==
=={{header|Phix}}==
Line 2,065: Line 2,065:
This can be run online [http://phix.x10.mx/p2js/OpenGL.htm here], also works on desktop/Phix.<br>
This can be run online [http://phix.x10.mx/p2js/OpenGL.htm here], also works on desktop/Phix.<br>
You can find older windows 32bit only and OpenGL 1.0 verions [[OpenGL/Phix|here]].
You can find older windows 32bit only and OpenGL 1.0 verions [[OpenGL/Phix|here]].
<!--<lang Phix>(phixonline)-->
<!--<syntaxhighlight lang="phix">(phixonline)-->
<span style="color: #000080;font-style:italic;">--
<span style="color: #000080;font-style:italic;">--
-- demo\rosetta\OpenGL.exw
-- demo\rosetta\OpenGL.exw
Line 2,192: Line 2,192:
<span style="color: #008080;">end</span> <span style="color: #008080;">procedure</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">procedure</span>
<span style="color: #000000;">main</span><span style="color: #0000FF;">()</span>
<span style="color: #000000;">main</span><span style="color: #0000FF;">()</span>
<!--</lang>-->
<!--</syntaxhighlight>-->


=={{header|PicoLisp}}==
=={{header|PicoLisp}}==
This is for the 64-bit version.
This is for the 64-bit version.
<lang PicoLisp>(load "@lib/openGl.l")
<syntaxhighlight lang="picolisp">(load "@lib/openGl.l")


(glutInit)
(glutInit)
Line 2,229: Line 2,229:
(mouseFunc '((Btn State X Y) (bye)))
(mouseFunc '((Btn State X Y) (bye)))


(glutMainLoop)</lang>
(glutMainLoop)</syntaxhighlight>


=={{header|Pike}}==
=={{header|Pike}}==
Uses GLUE to create the window. Rendering code is based on the C example.
Uses GLUE to create the window. Rendering code is based on the C example.
<lang pike>int main() {
<syntaxhighlight lang="pike">int main() {
GLUE.init(([
GLUE.init(([
"fullscreen": 0,
"fullscreen": 0,
Line 2,269: Line 2,269:
sleep(0.01);
sleep(0.01);
}
}
}</lang>
}</syntaxhighlight>


=={{header|PureBasic}}==
=={{header|PureBasic}}==
Line 2,275: Line 2,275:




<syntaxhighlight lang="purebasic">
<lang Purebasic>
XIncludeFile "OpenGL.pbi"
XIncludeFile "OpenGL.pbi"
pfd.PIXELFORMATDESCRIPTOR
pfd.PIXELFORMATDESCRIPTOR
Line 2,318: Line 2,318:
Wend
Wend


</syntaxhighlight>
</lang>


=={{header|Python}}==
=={{header|Python}}==
<lang python>#!/usr/bin/env python
<syntaxhighlight lang="python">#!/usr/bin/env python
#-*- coding: utf-8 -*-
#-*- coding: utf-8 -*-


Line 2,362: Line 2,362:
glutReshapeFunc(reshape)
glutReshapeFunc(reshape)


glutMainLoop()</lang>
glutMainLoop()</syntaxhighlight>
=={{header|QB64}}==
=={{header|QB64}}==
<syntaxhighlight lang="qb64">
<lang QB64>
'Task
'Task
'Display a smooth shaded triangle with OpenGL.
'Display a smooth shaded triangle with OpenGL.
Line 2,390: Line 2,390:
_glEnd
_glEnd
End Sub
End Sub
</syntaxhighlight>
</lang>
=={{header|R}}==
=={{header|R}}==
{{libheader|rgl}}
{{libheader|rgl}}
<lang R>library(rgl)
<syntaxhighlight lang="r">library(rgl)
x <- c(-1, -1, 1)
x <- c(-1, -1, 1)
y <- c(0, -1, -1)
y <- c(0, -1, -1)
Line 2,399: Line 2,399:
M <- cbind(x,y,z)
M <- cbind(x,y,z)
rgl.bg(color="gray15")
rgl.bg(color="gray15")
triangles3d(M, col=rainbow(8))</lang>
triangles3d(M, col=rainbow(8))</syntaxhighlight>


=={{header|Racket}}==
=={{header|Racket}}==
Line 2,407: Line 2,407:
If OpenGL context creation fails please consult Racket [http://docs.racket-lang.org/gui/libs.html documentation]
If OpenGL context creation fails please consult Racket [http://docs.racket-lang.org/gui/libs.html documentation]


<lang racket>
<syntaxhighlight lang="racket">
#lang racket/gui
#lang racket/gui
(require sgl/gl)
(require sgl/gl)
Line 2,450: Line 2,450:


(send win show #t)
(send win show #t)
</syntaxhighlight>
</lang>


=={{header|Raku}}==
=={{header|Raku}}==
Line 2,459: Line 2,459:
It's a little verbose since it is doing all of the setup and loading manually.
It's a little verbose since it is doing all of the setup and loading manually.


<lang perl6>use NativeCall;
<syntaxhighlight lang="raku" line>use NativeCall;


class Window is repr('CPointer') {}
class Window is repr('CPointer') {}
Line 2,547: Line 2,547:


glfwTerminate();
glfwTerminate();
</syntaxhighlight>
</lang>


See screen cap: [https://github.com/thundergnat/rc/blob/master/img/OpenGL-Triangle-perl6.png OpenGL-Triangle-perl6.png] (Offsite PNG image.)
See screen cap: [https://github.com/thundergnat/rc/blob/master/img/OpenGL-Triangle-perl6.png OpenGL-Triangle-perl6.png] (Offsite PNG image.)
Line 2,554: Line 2,554:


=={{header|Ring}}==
=={{header|Ring}}==
<lang ring>
<syntaxhighlight lang="ring">
# Project: OpenGL
# Project: OpenGL


Line 2,577: Line 2,577:
glEnd()
glEnd()
glutSwapBuffers()
glutSwapBuffers()
</syntaxhighlight>
</lang>
Outputimage:
Outputimage:


Line 2,585: Line 2,585:
{{libheader|ruby-opengl}}
{{libheader|ruby-opengl}}


<lang ruby>require 'rubygems'
<syntaxhighlight lang="ruby">require 'rubygems'
require 'gl'
require 'gl'
require 'glut'
require 'glut'
Line 2,628: Line 2,628:
glutReshapeFunc(reshape)
glutReshapeFunc(reshape)


glutMainLoop</lang>
glutMainLoop</syntaxhighlight>
=={{header|Rust}}==
=={{header|Rust}}==
using glutin for window creation and glow for opengl/opengles functions. as such, the fixed function pipeline is not supported
using glutin for window creation and glow for opengl/opengles functions. as such, the fixed function pipeline is not supported
<lang Rust>use glow::*;
<syntaxhighlight lang="rust">use glow::*;
use glutin::event::*;
use glutin::event::*;
use glutin::event_loop::{ControlFlow, EventLoop};
use glutin::event_loop::{ControlFlow, EventLoop};
Line 2,741: Line 2,741:
_ => {}
_ => {}
});
});
}</lang>
}</syntaxhighlight>
=={{header|Scala}}==
=={{header|Scala}}==
{{libheader|Light Weight Java Game Library}}
{{libheader|Light Weight Java Game Library}}
<lang Scala>import org.lwjgl.opengl.{ Display, DisplayMode }
<syntaxhighlight lang="scala">import org.lwjgl.opengl.{ Display, DisplayMode }
import org.lwjgl.opengl.GL11._
import org.lwjgl.opengl.GL11._


Line 2,782: Line 2,782:
Thread.sleep(1000)
Thread.sleep(1000)
}
}
}</lang>
}</syntaxhighlight>


=={{header|Tcl}}==
=={{header|Tcl}}==
{{libheader|Tk}}
{{libheader|Tk}}
{{libheader|tcl3d}}
{{libheader|tcl3d}}
<lang Tcl>package require Tk
<syntaxhighlight lang="tcl">package require Tk
package require tcl3d
package require tcl3d


Line 2,816: Line 2,816:
togl .surface -width 640 -height 480 -double true -depth true \
togl .surface -width 640 -height 480 -double true -depth true \
-displayproc paintShape -reshapeproc resizedWin
-displayproc paintShape -reshapeproc resizedWin
pack .surface -fill both -expand 1</lang>Most of this code should be very familiar to anyone looking at the C version above, or with normal [[Tk]] applications.
pack .surface -fill both -expand 1</syntaxhighlight>Most of this code should be very familiar to anyone looking at the C version above, or with normal [[Tk]] applications.


=={{header|Wren}}==
=={{header|Wren}}==
Line 2,826: Line 2,826:


Notice that we can't pass Wren methods directly to the glutDisplayFunc and glutReshapeFunc functions for callback registration purposes because of re-entrancy problems so, instead, we pass sufficient information from Wren to enable the callbacks to be constructed from the C side.
Notice that we can't pass Wren methods directly to the glutDisplayFunc and glutReshapeFunc functions for callback registration purposes because of re-entrancy problems so, instead, we pass sufficient information from Wren to enable the callbacks to be constructed from the C side.
<lang ecmascript>/* opengl.wren */
<syntaxhighlight lang="ecmascript">/* opengl.wren */


var GL_COLOR_BUFFER_BIT = 0x4000
var GL_COLOR_BUFFER_BIT = 0x4000
Line 2,911: Line 2,911:
Glut.displayFunc("GLCallbacks", "paint()")
Glut.displayFunc("GLCallbacks", "paint()")
Glut.reshapeFunc("GLCallbacks", "reshape(_,_)")
Glut.reshapeFunc("GLCallbacks", "reshape(_,_)")
Glut.setOption(GLUT_ACTION_ON_WINDOW_CLOSE, GLUT_ACTION_GLUTMAINLOOP_RETURNS)</lang>
Glut.setOption(GLUT_ACTION_ON_WINDOW_CLOSE, GLUT_ACTION_GLUTMAINLOOP_RETURNS)</syntaxhighlight>
<br>
<br>
We now embed this Wren script in the following C program, compile and run it.
We now embed this Wren script in the following C program, compile and run it.
<lang c>#include <stdlib.h>
<syntaxhighlight lang="c">#include <stdlib.h>
#include <stdio.h>
#include <stdio.h>
#include <string.h>
#include <string.h>
Line 3,140: Line 3,140:
free(script);
free(script);
return 0;
return 0;
}</lang>
}</syntaxhighlight>


{{out}}
{{out}}