PLAYGROUND3D: Added bitmap test
This commit is contained in:
parent
722d0a83b9
commit
ed837d20a8
13 changed files with 576 additions and 5 deletions
|
@ -186,6 +186,8 @@ shaders/wme_sprite.fragment FILE "engines/wintermute/base/gfx/ope
|
|||
shaders/wme_sprite.vertex FILE "engines/wintermute/base/gfx/opengl/shaders/wme_sprite.vertex"
|
||||
#endif
|
||||
#if PLUGIN_ENABLED_STATIC(PLAYGROUND3D)
|
||||
shaders/playground3d_bitmap.fragment FILE "engines/playground3d/shaders/playground3d_bitmap.fragment"
|
||||
shaders/playground3d_bitmap.vertex FILE "engines/playground3d/shaders/playground3d_bitmap.vertex"
|
||||
shaders/playground3d_cube.fragment FILE "engines/playground3d/shaders/playground3d_cube.fragment"
|
||||
shaders/playground3d_cube.vertex FILE "engines/playground3d/shaders/playground3d_cube.vertex"
|
||||
shaders/playground3d_fade.fragment FILE "engines/playground3d/shaders/playground3d_fade.fragment"
|
||||
|
|
|
@ -96,7 +96,6 @@ void Renderer::computeScreenViewport() {
|
|||
|
||||
Math::Matrix4 Renderer::makeProjectionMatrix(float fov, float nearClip, float farClip) const {
|
||||
float aspectRatio = kOriginalWidth / (float) kOriginalHeight;
|
||||
|
||||
float xmaxValue = nearClip * tanf(fov * M_PI / 360.0f);
|
||||
float ymaxValue = xmaxValue / aspectRatio;
|
||||
return Math::makeFrustumMatrix(-xmaxValue, xmaxValue, -ymaxValue, ymaxValue, nearClip, farClip);
|
||||
|
@ -109,7 +108,6 @@ void Renderer::setupCameraPerspective(float pitch, float heading, float fov) {
|
|||
Math::Matrix4 model = _modelViewMatrix;
|
||||
proj.transpose();
|
||||
model.transpose();
|
||||
|
||||
_mvpMatrix = proj * model;
|
||||
_mvpMatrix.transpose();
|
||||
}
|
||||
|
|
|
@ -30,6 +30,9 @@
|
|||
#include "math/matrix4.h"
|
||||
#include "math/vector3d.h"
|
||||
|
||||
#include "graphics/surface.h"
|
||||
#include "graphics/pixelformat.h"
|
||||
|
||||
namespace Playground3d {
|
||||
|
||||
class Renderer {
|
||||
|
@ -38,6 +41,7 @@ public:
|
|||
virtual ~Renderer();
|
||||
|
||||
virtual void init() = 0;
|
||||
virtual void deinit() = 0;
|
||||
virtual void clear(const Math::Vector4d &clearColor) = 0;
|
||||
|
||||
/**
|
||||
|
@ -55,10 +59,13 @@ public:
|
|||
void computeScreenViewport();
|
||||
|
||||
virtual void setupViewport(int x, int y, int width, int height) = 0;
|
||||
virtual void loadTextureRGBA(Graphics::Surface *texture) = 0;
|
||||
virtual void loadTextureRGB(Graphics::Surface *texture) = 0;
|
||||
virtual void drawCube(const Math::Vector3d &pos, const Math::Vector3d &roll) = 0;
|
||||
virtual void drawPolyOffsetTest(const Math::Vector3d &pos, const Math::Vector3d &roll) = 0;
|
||||
virtual void dimRegionInOut(float fade) = 0;
|
||||
virtual void drawInViewport() = 0;
|
||||
virtual void drawRgbaTexture() = 0;
|
||||
|
||||
protected:
|
||||
OSystem *_system;
|
||||
|
@ -70,6 +77,7 @@ protected:
|
|||
Math::Matrix4 _mvpMatrix;
|
||||
|
||||
static const float cubeVertices[11 * 6 * 4];
|
||||
Graphics::Surface *_texture;
|
||||
|
||||
Math::Matrix4 makeProjectionMatrix(float fov, float nearClip, float farClip) const;
|
||||
};
|
||||
|
|
|
@ -49,6 +49,22 @@ static const GLfloat boxVertices[] = {
|
|||
1.0f, -1.0f,
|
||||
};
|
||||
|
||||
static const GLfloat bitmapVertices[] = {
|
||||
// X Y
|
||||
-0.2f, 0.2f,
|
||||
0.2f, 0.2f,
|
||||
-0.2f, -0.2f,
|
||||
0.2f, -0.2f,
|
||||
};
|
||||
|
||||
static const GLfloat textCords[] = {
|
||||
// S T
|
||||
0.0f, 0.0f,
|
||||
1.0f, 0.0f,
|
||||
0.0f, 1.0f,
|
||||
1.0f, 1.0f,
|
||||
};
|
||||
|
||||
Renderer *CreateGfxOpenGL(OSystem *system) {
|
||||
return new OpenGLRenderer(system);
|
||||
}
|
||||
|
@ -79,6 +95,14 @@ void OpenGLRenderer::init() {
|
|||
glDisable(GL_TEXTURE_2D);
|
||||
glDisable(GL_LIGHTING);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
|
||||
glGenTextures(10, _textureRgbaId);
|
||||
glGenTextures(10, _textureRgbId);
|
||||
}
|
||||
|
||||
void OpenGLRenderer::deinit() {
|
||||
glDeleteTextures(10, _textureRgbaId);
|
||||
glDeleteTextures(10, _textureRgbId);
|
||||
}
|
||||
|
||||
void OpenGLRenderer::clear(const Math::Vector4d &clearColor) {
|
||||
|
@ -86,6 +110,44 @@ void OpenGLRenderer::clear(const Math::Vector4d &clearColor) {
|
|||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
}
|
||||
|
||||
void OpenGLRenderer::loadTextureRGBA(Graphics::Surface *texture) {
|
||||
glBindTexture(GL_TEXTURE_2D, _textureRgbaId[0]);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texture->w, texture->h, 0, GL_RGBA, GL_UNSIGNED_BYTE, texture->getPixels());
|
||||
glBindTexture(GL_TEXTURE_2D, _textureRgbaId[1]);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texture->w, texture->h, 0, GL_BGRA, GL_UNSIGNED_BYTE, texture->getPixels());
|
||||
glBindTexture(GL_TEXTURE_2D, _textureRgbaId[2]);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texture->w, texture->h, 0, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8, texture->getPixels());
|
||||
glBindTexture(GL_TEXTURE_2D, _textureRgbaId[3]);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texture->w, texture->h, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8, texture->getPixels());
|
||||
glBindTexture(GL_TEXTURE_2D, _textureRgbaId[4]);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texture->w, texture->h, 0, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV, texture->getPixels());
|
||||
glBindTexture(GL_TEXTURE_2D, _textureRgbaId[5]);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texture->w, texture->h, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, texture->getPixels());
|
||||
}
|
||||
|
||||
void OpenGLRenderer::loadTextureRGB(Graphics::Surface *texture) {
|
||||
glBindTexture(GL_TEXTURE_2D, _textureRgbId[0]);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texture->w, texture->h, 0, GL_RGB, GL_UNSIGNED_BYTE, texture->getPixels());
|
||||
glBindTexture(GL_TEXTURE_2D, _textureRgbId[1]);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texture->w, texture->h, 0, GL_BGR, GL_UNSIGNED_BYTE, texture->getPixels());
|
||||
}
|
||||
|
||||
void OpenGLRenderer::setupViewport(int x, int y, int width, int height) {
|
||||
glViewport(x, y, width, height);
|
||||
}
|
||||
|
@ -225,6 +287,118 @@ void OpenGLRenderer::drawInViewport() {
|
|||
glPopMatrix();
|
||||
}
|
||||
|
||||
void OpenGLRenderer::drawRgbaTexture() {
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glPushMatrix();
|
||||
glLoadIdentity();
|
||||
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glPushMatrix();
|
||||
glLoadIdentity();
|
||||
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
glDepthMask(GL_FALSE);
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
|
||||
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
|
||||
glTranslatef(-0.8, 0.8, 0);
|
||||
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
glVertexPointer(2, GL_FLOAT, 2 * sizeof(GLfloat), bitmapVertices);
|
||||
glTexCoordPointer(2, GL_FLOAT, 2 * sizeof(GLfloat), textCords);
|
||||
glBindTexture(GL_TEXTURE_2D, _textureRgbaId[0]);
|
||||
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
||||
glDisableClientState(GL_VERTEX_ARRAY);
|
||||
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
|
||||
glTranslatef(0.5, 0, 0);
|
||||
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
glVertexPointer(2, GL_FLOAT, 2 * sizeof(GLfloat), bitmapVertices);
|
||||
glTexCoordPointer(2, GL_FLOAT, 2 * sizeof(GLfloat), textCords);
|
||||
glBindTexture(GL_TEXTURE_2D, _textureRgbaId[1]);
|
||||
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
||||
glDisableClientState(GL_VERTEX_ARRAY);
|
||||
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
|
||||
glTranslatef(0.5, 0, 0);
|
||||
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
glVertexPointer(2, GL_FLOAT, 2 * sizeof(GLfloat), bitmapVertices);
|
||||
glTexCoordPointer(2, GL_FLOAT, 2 * sizeof(GLfloat), textCords);
|
||||
glBindTexture(GL_TEXTURE_2D, _textureRgbaId[2]);
|
||||
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
||||
glDisableClientState(GL_VERTEX_ARRAY);
|
||||
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
|
||||
glTranslatef(0.5, 0, 0);
|
||||
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
glVertexPointer(2, GL_FLOAT, 2 * sizeof(GLfloat), bitmapVertices);
|
||||
glTexCoordPointer(2, GL_FLOAT, 2 * sizeof(GLfloat), textCords);
|
||||
glBindTexture(GL_TEXTURE_2D, _textureRgbaId[3]);
|
||||
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
||||
glDisableClientState(GL_VERTEX_ARRAY);
|
||||
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
|
||||
glTranslatef(-1.5, -0.5, 0);
|
||||
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
glVertexPointer(2, GL_FLOAT, 2 * sizeof(GLfloat), bitmapVertices);
|
||||
glTexCoordPointer(2, GL_FLOAT, 2 * sizeof(GLfloat), textCords);
|
||||
glBindTexture(GL_TEXTURE_2D, _textureRgbaId[4]);
|
||||
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
||||
glDisableClientState(GL_VERTEX_ARRAY);
|
||||
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
|
||||
glTranslatef(0.5, 0, 0);
|
||||
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
glVertexPointer(2, GL_FLOAT, 2 * sizeof(GLfloat), bitmapVertices);
|
||||
glTexCoordPointer(2, GL_FLOAT, 2 * sizeof(GLfloat), textCords);
|
||||
glBindTexture(GL_TEXTURE_2D, _textureRgbaId[5]);
|
||||
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
||||
glDisableClientState(GL_VERTEX_ARRAY);
|
||||
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
|
||||
glTranslatef(0.5, 0, 0);
|
||||
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
glVertexPointer(2, GL_FLOAT, 2 * sizeof(GLfloat), bitmapVertices);
|
||||
glTexCoordPointer(2, GL_FLOAT, 2 * sizeof(GLfloat), textCords);
|
||||
glBindTexture(GL_TEXTURE_2D, _textureRgbId[0]);
|
||||
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
||||
glDisableClientState(GL_VERTEX_ARRAY);
|
||||
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
|
||||
glTranslatef(0.5, 0, 0);
|
||||
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
glVertexPointer(2, GL_FLOAT, 2 * sizeof(GLfloat), bitmapVertices);
|
||||
glTexCoordPointer(2, GL_FLOAT, 2 * sizeof(GLfloat), textCords);
|
||||
glBindTexture(GL_TEXTURE_2D, _textureRgbId[1]);
|
||||
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
||||
glDisableClientState(GL_VERTEX_ARRAY);
|
||||
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glPopMatrix();
|
||||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
} // End of namespace Playground3d
|
||||
|
||||
#endif
|
||||
|
|
|
@ -40,17 +40,23 @@ public:
|
|||
virtual ~OpenGLRenderer();
|
||||
|
||||
void init() override;
|
||||
void deinit() override;
|
||||
|
||||
void clear(const Math::Vector4d &clearColor) override;
|
||||
void loadTextureRGBA(Graphics::Surface *texture) override;
|
||||
void loadTextureRGB(Graphics::Surface *texture) override;
|
||||
|
||||
void setupViewport(int x, int y, int width, int height) override;
|
||||
void drawCube(const Math::Vector3d &pos, const Math::Vector3d &roll) override;
|
||||
void drawPolyOffsetTest(const Math::Vector3d &pos, const Math::Vector3d &roll) override;
|
||||
void dimRegionInOut(float fade) override;
|
||||
void drawInViewport() override;
|
||||
void drawRgbaTexture() override;
|
||||
|
||||
private:
|
||||
Math::Vector3d _pos;
|
||||
GLuint _textureRgbaId[10];
|
||||
GLuint _textureRgbId[10];
|
||||
|
||||
void drawFace(uint face);
|
||||
};
|
||||
|
|
|
@ -47,6 +47,14 @@ static const GLfloat dimRegionVertices[] = {
|
|||
0.5f, -0.5f,
|
||||
};
|
||||
|
||||
static const GLfloat bitmapVertices[] = {
|
||||
// X Y S T
|
||||
-0.2f, 0.2f, 0.0f, 0.0f,
|
||||
0.2f, 0.2f, 1.0f, 0.0f,
|
||||
-0.2f, -0.2f, 0.0f, 1.0f,
|
||||
0.2f, -0.2f, 1.0f, 1.0f,
|
||||
};
|
||||
|
||||
Renderer *CreateGfxOpenGLShader(OSystem *system) {
|
||||
return new ShaderRenderer(system);
|
||||
}
|
||||
|
@ -57,15 +65,18 @@ ShaderRenderer::ShaderRenderer(OSystem *system) :
|
|||
_cubeShader(nullptr),
|
||||
_fadeShader(nullptr),
|
||||
_cubeVBO(0),
|
||||
_fadeVBO(0) {
|
||||
_fadeVBO(0),
|
||||
_bitmapVBO(0) {
|
||||
}
|
||||
|
||||
ShaderRenderer::~ShaderRenderer() {
|
||||
OpenGL::ShaderGL::freeBuffer(_cubeVBO);
|
||||
OpenGL::ShaderGL::freeBuffer(_fadeVBO);
|
||||
OpenGL::ShaderGL::freeBuffer(_bitmapVBO);
|
||||
|
||||
delete _cubeShader;
|
||||
delete _fadeShader;
|
||||
delete _bitmapShader;
|
||||
}
|
||||
|
||||
void ShaderRenderer::init() {
|
||||
|
@ -83,10 +94,24 @@ void ShaderRenderer::init() {
|
|||
_cubeShader->enableVertexAttribute("normal", _cubeVBO, 3, GL_FLOAT, GL_FALSE, 11 * sizeof(float), 20);
|
||||
_cubeShader->enableVertexAttribute("color", _cubeVBO, 3, GL_FLOAT, GL_FALSE, 11 * sizeof(float), 32);
|
||||
|
||||
static const char* fadeAttributes[] = { "position", nullptr };
|
||||
static const char *fadeAttributes[] = { "position", nullptr };
|
||||
_fadeShader = OpenGL::ShaderGL::fromFiles("playground3d_fade", fadeAttributes);
|
||||
_fadeVBO = OpenGL::ShaderGL::createBuffer(GL_ARRAY_BUFFER, sizeof(dimRegionVertices), dimRegionVertices);
|
||||
_fadeShader->enableVertexAttribute("position", _fadeVBO, 2, GL_FLOAT, GL_TRUE, 2 * sizeof(float), 0);
|
||||
|
||||
static const char *bitmapAttributes[] = { "position", "texcoord", nullptr };
|
||||
_bitmapShader = OpenGL::ShaderGL::fromFiles("playground3d_bitmap", bitmapAttributes);
|
||||
_bitmapVBO = OpenGL::ShaderGL::createBuffer(GL_ARRAY_BUFFER, sizeof(bitmapVertices), bitmapVertices);
|
||||
_bitmapShader->enableVertexAttribute("position", _bitmapVBO, 2, GL_FLOAT, GL_TRUE, 4 * sizeof(float), 0);
|
||||
_bitmapShader->enableVertexAttribute("texcoord", _bitmapVBO, 2, GL_FLOAT, GL_TRUE, 4 * sizeof(float), 8);
|
||||
|
||||
glGenTextures(10, _textureRgbaId);
|
||||
glGenTextures(10, _textureRgbId);
|
||||
}
|
||||
|
||||
void ShaderRenderer::deinit() {
|
||||
glDeleteTextures(10, _textureRgbaId);
|
||||
glDeleteTextures(10, _textureRgbId);
|
||||
}
|
||||
|
||||
void ShaderRenderer::clear(const Math::Vector4d &clearColor) {
|
||||
|
@ -94,6 +119,44 @@ void ShaderRenderer::clear(const Math::Vector4d &clearColor) {
|
|||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
}
|
||||
|
||||
void ShaderRenderer::loadTextureRGBA(Graphics::Surface *texture) {
|
||||
glBindTexture(GL_TEXTURE_2D, _textureRgbaId[0]);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texture->w, texture->h, 0, GL_RGBA, GL_UNSIGNED_BYTE, texture->getPixels());
|
||||
glBindTexture(GL_TEXTURE_2D, _textureRgbaId[1]);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texture->w, texture->h, 0, GL_BGRA, GL_UNSIGNED_BYTE, texture->getPixels());
|
||||
glBindTexture(GL_TEXTURE_2D, _textureRgbaId[2]);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texture->w, texture->h, 0, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8, texture->getPixels());
|
||||
glBindTexture(GL_TEXTURE_2D, _textureRgbaId[3]);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texture->w, texture->h, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8, texture->getPixels());
|
||||
glBindTexture(GL_TEXTURE_2D, _textureRgbaId[4]);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texture->w, texture->h, 0, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV, texture->getPixels());
|
||||
glBindTexture(GL_TEXTURE_2D, _textureRgbaId[5]);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texture->w, texture->h, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, texture->getPixels());
|
||||
}
|
||||
|
||||
void ShaderRenderer::loadTextureRGB(Graphics::Surface *texture) {
|
||||
glBindTexture(GL_TEXTURE_2D, _textureRgbId[0]);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texture->w, texture->h, 0, GL_RGB, GL_UNSIGNED_BYTE, texture->getPixels());
|
||||
glBindTexture(GL_TEXTURE_2D, _textureRgbId[1]);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texture->w, texture->h, 0, GL_BGR, GL_UNSIGNED_BYTE, texture->getPixels());
|
||||
}
|
||||
|
||||
void ShaderRenderer::setupViewport(int x, int y, int width, int height) {
|
||||
glViewport(x, y, width, height);
|
||||
}
|
||||
|
@ -131,7 +194,67 @@ void ShaderRenderer::dimRegionInOut(float fade) {
|
|||
}
|
||||
|
||||
void ShaderRenderer::drawInViewport() {
|
||||
// TODO
|
||||
error("Draw in viewport test not implemented yet");
|
||||
}
|
||||
|
||||
void ShaderRenderer::drawRgbaTexture() {
|
||||
Math::Vector2d offset;
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
glDepthMask(GL_FALSE);
|
||||
|
||||
_bitmapShader->use();
|
||||
|
||||
offset.setX(-0.8);
|
||||
offset.setY(0.8);
|
||||
_bitmapShader->setUniform("offsetXY", offset);
|
||||
glBindTexture(GL_TEXTURE_2D, _textureRgbaId[0]);
|
||||
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
||||
|
||||
offset.setX(-0.3);
|
||||
offset.setY(0.8);
|
||||
_bitmapShader->setUniform("offsetXY", offset);
|
||||
glBindTexture(GL_TEXTURE_2D, _textureRgbaId[1]);
|
||||
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
||||
|
||||
offset.setX(0.2);
|
||||
offset.setY(0.8);
|
||||
_bitmapShader->setUniform("offsetXY", offset);
|
||||
glBindTexture(GL_TEXTURE_2D, _textureRgbaId[2]);
|
||||
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
||||
|
||||
offset.setX(0.7);
|
||||
offset.setY(0.8);
|
||||
_bitmapShader->setUniform("offsetXY", offset);
|
||||
glBindTexture(GL_TEXTURE_2D, _textureRgbaId[3]);
|
||||
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
||||
|
||||
offset.setX(-0.8);
|
||||
offset.setY(0.3);
|
||||
_bitmapShader->setUniform("offsetXY", offset);
|
||||
glBindTexture(GL_TEXTURE_2D, _textureRgbaId[4]);
|
||||
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
||||
|
||||
offset.setX(-0.3);
|
||||
offset.setY(0.3);
|
||||
_bitmapShader->setUniform("offsetXY", offset);
|
||||
glBindTexture(GL_TEXTURE_2D, _textureRgbaId[5]);
|
||||
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
||||
|
||||
offset.setX(0.2);
|
||||
offset.setY(0.3);
|
||||
_bitmapShader->setUniform("offsetXY", offset);
|
||||
glBindTexture(GL_TEXTURE_2D, _textureRgbId[0]);
|
||||
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
||||
|
||||
offset.setX(0.7);
|
||||
offset.setY(0.3);
|
||||
_bitmapShader->setUniform("offsetXY", offset);
|
||||
glBindTexture(GL_TEXTURE_2D, _textureRgbId[1]);
|
||||
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
||||
|
||||
_bitmapShader->unbind();
|
||||
}
|
||||
|
||||
} // End of namespace Playground3d
|
||||
|
|
|
@ -40,23 +40,31 @@ public:
|
|||
virtual ~ShaderRenderer();
|
||||
|
||||
void init() override;
|
||||
void deinit() override;
|
||||
|
||||
void clear(const Math::Vector4d &clearColor) override;
|
||||
void loadTextureRGBA(Graphics::Surface *texture) override;
|
||||
void loadTextureRGB(Graphics::Surface *texture) override;
|
||||
|
||||
void setupViewport(int x, int y, int width, int height) override;
|
||||
void drawCube(const Math::Vector3d &pos, const Math::Vector3d &roll) override;
|
||||
void drawPolyOffsetTest(const Math::Vector3d &pos, const Math::Vector3d &roll) override;
|
||||
void dimRegionInOut(float fade) override;
|
||||
void drawInViewport() override;
|
||||
void drawRgbaTexture() override;
|
||||
|
||||
private:
|
||||
OpenGL::ShaderGL *_cubeShader;
|
||||
OpenGL::ShaderGL *_fadeShader;
|
||||
OpenGL::ShaderGL *_bitmapShader;
|
||||
|
||||
GLuint _cubeVBO;
|
||||
GLuint _fadeVBO;
|
||||
GLuint _bitmapVBO;
|
||||
|
||||
Common::Rect _currentViewport;
|
||||
GLuint _textureRgbaId[10];
|
||||
GLuint _textureRgbId[10];
|
||||
};
|
||||
|
||||
} // End of namespace Playground3d
|
||||
|
|
|
@ -55,6 +55,22 @@ static const TGLfloat boxVertices[] = {
|
|||
1.0f, -1.0f,
|
||||
};
|
||||
|
||||
static const TGLfloat bitmapVertices[] = {
|
||||
// X Y
|
||||
-0.2f, 0.2f,
|
||||
0.2f, 0.2f,
|
||||
-0.2f, -0.2f,
|
||||
0.2f, -0.2f,
|
||||
};
|
||||
|
||||
static const TGLfloat textCords[] = {
|
||||
// S T
|
||||
0.0f, 0.0f,
|
||||
1.0f, 0.0f,
|
||||
0.0f, 1.0f,
|
||||
1.0f, 1.0f,
|
||||
};
|
||||
|
||||
Renderer *CreateGfxTinyGL(OSystem *system) {
|
||||
return new TinyGLRenderer(system);
|
||||
}
|
||||
|
@ -84,6 +100,52 @@ void TinyGLRenderer::init() {
|
|||
|
||||
tglDisable(TGL_LIGHTING);
|
||||
tglEnable(TGL_DEPTH_TEST);
|
||||
|
||||
tglGenTextures(10, _textureRgbaId);
|
||||
tglGenTextures(10, _textureRgbId);
|
||||
}
|
||||
|
||||
void TinyGLRenderer::deinit() {
|
||||
//tglDeleteTextures(10, &_textureRgbaId);
|
||||
//tglDeleteTextures(10, &_textureRgbId);
|
||||
}
|
||||
|
||||
void TinyGLRenderer::loadTextureRGBA(Graphics::Surface *texture) {
|
||||
tglBindTexture(TGL_TEXTURE_2D, _textureRgbaId[0]);
|
||||
tglTexParameteri(TGL_TEXTURE_2D, TGL_TEXTURE_MIN_FILTER, TGL_NEAREST);
|
||||
tglTexParameteri(TGL_TEXTURE_2D, TGL_TEXTURE_MAG_FILTER, TGL_NEAREST);
|
||||
tglTexImage2D(TGL_TEXTURE_2D, 0, TGL_RGBA, texture->w, texture->h, 0, TGL_RGBA, TGL_UNSIGNED_BYTE, texture->getPixels());
|
||||
tglBindTexture(TGL_TEXTURE_2D, _textureRgbaId[1]);
|
||||
tglTexParameteri(TGL_TEXTURE_2D, TGL_TEXTURE_MIN_FILTER, TGL_NEAREST);
|
||||
tglTexParameteri(TGL_TEXTURE_2D, TGL_TEXTURE_MAG_FILTER, TGL_NEAREST);
|
||||
tglTexImage2D(TGL_TEXTURE_2D, 0, TGL_RGBA, texture->w, texture->h, 0, TGL_BGRA, TGL_UNSIGNED_BYTE, texture->getPixels());
|
||||
tglBindTexture(TGL_TEXTURE_2D, _textureRgbaId[2]);
|
||||
tglTexParameteri(TGL_TEXTURE_2D, TGL_TEXTURE_MIN_FILTER, TGL_NEAREST);
|
||||
tglTexParameteri(TGL_TEXTURE_2D, TGL_TEXTURE_MAG_FILTER, TGL_NEAREST);
|
||||
tglTexImage2D(TGL_TEXTURE_2D, 0, TGL_RGBA, texture->w, texture->h, 0, TGL_RGBA, TGL_UNSIGNED_INT_8_8_8_8, texture->getPixels());
|
||||
tglBindTexture(TGL_TEXTURE_2D, _textureRgbaId[3]);
|
||||
tglTexParameteri(TGL_TEXTURE_2D, TGL_TEXTURE_MIN_FILTER, TGL_NEAREST);
|
||||
tglTexParameteri(TGL_TEXTURE_2D, TGL_TEXTURE_MAG_FILTER, TGL_NEAREST);
|
||||
tglTexImage2D(TGL_TEXTURE_2D, 0, TGL_RGBA, texture->w, texture->h, 0, TGL_BGRA, TGL_UNSIGNED_INT_8_8_8_8, texture->getPixels());
|
||||
tglBindTexture(TGL_TEXTURE_2D, _textureRgbaId[4]);
|
||||
tglTexParameteri(TGL_TEXTURE_2D, TGL_TEXTURE_MIN_FILTER, TGL_NEAREST);
|
||||
tglTexParameteri(TGL_TEXTURE_2D, TGL_TEXTURE_MAG_FILTER, TGL_NEAREST);
|
||||
tglTexImage2D(TGL_TEXTURE_2D, 0, TGL_RGBA, texture->w, texture->h, 0, TGL_RGBA, TGL_UNSIGNED_INT_8_8_8_8_REV, texture->getPixels());
|
||||
tglBindTexture(TGL_TEXTURE_2D, _textureRgbaId[5]);
|
||||
tglTexParameteri(TGL_TEXTURE_2D, TGL_TEXTURE_MIN_FILTER, TGL_NEAREST);
|
||||
tglTexParameteri(TGL_TEXTURE_2D, TGL_TEXTURE_MAG_FILTER, TGL_NEAREST);
|
||||
tglTexImage2D(TGL_TEXTURE_2D, 0, TGL_RGBA, texture->w, texture->h, 0, TGL_BGRA, TGL_UNSIGNED_INT_8_8_8_8_REV, texture->getPixels());
|
||||
}
|
||||
|
||||
void TinyGLRenderer::loadTextureRGB(Graphics::Surface *texture) {
|
||||
tglBindTexture(TGL_TEXTURE_2D, _textureRgbId[0]);
|
||||
tglTexParameteri(TGL_TEXTURE_2D, TGL_TEXTURE_MIN_FILTER, TGL_NEAREST);
|
||||
tglTexParameteri(TGL_TEXTURE_2D, TGL_TEXTURE_MAG_FILTER, TGL_NEAREST);
|
||||
tglTexImage2D(TGL_TEXTURE_2D, 0, TGL_RGBA, texture->w, texture->h, 0, TGL_RGB, TGL_UNSIGNED_BYTE, texture->getPixels());
|
||||
tglBindTexture(TGL_TEXTURE_2D, _textureRgbId[1]);
|
||||
tglTexParameteri(TGL_TEXTURE_2D, TGL_TEXTURE_MIN_FILTER, TGL_NEAREST);
|
||||
tglTexParameteri(TGL_TEXTURE_2D, TGL_TEXTURE_MAG_FILTER, TGL_NEAREST);
|
||||
tglTexImage2D(TGL_TEXTURE_2D, 0, TGL_RGBA, texture->w, texture->h, 0, TGL_BGR, TGL_UNSIGNED_BYTE, texture->getPixels());
|
||||
}
|
||||
|
||||
void TinyGLRenderer::clear(const Math::Vector4d &clearColor) {
|
||||
|
@ -236,4 +298,116 @@ void TinyGLRenderer::drawInViewport() {
|
|||
tglPopMatrix();
|
||||
}
|
||||
|
||||
void TinyGLRenderer::drawRgbaTexture() {
|
||||
tglMatrixMode(TGL_PROJECTION);
|
||||
tglPushMatrix();
|
||||
tglLoadIdentity();
|
||||
|
||||
tglMatrixMode(TGL_MODELVIEW);
|
||||
tglPushMatrix();
|
||||
tglLoadIdentity();
|
||||
|
||||
tglEnable(TGL_BLEND);
|
||||
tglBlendFunc(TGL_ONE, TGL_ONE_MINUS_SRC_ALPHA);
|
||||
tglDisable(TGL_DEPTH_TEST);
|
||||
tglDepthMask(TGL_FALSE);
|
||||
tglEnable(TGL_TEXTURE_2D);
|
||||
|
||||
tglColor4f(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
|
||||
tglTranslatef(-0.8, 0.8, 0);
|
||||
|
||||
tglEnableClientState(TGL_VERTEX_ARRAY);
|
||||
tglEnableClientState(TGL_TEXTURE_COORD_ARRAY);
|
||||
tglVertexPointer(2, TGL_FLOAT, 2 * sizeof(TGLfloat), bitmapVertices);
|
||||
tglTexCoordPointer(2, TGL_FLOAT, 2 * sizeof(TGLfloat), textCords);
|
||||
tglBindTexture(TGL_TEXTURE_2D, _textureRgbaId[0]);
|
||||
tglDrawArrays(TGL_TRIANGLE_STRIP, 0, 4);
|
||||
tglDisableClientState(TGL_VERTEX_ARRAY);
|
||||
tglDisableClientState(TGL_TEXTURE_COORD_ARRAY);
|
||||
|
||||
tglTranslatef(0.5, 0, 0);
|
||||
|
||||
tglEnableClientState(TGL_VERTEX_ARRAY);
|
||||
tglEnableClientState(TGL_TEXTURE_COORD_ARRAY);
|
||||
tglVertexPointer(2, TGL_FLOAT, 2 * sizeof(TGLfloat), bitmapVertices);
|
||||
tglTexCoordPointer(2, TGL_FLOAT, 2 * sizeof(TGLfloat), textCords);
|
||||
tglBindTexture(TGL_TEXTURE_2D, _textureRgbaId[1]);
|
||||
tglDrawArrays(TGL_TRIANGLE_STRIP, 0, 4);
|
||||
tglDisableClientState(TGL_VERTEX_ARRAY);
|
||||
tglDisableClientState(TGL_TEXTURE_COORD_ARRAY);
|
||||
|
||||
tglTranslatef(0.5, 0, 0);
|
||||
|
||||
tglEnableClientState(TGL_VERTEX_ARRAY);
|
||||
tglEnableClientState(TGL_TEXTURE_COORD_ARRAY);
|
||||
tglVertexPointer(2, TGL_FLOAT, 2 * sizeof(TGLfloat), bitmapVertices);
|
||||
tglTexCoordPointer(2, TGL_FLOAT, 2 * sizeof(TGLfloat), textCords);
|
||||
tglBindTexture(TGL_TEXTURE_2D, _textureRgbaId[2]);
|
||||
tglDrawArrays(TGL_TRIANGLE_STRIP, 0, 4);
|
||||
tglDisableClientState(TGL_VERTEX_ARRAY);
|
||||
tglDisableClientState(TGL_TEXTURE_COORD_ARRAY);
|
||||
|
||||
tglTranslatef(0.5, 0, 0);
|
||||
|
||||
tglEnableClientState(TGL_VERTEX_ARRAY);
|
||||
tglEnableClientState(TGL_TEXTURE_COORD_ARRAY);
|
||||
tglVertexPointer(2, TGL_FLOAT, 2 * sizeof(TGLfloat), bitmapVertices);
|
||||
tglTexCoordPointer(2, TGL_FLOAT, 2 * sizeof(TGLfloat), textCords);
|
||||
tglBindTexture(TGL_TEXTURE_2D, _textureRgbaId[3]);
|
||||
tglDrawArrays(TGL_TRIANGLE_STRIP, 0, 4);
|
||||
tglDisableClientState(TGL_VERTEX_ARRAY);
|
||||
tglDisableClientState(TGL_TEXTURE_COORD_ARRAY);
|
||||
|
||||
tglTranslatef(-1.5, -0.5, 0);
|
||||
|
||||
tglEnableClientState(TGL_VERTEX_ARRAY);
|
||||
tglEnableClientState(TGL_TEXTURE_COORD_ARRAY);
|
||||
tglVertexPointer(2, TGL_FLOAT, 2 * sizeof(TGLfloat), bitmapVertices);
|
||||
tglTexCoordPointer(2, TGL_FLOAT, 2 * sizeof(TGLfloat), textCords);
|
||||
tglBindTexture(TGL_TEXTURE_2D, _textureRgbaId[4]);
|
||||
tglDrawArrays(TGL_TRIANGLE_STRIP, 0, 4);
|
||||
tglDisableClientState(TGL_VERTEX_ARRAY);
|
||||
tglDisableClientState(TGL_TEXTURE_COORD_ARRAY);
|
||||
|
||||
tglTranslatef(0.5, 0, 0);
|
||||
|
||||
tglEnableClientState(TGL_VERTEX_ARRAY);
|
||||
tglEnableClientState(TGL_TEXTURE_COORD_ARRAY);
|
||||
tglVertexPointer(2, TGL_FLOAT, 2 * sizeof(TGLfloat), bitmapVertices);
|
||||
tglTexCoordPointer(2, TGL_FLOAT, 2 * sizeof(TGLfloat), textCords);
|
||||
tglBindTexture(TGL_TEXTURE_2D, _textureRgbaId[5]);
|
||||
tglDrawArrays(TGL_TRIANGLE_STRIP, 0, 4);
|
||||
tglDisableClientState(TGL_VERTEX_ARRAY);
|
||||
tglDisableClientState(TGL_TEXTURE_COORD_ARRAY);
|
||||
|
||||
tglTranslatef(0.5, 0, 0);
|
||||
|
||||
tglEnableClientState(TGL_VERTEX_ARRAY);
|
||||
tglEnableClientState(TGL_TEXTURE_COORD_ARRAY);
|
||||
tglVertexPointer(2, TGL_FLOAT, 2 * sizeof(TGLfloat), bitmapVertices);
|
||||
tglTexCoordPointer(2, TGL_FLOAT, 2 * sizeof(TGLfloat), textCords);
|
||||
tglBindTexture(TGL_TEXTURE_2D, _textureRgbId[0]);
|
||||
tglDrawArrays(TGL_TRIANGLE_STRIP, 0, 4);
|
||||
tglDisableClientState(TGL_VERTEX_ARRAY);
|
||||
tglDisableClientState(TGL_TEXTURE_COORD_ARRAY);
|
||||
|
||||
tglTranslatef(0.5, 0, 0);
|
||||
|
||||
tglEnableClientState(TGL_VERTEX_ARRAY);
|
||||
tglEnableClientState(TGL_TEXTURE_COORD_ARRAY);
|
||||
tglVertexPointer(2, TGL_FLOAT, 2 * sizeof(TGLfloat), bitmapVertices);
|
||||
tglTexCoordPointer(2, TGL_FLOAT, 2 * sizeof(TGLfloat), textCords);
|
||||
tglBindTexture(TGL_TEXTURE_2D, _textureRgbId[1]);
|
||||
tglDrawArrays(TGL_TRIANGLE_STRIP, 0, 4);
|
||||
tglDisableClientState(TGL_VERTEX_ARRAY);
|
||||
tglDisableClientState(TGL_TEXTURE_COORD_ARRAY);
|
||||
|
||||
tglMatrixMode(TGL_MODELVIEW);
|
||||
tglPopMatrix();
|
||||
|
||||
tglMatrixMode(TGL_PROJECTION);
|
||||
tglPopMatrix();
|
||||
}
|
||||
|
||||
} // End of namespace Playground3d
|
||||
|
|
|
@ -40,20 +40,26 @@ public:
|
|||
virtual ~TinyGLRenderer();
|
||||
|
||||
void init() override;
|
||||
void deinit() override;
|
||||
|
||||
void clear(const Math::Vector4d &clearColor) override;
|
||||
void loadTextureRGB(Graphics::Surface *texture) override;
|
||||
void loadTextureRGBA(Graphics::Surface *texture) override;
|
||||
|
||||
void setupViewport(int x, int y, int width, int height) override;
|
||||
void drawCube(const Math::Vector3d &pos, const Math::Vector3d &roll) override;
|
||||
void drawPolyOffsetTest(const Math::Vector3d &pos, const Math::Vector3d &roll) override;
|
||||
void dimRegionInOut(float fade) override;
|
||||
void drawInViewport() override;
|
||||
void drawRgbaTexture() override;
|
||||
|
||||
void flipBuffer() override;
|
||||
|
||||
private:
|
||||
TinyGL::FrameBuffer *_fb;
|
||||
Math::Vector3d _pos;
|
||||
TGLuint _textureRgbaId[10];
|
||||
TGLuint _textureRgbId[10];
|
||||
|
||||
void drawFace(uint face);
|
||||
};
|
||||
|
|
|
@ -68,6 +68,7 @@ Common::Error Playground3dEngine::run() {
|
|||
// 3 - fade in/out
|
||||
// 4 - moving filled rectangle in viewport
|
||||
int testId = 1;
|
||||
// 5 - drawing RGBA pattern texture to check endian correctness
|
||||
|
||||
switch (testId) {
|
||||
case 1:
|
||||
|
@ -83,6 +84,19 @@ Common::Error Playground3dEngine::run() {
|
|||
case 4:
|
||||
_clearColor = Math::Vector4d(0.5f, 0.5f, 0.5f, 1.0f);
|
||||
break;
|
||||
case 5: {
|
||||
_clearColor = Math::Vector4d(0.5f, 0.5f, 0.5f, 1.0f);
|
||||
#if defined(SCUMM_LITTLE_ENDIAN)
|
||||
Graphics::PixelFormat pixelFormatRGBA(4, 8, 8, 8, 8, 0, 8, 16, 24);
|
||||
Graphics::PixelFormat pixelFormatRGB(3, 8, 8, 8, 0, 0, 8, 16, 0);
|
||||
#else
|
||||
Graphics::PixelFormat pixelFormatRGBA(4, 8, 8, 8, 8, 24, 16, 8, 0);
|
||||
Graphics::PixelFormat pixelFormatRGB(3, 8, 8, 8, 0, 0, 8, 16, 0);
|
||||
#endif
|
||||
_rgbaTexture = generateRgbaTexture(120, 120, pixelFormatRGBA);
|
||||
_rgbTexture = _rgbaTexture->convertTo(pixelFormatRGB);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
assert(false);
|
||||
}
|
||||
|
@ -92,6 +106,9 @@ Common::Error Playground3dEngine::run() {
|
|||
drawFrame(testId);
|
||||
}
|
||||
|
||||
delete _rgbaTexture;
|
||||
delete _rgbTexture;
|
||||
_gfx->deinit();
|
||||
_system->showMouse(false);
|
||||
|
||||
return Common::kNoError;
|
||||
|
@ -107,6 +124,28 @@ void Playground3dEngine::processInput() {
|
|||
}
|
||||
}
|
||||
|
||||
Graphics::Surface *Playground3dEngine::generateRgbaTexture(int width, int height, Graphics::PixelFormat format) {
|
||||
Graphics::Surface *surface = new Graphics::Surface;
|
||||
surface->create(width, height, format);
|
||||
const int barW = width / 4;
|
||||
Common::Rect r(0, 0, barW, height);
|
||||
uint32 pixel = format.ARGBToColor(255, 255, 0, 0);
|
||||
surface->fillRect(r, pixel);
|
||||
r.left += barW;
|
||||
r.right += barW;
|
||||
pixel = format.ARGBToColor(255, 0, 255, 0);
|
||||
surface->fillRect(r, pixel);
|
||||
r.left += barW;
|
||||
r.right += barW;
|
||||
pixel = format.ARGBToColor(255, 0, 0, 255);
|
||||
surface->fillRect(r, pixel);
|
||||
r.left += barW;
|
||||
r.right += barW;
|
||||
pixel = format.ARGBToColor(128, 0, 0, 0);
|
||||
surface->fillRect(r, pixel);
|
||||
return surface;
|
||||
}
|
||||
|
||||
void Playground3dEngine::drawAndRotateCube() {
|
||||
Math::Vector3d pos = Math::Vector3d(0.0f, 0.0f, 6.0f);
|
||||
_gfx->drawCube(pos, Math::Vector3d(_rotateAngleX, _rotateAngleY, _rotateAngleZ));
|
||||
|
@ -148,6 +187,10 @@ void Playground3dEngine::drawInViewport() {
|
|||
_gfx->drawInViewport();
|
||||
}
|
||||
|
||||
void Playground3dEngine::drawRgbaTexture() {
|
||||
_gfx->drawRgbaTexture();
|
||||
}
|
||||
|
||||
void Playground3dEngine::drawFrame(int testId) {
|
||||
_gfx->clear(_clearColor);
|
||||
|
||||
|
@ -173,6 +216,11 @@ void Playground3dEngine::drawFrame(int testId) {
|
|||
_gfx->setupViewport(vp.left + 40, _system->getHeight() - vp.top - vp.height() + 40, vp.width() - 80, vp.height() - 80);
|
||||
drawInViewport();
|
||||
break;
|
||||
case 5:
|
||||
_gfx->loadTextureRGBA(_rgbaTexture);
|
||||
_gfx->loadTextureRGB(_rgbTexture);
|
||||
drawRgbaTexture();
|
||||
break;
|
||||
default:
|
||||
assert(false);
|
||||
}
|
||||
|
|
|
@ -53,13 +53,17 @@ private:
|
|||
Math::Vector4d _clearColor;
|
||||
float _fade;
|
||||
bool _fadeIn;
|
||||
Graphics::Surface *_rgbaTexture;
|
||||
Graphics::Surface *_rgbTexture;
|
||||
|
||||
float _rotateAngleX, _rotateAngleY, _rotateAngleZ;
|
||||
|
||||
Graphics::Surface *generateRgbaTexture(int width, int height, Graphics::PixelFormat format);
|
||||
void drawAndRotateCube();
|
||||
void drawPolyOffsetTest();
|
||||
void dimRegionInOut();
|
||||
void drawInViewport();
|
||||
void drawRgbaTexture();
|
||||
};
|
||||
|
||||
} // End of namespace Playground3d
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
in vec2 Texcoord;
|
||||
|
||||
OUTPUT
|
||||
|
||||
uniform sampler2D tex;
|
||||
|
||||
void main() {
|
||||
outColor = texture(tex, Texcoord);
|
||||
}
|
11
engines/playground3d/shaders/playground3d_bitmap.vertex
Normal file
11
engines/playground3d/shaders/playground3d_bitmap.vertex
Normal file
|
@ -0,0 +1,11 @@
|
|||
in vec2 position;
|
||||
in vec2 texcoord;
|
||||
|
||||
out vec2 Texcoord;
|
||||
|
||||
uniform vec2 offsetXY;
|
||||
|
||||
void main() {
|
||||
Texcoord = texcoord;
|
||||
gl_Position = vec4(position + offsetXY, 0.0, 1.0);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue