OpenGL pixel shader: Difference between revisions

m
m (→‎{{header|Phix}}: made p2js compatible, added online link)
m (→‎{{header|Wren}}: Minor tidy)
 
(2 intermediate revisions by one other user not shown)
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}} (WebGL) ==
 
===(WebGL)===
<lang javascript><html style="margin: 0;">
 
<langsyntaxhighlight lang="javascript"><html style="margin: 0;">
<head>
<title>Fragment Shader WebGL Example</title>
Line 337 ⟶ 339:
</script>
</body>
</html></langsyntaxhighlight>
 
=={{header|Kotlin}}==
Line 352 ⟶ 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 436 ⟶ 438:
setShader()
glutMainLoop()
}</langsyntaxhighlight>
 
=={{header|Ol}}==
<langsyntaxhighlight lang="scheme">
#!/usr/bin/ol
(import (lib gl2))
Line 477 ⟶ 479:
(glVertex2f -0.0 +0.7)
(glEnd)))
</syntaxhighlight>
</lang>
 
=={{header|Phix}}==
Line 484 ⟶ 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 611 ⟶ 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 690 ⟶ 692:
(define gl (new my-canvas% [parent win]))
(send win show #t)</langsyntaxhighlight>
 
=={{header|Tcl}}==
Line 698 ⟶ 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 761 ⟶ 763:
set_shader
render
</syntaxhighlight>
</lang>
 
=={{header|Wren}}==
Line 769 ⟶ 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 ecmascriptlang="wren">/* pixel_shaderOpenGL_pixel_shader.wren */
 
import "random" for Random
Line 903 ⟶ 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,155 ⟶ 1,157:
vm = wrenNewVM(&config);
const char* module = "main";
const char* fileName = "pixel_shaderOpenGL_pixel_shader.wren";
char *script = readFile(fileName);
WrenInterpretResult result = wrenInterpret(vm, module, script);
Line 1,172 ⟶ 1,174:
free(script);
return 0;
}</langsyntaxhighlight>
 
{{out}}
9,476

edits