OpenGL pixel shader: Difference between revisions

m
syntax highlighting fixup automation
m (→‎{{header|JavaScript}} (WebGL): Library doesn't go in header)
m (syntax highlighting fixup automation)
Line 11:
{{libheader|GLUT}}
Getting a true (pseudo) random number is surprisingly tricky. The following code makes something noisy, but not at all random:[[image:pixel_shader_C.png|right]]
<langsyntaxhighlight lang="c">#include <stdio.h>
#include <stdlib.h>
#include <GL/glew.h>
Line 86:
 
return 0;
}</langsyntaxhighlight>
 
=={{header|Go}}==
Line 94:
<br>
The following uses 'cgo' to bind to the above C libraries. As C macro functions cannot be invoked directly from Go code, it has been necessary to wrap them first in 'normal' C functions and then invoke those.
<langsyntaxhighlight lang="go">package main
 
/*
Line 227:
setShader()
C.glutMainLoop()
}</langsyntaxhighlight>
 
=={{header|JavaScript}}==
Line 233:
===(WebGL)===
 
<langsyntaxhighlight lang="javascript"><html style="margin: 0;">
<head>
<title>Fragment Shader WebGL Example</title>
Line 339:
</script>
</body>
</html></langsyntaxhighlight>
 
=={{header|Kotlin}}==
Line 354:
</pre>
You then need to compile the following Kotlin program, linking against opengl2.klib, and run the resulting .kexe file to view the rotating triangle.
<langsyntaxhighlight lang="scala">// Kotlin Native v0.6
 
import kotlinx.cinterop.*
Line 438:
setShader()
glutMainLoop()
}</langsyntaxhighlight>
 
=={{header|Ol}}==
<langsyntaxhighlight lang="scheme">
#!/usr/bin/ol
(import (lib gl2))
Line 479:
(glVertex2f -0.0 +0.7)
(glEnd)))
</syntaxhighlight>
</lang>
 
=={{header|Phix}}==
Line 486:
{{libheader|Phix/online}}
You can run this online [http://phix.x10.mx/p2js/OpenGLShader.htm here].
<!--<langsyntaxhighlight Phixlang="phix">(phixonline)-->
<span style="color: #000080;font-style:italic;">--
-- demo\rosetta\OpenGLShader.exw
Line 613:
<span style="color: #008080;">end</span> <span style="color: #008080;">procedure</span>
<span style="color: #000000;">main</span><span style="color: #0000FF;">()</span>
<!--</langsyntaxhighlight>-->
 
=={{header|Racket}}==
<langsyntaxhighlight lang="racket">#lang racket/gui
(require typed/opengl)
Line 692:
(define gl (new my-canvas% [parent win]))
(send win show #t)</langsyntaxhighlight>
 
=={{header|Tcl}}==
Line 700:
Using the [http://www.tcl3d.org Tcl3d] library and liberally borrowing from [http://wiki.tcl.tk/41477 this pixel shader demo on the wiki], here is a brute translation of the C implementation.
 
<syntaxhighlight lang="tcl">
<lang Tcl>
package require tcl3d
 
Line 763:
set_shader
render
</syntaxhighlight>
</lang>
 
=={{header|Wren}}==
Line 771:
<br>
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 lang="ecmascript">/* pixel_shader.wren */
 
import "random" for Random
Line 905:
}
setShader.call()
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 1,174:
free(script);
return 0;
}</langsyntaxhighlight>
 
{{out}}
10,333

edits