mirror of
https://github.com/libretro/cpp-cheat.git
synced 2025-04-12 08:14:07 +00:00
OpenGL naughty shaders
This commit is contained in:
parent
233df774cf
commit
e99d65dfb7
@ -29,12 +29,16 @@
|
||||
1. [glutBitmapCharacter](bitmap_character.c)
|
||||
1. [Animation](animation.c)
|
||||
1. GLFW
|
||||
1. [hello world](glfw_hello_world.c)
|
||||
1. [triangle](glfw_triangle.c)
|
||||
1. [triangles](glfw_triangles.c)
|
||||
1. [shader](glfw_shader.c)
|
||||
1. [transform](glfw_transform.c)
|
||||
1. [animation](glfw_animation.c)
|
||||
1. [hello world](glfw_hello_world.c)
|
||||
1. [animation](glfw_animation.c)
|
||||
1. Retained mode + shaders
|
||||
1. [triangle](glfw_triangle.c)
|
||||
1. [color](glfw_color.c)
|
||||
1. [triangles](glfw_triangles.c)
|
||||
1. [transform](glfw_transform.c)
|
||||
1. Naughty
|
||||
1. [Infinite loop shader](glfw_infinite_loop_shader.c.off)
|
||||
1. [Memory overflow shader](glfw_memory_overflow_shader.c.off)
|
||||
1. [GLX](glx.c)
|
||||
1. Performance
|
||||
1. [Many triangles](many_triangles.c)
|
||||
|
@ -45,6 +45,7 @@
|
||||
- https://en.wikipedia.org/wiki/Stencil_buffer
|
||||
- http://www.learnopengl.com/#!Advanced-OpenGL/Stencil-testing
|
||||
- shading, glsl
|
||||
- what is the basis for GLSL implementations? GCC, clang, others?
|
||||
- pipeline https://www.opengl.org/wiki/Rendering_Pipeline_Overview , great diagram
|
||||
- rasterization: determines which pixels are covered by a triangle
|
||||
- name is wrong nowadays: shaders can do more things than just shading, including positioning vertexes (e.g. for tesselation) and arbitrary computaiton!
|
||||
@ -71,6 +72,10 @@
|
||||
- `in`, `out`: http://gamedev.stackexchange.com/questions/29672/in-out-keywords-in-glsl
|
||||
- https://www.opengl.org/wiki/Shader
|
||||
- there are many types of shaders besides vertex and fragment
|
||||
- get output out of glsl
|
||||
- http://stackoverflow.com/questions/2508818/how-to-debug-a-glsl-shader
|
||||
- http://stackoverflow.com/questions/14086926/get-results-of-gpu-calculations-back-to-the-cpu-program-in-opengl
|
||||
- http://stackoverflow.com/questions/19123239/is-it-possible-to-read-data-from-vertex-shader
|
||||
- motion blur:
|
||||
- http://john-chapman-graphics.blogspot.fr/2013/01/what-is-motion-blur-motion-pictures-are.html
|
||||
|
||||
|
82
opengl/glfw_infinite_loop_shader.c.off
Normal file
82
opengl/glfw_infinite_loop_shader.c.off
Normal file
@ -0,0 +1,82 @@
|
||||
/*
|
||||
Just for fun.
|
||||
|
||||
Blocked my Ubuntu 15.10 with OpenGL 4.5.0 NVIDIA 352.63,
|
||||
but I was able to regain control with after a lot of Alt+F4 nd Ctrl+C
|
||||
TODO why does it block everything, if it's only in the GPU?
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#define GLEW_STATIC
|
||||
#include <GL/glew.h>
|
||||
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
#include "common.h"
|
||||
|
||||
static const GLuint WIDTH = 800;
|
||||
static const GLuint HEIGHT = 600;
|
||||
static const GLchar* vertex_shader_source =
|
||||
"#version 330 core\n"
|
||||
"layout (location = 0) in vec3 position;\n"
|
||||
"void main() {\n"
|
||||
" while(true);\n"
|
||||
" gl_Position = vec4(position, 1.0);\n"
|
||||
"}\n";
|
||||
static const GLchar* fragment_shader_source =
|
||||
"#version 330 core\n"
|
||||
"out vec4 color;\n"
|
||||
"void main() {\n"
|
||||
" color = vec4(1.0f, 0.0f, 0.0f, 1.0f);\n"
|
||||
"}\n";
|
||||
/* Passed as input to the vertex shader. */
|
||||
static const GLfloat vertices[] = {
|
||||
0.0f, 0.5f, 0.0f,
|
||||
0.5f, -0.5f, 0.0f,
|
||||
-0.5f, -0.5f, 0.0f,
|
||||
};
|
||||
|
||||
int main(void) {
|
||||
GLint shader_program;
|
||||
|
||||
glfwInit();
|
||||
GLFWwindow* window = glfwCreateWindow(WIDTH, HEIGHT, __FILE__, NULL, NULL);
|
||||
glfwMakeContextCurrent(window);
|
||||
glewExperimental = GL_TRUE;
|
||||
glewInit();
|
||||
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
|
||||
glViewport(0, 0, WIDTH, HEIGHT);
|
||||
|
||||
shader_program = common_get_shader_program(vertex_shader_source, fragment_shader_source);
|
||||
|
||||
GLuint vbo, vao;
|
||||
glGenVertexArrays(1, &vao);
|
||||
glGenBuffers(1, &vbo);
|
||||
glBindVertexArray(vao);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, vbo);
|
||||
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
|
||||
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, (GLvoid*)0);
|
||||
glEnableVertexAttribArray(0);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
glBindVertexArray(0);
|
||||
|
||||
while (!glfwWindowShouldClose(window)) {
|
||||
glfwPollEvents();
|
||||
|
||||
/* Render */
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
glUseProgram(shader_program);
|
||||
glBindVertexArray(vao);
|
||||
glDrawArrays(GL_TRIANGLES, 0, 3);
|
||||
/*glDrawElements(GL_TRIANGLES, 3, GL_UNSIGNED_INT, 0);*/
|
||||
glBindVertexArray(0);
|
||||
|
||||
glfwSwapBuffers(window);
|
||||
}
|
||||
glDeleteVertexArrays(1, &vao);
|
||||
glDeleteBuffers(1, &vbo);
|
||||
glfwTerminate();
|
||||
return EXIT_SUCCESS;
|
||||
}
|
77
opengl/glfw_memory_overflow_shader.c.off
Normal file
77
opengl/glfw_memory_overflow_shader.c.off
Normal file
@ -0,0 +1,77 @@
|
||||
/*
|
||||
Similar effect infinite loop shader :-)
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#define GLEW_STATIC
|
||||
#include <GL/glew.h>
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
#include "common.h"
|
||||
|
||||
static const GLuint WIDTH = 800;
|
||||
static const GLuint HEIGHT = 600;
|
||||
static const GLchar* vertex_shader_source =
|
||||
"#version 330 core\n"
|
||||
"layout (location = 0) in vec3 position;\n"
|
||||
"void main() {\n"
|
||||
" float is[10000000000L];\n"
|
||||
" gl_Position = vec4(position, is[9999999999L]);\n"
|
||||
"}\n";
|
||||
static const GLchar* fragment_shader_source =
|
||||
"#version 330 core\n"
|
||||
"out vec4 color;\n"
|
||||
"void main() {\n"
|
||||
" color = vec4(1.0f, 0.0f, 0.0f, 1.0f);\n"
|
||||
"}\n";
|
||||
/* Passed as input to the vertex shader. */
|
||||
static const GLfloat vertices[] = {
|
||||
0.0f, 0.5f, 0.0f,
|
||||
0.5f, -0.5f, 0.0f,
|
||||
-0.5f, -0.5f, 0.0f,
|
||||
};
|
||||
|
||||
int main(void) {
|
||||
GLint shader_program;
|
||||
|
||||
glfwInit();
|
||||
GLFWwindow* window = glfwCreateWindow(WIDTH, HEIGHT, __FILE__, NULL, NULL);
|
||||
glfwMakeContextCurrent(window);
|
||||
glewExperimental = GL_TRUE;
|
||||
glewInit();
|
||||
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
|
||||
glViewport(0, 0, WIDTH, HEIGHT);
|
||||
|
||||
shader_program = common_get_shader_program(vertex_shader_source, fragment_shader_source);
|
||||
|
||||
GLuint vbo, vao;
|
||||
glGenVertexArrays(1, &vao);
|
||||
glGenBuffers(1, &vbo);
|
||||
glBindVertexArray(vao);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, vbo);
|
||||
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
|
||||
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, (GLvoid*)0);
|
||||
glEnableVertexAttribArray(0);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
glBindVertexArray(0);
|
||||
|
||||
while (!glfwWindowShouldClose(window)) {
|
||||
glfwPollEvents();
|
||||
|
||||
/* Render */
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
glUseProgram(shader_program);
|
||||
glBindVertexArray(vao);
|
||||
glDrawArrays(GL_TRIANGLES, 0, 3);
|
||||
/*glDrawElements(GL_TRIANGLES, 3, GL_UNSIGNED_INT, 0);*/
|
||||
glBindVertexArray(0);
|
||||
|
||||
glfwSwapBuffers(window);
|
||||
}
|
||||
glDeleteVertexArrays(1, &vao);
|
||||
glDeleteBuffers(1, &vbo);
|
||||
glfwTerminate();
|
||||
return EXIT_SUCCESS;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user