OpenGL pixel shader: Difference between revisions
m
syntax highlighting fixup automation
Thundergnat (talk | contribs) m (→{{header|JavaScript}} (WebGL): Library doesn't go in header) |
Thundergnat (talk | contribs) 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]]
<
#include <stdlib.h>
#include <GL/glew.h>
Line 86:
return 0;
}</
=={{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.
<
/*
Line 227:
setShader()
C.glutMainLoop()
}</
=={{header|JavaScript}}==
Line 233:
===(WebGL)===
<
<head>
<title>Fragment Shader WebGL Example</title>
Line 339:
</script>
</body>
</html></
=={{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.
<
import kotlinx.cinterop.*
Line 438:
setShader()
glutMainLoop()
}</
=={{header|Ol}}==
<
#!/usr/bin/ol
(import (lib gl2))
Line 479:
(glVertex2f -0.0 +0.7)
(glEnd)))
</syntaxhighlight>
=={{header|Phix}}==
Line 486:
{{libheader|Phix/online}}
You can run this online [http://phix.x10.mx/p2js/OpenGLShader.htm here].
<!--<
<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>
<!--</
=={{header|Racket}}==
<
(require typed/opengl)
Line 692:
(define gl (new my-canvas% [parent win]))
(send win show #t)</
=={{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">
package require tcl3d
Line 763:
set_shader
render
</syntaxhighlight>
=={{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.
<
import "random" for Random
Line 905:
}
setShader.call()
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 1,174:
free(script);
return 0;
}</
{{out}}
|