mirror of
https://github.com/brunoherbelin/vimix.git
synced 2025-12-11 18:34:58 +01:00
Implementation of stippling in GLSL image shader and use in Mixing
Source. Creation of Mxing circle texture.
This commit is contained in:
61
View.cpp
61
View.cpp
@@ -3,14 +3,20 @@
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/gtc/matrix_transform.hpp>
|
||||
|
||||
// memmove
|
||||
#include <string.h>
|
||||
|
||||
#include "defines.h"
|
||||
#include "View.h"
|
||||
#include "Source.h"
|
||||
#include "Primitives.h"
|
||||
#include "Resource.h"
|
||||
#include "Mesh.h"
|
||||
#include "FrameBuffer.h"
|
||||
#include "Log.h"
|
||||
|
||||
#define CIRCLE_PIXELS 64
|
||||
#define CIRCLE_PIXEL_RADIUS 1024.0
|
||||
|
||||
View::View()
|
||||
{
|
||||
@@ -24,8 +30,12 @@ void View::update(float dt)
|
||||
|
||||
MixingView::MixingView() : View()
|
||||
{
|
||||
// default settings
|
||||
scene.root()->scale_ = glm::vec3(1.4, 1.4, 1.0);
|
||||
|
||||
// Mixing scene
|
||||
Mesh *disk = new Mesh("mesh/disk.ply", "images/transparencygrid.png");
|
||||
Mesh *disk = new Mesh("mesh/disk.ply");
|
||||
disk->setTexture(textureMixingQuadratic());
|
||||
backgound_.addChild(disk);
|
||||
|
||||
glm::vec4 pink( 0.8f, 0.f, 0.8f, 1.f );
|
||||
@@ -104,6 +114,55 @@ void MixingView::grab (glm::vec2 from, glm::vec2 to, Source *s)
|
||||
|
||||
}
|
||||
|
||||
|
||||
uint MixingView::textureMixingQuadratic()
|
||||
{
|
||||
static GLuint texid = 0;
|
||||
if (texid == 0) {
|
||||
// generate the texture with alpha exactly as computed for sources
|
||||
glGenTextures(1, &texid);
|
||||
glBindTexture(GL_TEXTURE_2D, texid);
|
||||
GLubyte matrix[CIRCLE_PIXELS*CIRCLE_PIXELS * 4];
|
||||
GLubyte color[4] = {0,0,0,0};
|
||||
GLfloat luminance = 1.f;
|
||||
GLfloat alpha = 0.f;
|
||||
GLfloat distance = 0.f;
|
||||
int l = -CIRCLE_PIXELS / 2 + 1, c = 0;
|
||||
|
||||
for (int i = 0; i < CIRCLE_PIXELS / 2; ++i) {
|
||||
c = -CIRCLE_PIXELS / 2 + 1;
|
||||
for (int j=0; j < CIRCLE_PIXELS / 2; ++j) {
|
||||
// distance to the center
|
||||
distance = (GLfloat) ((c * c) + (l * l)) / CIRCLE_PIXEL_RADIUS;
|
||||
// luminance
|
||||
luminance = 255.f * CLAMP( 0.95f - 0.8f * distance, 0.f, 1.f);
|
||||
color[0] = color[1] = color[2] = static_cast<GLubyte>(luminance);
|
||||
// alpha
|
||||
alpha = 255.f * CLAMP( 1.f - distance , 0.f, 1.f);
|
||||
color[3] = static_cast<GLubyte>(alpha);
|
||||
|
||||
// 1st quadrant
|
||||
memmove(&matrix[ j * 4 + i * CIRCLE_PIXELS * 4 ], color, 4);
|
||||
// 4nd quadrant
|
||||
memmove(&matrix[ (CIRCLE_PIXELS -j -1)* 4 + i * CIRCLE_PIXELS * 4 ], color, 4);
|
||||
// 3rd quadrant
|
||||
memmove(&matrix[ j * 4 + (CIRCLE_PIXELS -i -1) * CIRCLE_PIXELS * 4 ], color, 4);
|
||||
// 4th quadrant
|
||||
memmove(&matrix[ (CIRCLE_PIXELS -j -1) * 4 + (CIRCLE_PIXELS -i -1) * CIRCLE_PIXELS * 4 ], color, 4);
|
||||
|
||||
++c;
|
||||
}
|
||||
++l;
|
||||
}
|
||||
// two components texture : luminance and alpha
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, CIRCLE_PIXELS, CIRCLE_PIXELS, 0, GL_RGBA, GL_UNSIGNED_BYTE, (float *) matrix);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
|
||||
}
|
||||
return texid;
|
||||
}
|
||||
|
||||
RenderView::RenderView() : View(), frame_buffer_(nullptr)
|
||||
{
|
||||
setResolution(1280, 720);
|
||||
|
||||
Reference in New Issue
Block a user