mirror of
https://github.com/edubart/otclient.git
synced 2025-11-30 15:26:49 +01:00
test shader effect
This commit is contained in:
@@ -22,3 +22,20 @@
|
||||
|
||||
#include "glbuffer.h"
|
||||
|
||||
GLBuffer::GLBuffer()
|
||||
{
|
||||
glGenBuffers(1, &m_id);
|
||||
if(!m_id)
|
||||
logFatal("Unable to create a simple GL buffer");
|
||||
}
|
||||
|
||||
void GLBuffer::bind()
|
||||
{
|
||||
gl
|
||||
}
|
||||
|
||||
void GLBuffer::release()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -23,8 +23,22 @@
|
||||
#ifndef GLBUFFER_H
|
||||
#define GLBUFFER_H
|
||||
|
||||
#include "declarations.h"
|
||||
|
||||
class GLBuffer
|
||||
{
|
||||
public:
|
||||
GLBuffer();
|
||||
~GLBuffer();
|
||||
|
||||
void write(const
|
||||
void bind();
|
||||
void release();
|
||||
|
||||
GLuint bufferId();
|
||||
|
||||
private:
|
||||
GLuint m_id;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -47,6 +47,7 @@ void Painter::init()
|
||||
program->bindUniformLocation(PainterShaderProgram::COLOR_UNIFORM, "color");
|
||||
program->bindUniformLocation(PainterShaderProgram::OPACITY_UNIFORM, "opacity");
|
||||
program->bindUniformLocation(PainterShaderProgram::TEXTURE_UNIFORM, "texture");
|
||||
program->bindUniformLocation(PainterShaderProgram::TICKS_UNIFORM, "ticks");
|
||||
m_drawTexturedProgram = program;
|
||||
|
||||
program = PainterShaderProgramPtr(new PainterShaderProgram);
|
||||
@@ -57,6 +58,7 @@ void Painter::init()
|
||||
program->bindUniformLocation(PainterShaderProgram::PROJECTION_MATRIX_UNIFORM, "projectionMatrix");
|
||||
program->bindUniformLocation(PainterShaderProgram::COLOR_UNIFORM, "color");
|
||||
program->bindUniformLocation(PainterShaderProgram::OPACITY_UNIFORM, "opacity");
|
||||
program->bindUniformLocation(PainterShaderProgram::TICKS_UNIFORM, "ticks");
|
||||
m_drawSolidColorProgram = program;
|
||||
}
|
||||
|
||||
|
||||
@@ -57,6 +57,8 @@ public:
|
||||
|
||||
void setCompositionMode(CompositionMode compositionMode);
|
||||
|
||||
GLfloat *getProjectionMatrix() { return (GLfloat*)m_projectionMatrix; }
|
||||
|
||||
private:
|
||||
PainterShaderProgramPtr m_drawTexturedProgram;
|
||||
PainterShaderProgramPtr m_drawSolidColorProgram;
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
#include "painter.h"
|
||||
#include "texture.h"
|
||||
#include "texturemanager.h"
|
||||
#include <framework/core/clock.h>
|
||||
|
||||
void PainterShaderProgram::setProjectionMatrix(float projectionMatrix[3][3])
|
||||
{
|
||||
@@ -76,6 +77,7 @@ void PainterShaderProgram::setTextureCoords(const GLfloat *textureCoords)
|
||||
void PainterShaderProgram::prepareForDraw()
|
||||
{
|
||||
assert(bind());
|
||||
setUniformValue(TICKS_UNIFORM, (GLfloat)g_clock.ticks());
|
||||
}
|
||||
|
||||
void PainterShaderProgram::drawTriangleStrip(int numVertices)
|
||||
|
||||
@@ -35,7 +35,8 @@ public:
|
||||
TEXTURE_TRANSFORM_MATRIX_UNIFORM = 1,
|
||||
COLOR_UNIFORM = 2,
|
||||
OPACITY_UNIFORM = 3,
|
||||
TEXTURE_UNIFORM = 4
|
||||
TEXTURE_UNIFORM = 4,
|
||||
TICKS_UNIFORM = 5
|
||||
};
|
||||
|
||||
void setProjectionMatrix(GLfloat projectionMatrix[3][3]);
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
*/
|
||||
|
||||
#include "shader.h"
|
||||
#include <framework/core/resourcemanager.h>
|
||||
|
||||
Shader::Shader(Shader::ShaderType shaderType)
|
||||
{
|
||||
@@ -70,8 +71,7 @@ bool Shader::compileSourceCode(const std::string& sourceCode)
|
||||
|
||||
bool Shader::compileSourceFile(const std::string& sourceFile)
|
||||
{
|
||||
std::ifstream fin(sourceFile);
|
||||
std::string sourceCode((std::istreambuf_iterator<char>(fin)), std::istreambuf_iterator<char>());
|
||||
std::string sourceCode = g_resources.loadFile(sourceFile);
|
||||
return compileSourceCode(sourceCode);
|
||||
}
|
||||
|
||||
|
||||
@@ -28,7 +28,9 @@
|
||||
#include "missile.h"
|
||||
#include <framework/graphics/graphics.h>
|
||||
#include <framework/graphics/framebuffer.h>
|
||||
|
||||
#include <framework/graphics/paintershaderprogram.h>
|
||||
#include <framework/graphics/paintershadersources.h>
|
||||
#include <framework/graphics/texture.h>
|
||||
Map g_map;
|
||||
|
||||
Map::Map()
|
||||
@@ -36,11 +38,27 @@ Map::Map()
|
||||
setVisibleSize(Size(MAP_VISIBLE_WIDTH, MAP_VISIBLE_HEIGHT));
|
||||
}
|
||||
|
||||
PainterShaderProgramPtr program;
|
||||
void Map::draw(const Rect& rect)
|
||||
{
|
||||
if(!m_framebuffer)
|
||||
if(!m_framebuffer) {
|
||||
m_framebuffer = FrameBufferPtr(new FrameBuffer(m_visibleSize.width() * NUM_TILE_PIXELS, m_visibleSize.height() * NUM_TILE_PIXELS));
|
||||
|
||||
|
||||
program = PainterShaderProgramPtr(new PainterShaderProgram);
|
||||
program->addShaderFromSourceCode(Shader::Vertex, glslMainWithTexCoordsVertexShader + glslPositionOnlyVertexShader);
|
||||
program->addShaderFromSourceFile(Shader::Fragment, "/shadertest.frag");
|
||||
program->bindAttributeLocation(VERTEX_COORDS_ATTR, "vertexCoord");
|
||||
program->bindAttributeLocation(TEXTURE_COORDS_ATTR, "textureCoord");
|
||||
assert(program->link());
|
||||
program->bindUniformLocation(PainterShaderProgram::PROJECTION_MATRIX_UNIFORM, "projectionMatrix");
|
||||
program->bindUniformLocation(PainterShaderProgram::TEXTURE_TRANSFORM_MATRIX_UNIFORM, "textureTransformMatrix");
|
||||
program->bindUniformLocation(PainterShaderProgram::COLOR_UNIFORM, "color");
|
||||
program->bindUniformLocation(PainterShaderProgram::OPACITY_UNIFORM, "opacity");
|
||||
program->bindUniformLocation(PainterShaderProgram::TEXTURE_UNIFORM, "texture");
|
||||
program->bindUniformLocation(PainterShaderProgram::TICKS_UNIFORM, "ticks");
|
||||
}
|
||||
|
||||
g_painter.setColor(Fw::white);
|
||||
m_framebuffer->bind();
|
||||
|
||||
@@ -82,8 +100,22 @@ void Map::draw(const Rect& rect)
|
||||
|
||||
m_framebuffer->release();
|
||||
|
||||
g_painter.setColor(Fw::white);
|
||||
m_framebuffer->draw(rect);
|
||||
//g_painter.setColor(Fw::white);
|
||||
//m_framebuffer->draw(rect);
|
||||
|
||||
|
||||
CoordsBuffer coordsBuffer;
|
||||
coordsBuffer.addRect(rect, Rect(0,0,m_framebuffer->getTexture()->getSize()));
|
||||
coordsBuffer.cacheVertexArrays();
|
||||
program->prepareForDraw();
|
||||
program->setProjectionMatrix((GLfloat (*)[3])g_painter.getProjectionMatrix());
|
||||
program->setOpacity(1.0f);
|
||||
program->setColor(Fw::white);
|
||||
program->setTexture(m_framebuffer->getTexture());
|
||||
program->setVertexCoords(coordsBuffer.getVertexCoords());
|
||||
program->setTextureCoords(coordsBuffer.getTextureCoords());
|
||||
program->drawTriangles(coordsBuffer.getVertexCount());
|
||||
program->releaseFromDraw();
|
||||
|
||||
// calculate stretch factor
|
||||
float horizontalStretchFactor = rect.width() / (float)(m_visibleSize.width() * NUM_TILE_PIXELS);
|
||||
|
||||
Reference in New Issue
Block a user