OpenGL pixel shader: Difference between revisions
m
→{{header|Wren}}: Minor tidy
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]]
<
#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}}
===(WebGL)===
<lang javascript><html style="margin: 0;">▼
<head>
<title>Fragment Shader WebGL Example</title>
Line 337 ⟶ 339:
</script>
</body>
</html></
=={{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.
<
import kotlinx.cinterop.*
Line 436 ⟶ 438:
setShader()
glutMainLoop()
}</
=={{header|Ol}}==
<
#!/usr/bin/ol
(import (lib gl2))
Line 477 ⟶ 479:
(glVertex2f -0.0 +0.7)
(glEnd)))
</syntaxhighlight>
=={{header|Phix}}==
Line 484 ⟶ 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 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>
<!--</
=={{header|Racket}}==
<
(require typed/opengl)
Line 690 ⟶ 692:
(define gl (new my-canvas% [parent win]))
(send win show #t)</
=={{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">
package require tcl3d
Line 761 ⟶ 763:
set_shader
render
</syntaxhighlight>
=={{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.
<
import "random" for Random
Line 903 ⟶ 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,155 ⟶ 1,157:
vm = wrenNewVM(&config);
const char* module = "main";
const char* fileName = "
char *script = readFile(fileName);
WrenInterpretResult result = wrenInterpret(vm, module, script);
Line 1,172 ⟶ 1,174:
free(script);
return 0;
}</
{{out}}
|