OpenGL: Difference between revisions
m
→{{header|Wren}}: Minor tidy
(→{{header|Phix}}: added p2js compatible version, archived prior to sub-page) |
m (→{{header|Wren}}: Minor tidy) |
||
(3 intermediate revisions by 2 users not shown) | |||
Line 14:
opengl.adb:
<
with Lumen.Events;
with Lumen.Events.Animate;
Line 134:
when Program_Exit =>
null; -- normal termination
end OpenGL;</
=={{header|AutoHotkey}}==
<
Gui, +LastFound +Resize
hDC := DllCall("GetDC", "uInt", WinExist())
Line 197:
DllCall("ReleaseDC", "uInt", hDC)
DllCall("FreeLibrary", "uInt", hOpenGL32)
ExitApp</
=={{header|BaCon}}==
BaCon allows embedding C code. This is an example with GLUT.
<
PRAGMA LDFLAGS GL glut
Line 234:
glutDisplayFunc(Triangle)
glutMainLoop()</
=={{header|BBC BASIC}}==
{{works with|BBC BASIC for Windows}}
<
SYS "LoadLibrary", "OPENGL32.DLL" TO opengl%
Line 319:
ghRC% += 0 : IF ghRC% SYS `wglDeleteContext`, ghRC% : ghRC% = 0
ghDC% += 0 : IF ghDC% SYS "ReleaseDC", @hwnd%, ghDC% : ghDC% = 0
ENDPROC</
=={{header|C}}==
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.
<
#include <GL/gl.h>
#include <GL/glut.h>
Line 373:
return EXIT_SUCCESS;
}</
=={{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.
<
using OpenTK.Graphics;
namespace OpenGLTest
Line 421:
}
}
}</
=={{header|Clojure}}==
Line 427:
In this example, we use [http://github.com/ztellman/penumbra Penumbra], which is an idiomatic wrapper for OpenGL.
<
(require '[penumbra.app :as app])
Line 448:
(color 0 0 1) (vertex 0 30)))
(app/start {:display display, :reshape reshape, :init init} {})</
=={{header|Common Lisp}}==
Line 457:
{{libheader|Lispbuilder-SDL}}
<
(case type
(right
Line 523:
(setup-gl w h)
(setf (sdl:frame-rate) 2)
(main-loop)))</
=={{header|D}}==
Line 532:
{{libheader|dglut}}
opengl_sample.d:
<
import dglut.core, dglut.window, dglut.opengl;
Line 563:
}
loop;
}</
=={{header|Delphi}}==
{{libheader| System.Classes}}
Line 570:
{{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.
<syntaxhighlight lang="delphi">
program OpenGLTriangle;
Line 642:
begin
RunApp(TTriangleApp, 640, 480, 'OpenGL Triangle');
end.</
=={{header|eC}}==
{{libheader|Ecere}}
<
import "ecere"
Line 681:
}
GLTriangle window {};</
=={{header|Euphoria}}==
{{works with|OpenEuphoria < 4.0}}
Adapted from NeHe tutorial #3 nehe.gamedev.net
<
include get.e
include dll.e
Line 979:
WinMain()
</syntaxhighlight>
=={{header|Factor}}==
Translated from C
<
ui.gadgets ui.render ;
IN: rosettacode.opengl
Line 1,016:
[ triangle-gadget new "Triangle" open-window ] with-ui ;
MAIN: triangle-window
</syntaxhighlight>
=={{header|Forth}}==
Line 1,023:
{{libheader|Theseus}}
triangle.fs:
<
glconst also float also opengl also</
triangle.m:
<
\ automatic generated code
\ do not edit
Line 1,080:
$1 0 ?DO stop LOOP bye ;
script? [IF] main [THEN]
previous previous previous</
=={{header|FreeBASIC}}==
This is adapted from example OpenGL code that's included with FreeBASIC distributions.
<
#include once "GL/gl.bi"
#include once "GL/glu.bi"
Line 1,122:
flip
loop while inkey = ""</
=={{header|Go}}==
Line 1,130:
<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]]).
<
import (
Line 1,220:
gl.Flush()
}</
=={{header|Haskell}}==
<
import Graphics.UI.GLUT
Line 1,247:
corner r g b x y = do color (Color3 r g b :: Color3 GLfloat)
vertex (Vertex2 x y :: Vertex2 GLfloat)</
=={{header|J}}==
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/.
<
(coinsert[require) 'jzopengl'
Line 1,285:
)
conew~'example'</
Note: OpenGL's initial state is well defined by the OpenGL standard.
Line 1,291:
=={{header|Java}}==
This example uses [http://lwjgl.org/ LWJGL], a game library which has an OpenGL binding for Java
<
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;
Line 1,349:
}
</syntaxhighlight>
=={{header|JavaScript}}
===(WebGL)===
Unfortunately for comparison with the other examples on this page, WebGL provides only OpenGL ES, which removes the classic “fixed-function pipeline” and glVertex() in favor of requiring you to write ''vertex shaders'' and ''fragment shaders'', and use vertex arrays. It is not hard to write shader programs to emulate as much of the fixed-function pipeline as you need, but it does mean more verbosity as you have to explicitly define all of the data you're going to communicate to your shader.
Line 1,357 ⟶ 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).
<
<head>
<title>Minimal WebGL Example</title>
Line 1,472 ⟶ 1,474:
</script>
</body>
</html></
=={{header|Julia}}==
Julia's Makie plotting package uses OpenGL as its backend. This example is from the Makie documentation.
<
mesh([(0.0, 0.0), (0.5, 1.0), (1.0, 0.0)], color = [:red, :green, :blue], shading = false)
</syntaxhighlight>
=={{header|Kotlin}}==
Line 1,485 ⟶ 1,487:
{{libheader|GLUT}}
{{Works with|Ubuntu 14.04}}
<
import kotlinx.cinterop.*
Line 1,532 ⟶ 1,534:
glutMainLoop()
}</
{{output}}
Line 1,540 ⟶ 1,542:
=={{header|Liberty BASIC}}==
<
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,_
Line 1,590 ⟶ 1,592:
close #glu
close #gl
end</
=={{header|Lingo}}==
{{libheader|RavOpenGL xtra}}
<
global GL -- OpenGL constants
Line 1,651 ⟶ 1,653:
-- Show the window
_movie.stage.visible = TRUE
end</
=={{header|Lua}}==
Line 1,659 ⟶ 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.
<
local iup = require "iuplua"
require "iupluagl"
Line 1,701 ⟶ 1,703:
iup.MainLoop()
</syntaxhighlight>
=={{header|Mathematica}} / {{header|Wolfram Language}}==
Non-Windows only:
<
VertexColors -> {Red, Green, Blue}]}, Boxed -> False],
RenderingOptions -> {"3DRenderingEngine" -> "OpenGL"}]</
=={{header|MAXScript}}==
The choice of OpenGL or D3D in MAX is a user configuration setting. All MAXScript code is platform independent.
<
setMesh newMesh vertices:#([-100, -100, 0], [100, -100, 0], [-100, 100, 0]) faces:#([1, 2, 3])
defaultVCFaces newMesh
Line 1,721 ⟶ 1,723:
viewport.setType #view_top
max tool maximize
viewport.SetRenderLevel #smoothhighlights</
=={{header|Mercury}}==
Line 1,727 ⟶ 1,729:
{{libheader|mercury_opengl}}
Translated from C.
<syntaxhighlight lang="text">:- module opengl.
:- interface.
Line 1,772 ⟶ 1,774:
mogl.load_identity(!IO),
mogl.ortho(-30.0, 30.0, -30.0, 30.0, -30.0, 30.0, !IO),
mogl.matrix_mode(modelview, !IO).</
=={{header|Nim}}==
{{libheader|OpenGL}}
{{libheader|Nim bindings for OpenGL}}
<
proc paint() {.cdecl.} =
Line 1,815 ⟶ 1,817:
glutReshapeFunc(reshape)
glutMainLoop()</
=={{header|OCaml}}==
{{libheader|glMLite}}
<
open Glut
Line 1,860 ⟶ 1,862:
glutMainLoop();
;;</
=={{header|Ol}}==
Line 1,866 ⟶ 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.
<
(import (lib gl))
(gl:set-window-title "Rosettacode OpenGL example")
Line 1,894 ⟶ 1,896:
(glEnd)
))
</syntaxhighlight>
=={{header|OxygenBasic}}==
<
title="Rotating Triangle"
include "OpenglSceneFrame.inc"
Line 1,940 ⟶ 1,942:
end sub
</syntaxhighlight>
=={{header|Pascal}}==
Line 1,948 ⟶ 1,950:
{{libheader|GLUT}}
Ported from the C example.
<
uses
Line 1,998 ⟶ 2,000:
end.
</syntaxhighlight>
=={{header|Perl}}==
<
sub triangle {
Line 2,024 ⟶ 2,026:
glpFlush;
glpMainLoop;</
==={{libheader|Perl/SDL}}===
<
use SDL::Event;
use SDL::OpenGL;
Line 2,055 ⟶ 2,057:
$app->loop ({
SDL_QUIT() => sub { exit; },
});</
=={{header|Phix}}==
Line 2,062 ⟶ 2,064:
{{trans|JavaScript}}
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
<!--<
<span style="color: #000080;font-style:italic;">--
-- demo\rosetta\OpenGL.exw
Line 2,190 ⟶ 2,192:
<span style="color: #008080;">end</span> <span style="color: #008080;">procedure</span>
<span style="color: #000000;">main</span><span style="color: #0000FF;">()</span>
<!--</
=={{header|PicoLisp}}==
This is for the 64-bit version.
<
(glutInit)
Line 2,227 ⟶ 2,229:
(mouseFunc '((Btn State X Y) (bye)))
(glutMainLoop)</
=={{header|Pike}}==
Uses GLUE to create the window. Rendering code is based on the C example.
<
GLUE.init(([
"fullscreen": 0,
Line 2,267 ⟶ 2,269:
sleep(0.01);
}
}</
=={{header|PureBasic}}==
Line 2,273 ⟶ 2,275:
<syntaxhighlight lang="purebasic">
XIncludeFile "OpenGL.pbi"
pfd.PIXELFORMATDESCRIPTOR
Line 2,316 ⟶ 2,318:
Wend
</syntaxhighlight>
=={{header|Python}}==
<
#-*- coding: utf-8 -*-
Line 2,360 ⟶ 2,362:
glutReshapeFunc(reshape)
glutMainLoop()</
=={{header|QB64}}==
<syntaxhighlight lang="qb64">
'Task
'Display a smooth shaded triangle with OpenGL.
Line 2,388 ⟶ 2,390:
_glEnd
End Sub
</syntaxhighlight>
=={{header|R}}==
{{libheader|rgl}}
<
x <- c(-1, -1, 1)
y <- c(0, -1, -1)
Line 2,397 ⟶ 2,399:
M <- cbind(x,y,z)
rgl.bg(color="gray15")
triangles3d(M, col=rainbow(8))</
=={{header|Racket}}==
Line 2,405 ⟶ 2,407:
If OpenGL context creation fails please consult Racket [http://docs.racket-lang.org/gui/libs.html documentation]
<
#lang racket/gui
(require sgl/gl)
Line 2,448 ⟶ 2,450:
(send win show #t)
</syntaxhighlight>
=={{header|Raku}}==
Line 2,457 ⟶ 2,459:
It's a little verbose since it is doing all of the setup and loading manually.
<syntaxhighlight lang="raku"
class Window is repr('CPointer') {}
Line 2,545 ⟶ 2,547:
glfwTerminate();
</syntaxhighlight>
See screen cap: [https://github.com/thundergnat/rc/blob/master/img/OpenGL-Triangle-perl6.png OpenGL-Triangle-perl6.png] (Offsite PNG image.)
Line 2,552 ⟶ 2,554:
=={{header|Ring}}==
<
# Project: OpenGL
Line 2,575 ⟶ 2,577:
glEnd()
glutSwapBuffers()
</syntaxhighlight>
Outputimage:
Line 2,583 ⟶ 2,585:
{{libheader|ruby-opengl}}
<
require 'gl'
require 'glut'
Line 2,626 ⟶ 2,628:
glutReshapeFunc(reshape)
glutMainLoop</
=={{header|Rust}}==
using glutin for window creation and glow for opengl/opengles functions. as such, the fixed function pipeline is not supported
<
use glutin::event::*;
use glutin::event_loop::{ControlFlow, EventLoop};
Line 2,739 ⟶ 2,741:
_ => {}
});
}</
=={{header|Scala}}==
{{libheader|Light Weight Java Game Library}}
<
import org.lwjgl.opengl.GL11._
Line 2,780 ⟶ 2,782:
Thread.sleep(1000)
}
}</
=={{header|Tcl}}==
{{libheader|Tk}}
{{libheader|tcl3d}}
<
package require tcl3d
Line 2,814 ⟶ 2,816:
togl .surface -width 640 -height 480 -double true -depth true \
-displayproc paintShape -reshapeproc resizedWin
pack .surface -fill both -expand 1</
=={{header|Wren}}==
Line 2,824 ⟶ 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.
<
var GL_COLOR_BUFFER_BIT = 0x4000
Line 2,909 ⟶ 2,911:
Glut.displayFunc("GLCallbacks", "paint()")
Glut.reshapeFunc("GLCallbacks", "reshape(_,_)")
Glut.setOption(GLUT_ACTION_ON_WINDOW_CLOSE, GLUT_ACTION_GLUTMAINLOOP_RETURNS)</
<br>
We now embed this Wren script in the following C program, compile and run it.
<
#include <stdio.h>
#include <string.h>
Line 3,121 ⟶ 3,123:
vm = wrenNewVM(&config);
const char* module = "main";
const char* fileName = "
char *script = readFile(fileName);
WrenInterpretResult result = wrenInterpret(vm, module, script);
Line 3,138 ⟶ 3,140:
free(script);
return 0;
}</
{{out}}
|