MYST3: Removed dependency to GLU

This commit is contained in:
Stefano Musumeci 2014-06-22 23:09:17 +02:00
parent 11b53aea97
commit a14f2b6695
4 changed files with 58 additions and 23 deletions

View File

@ -38,8 +38,6 @@
#include "engines/myst3/gfx_tinygl.h"
#include "engines/myst3/gfx_tinygl_texture.h"
#include <gl/GLU.h>
namespace Myst3 {
Renderer *CreateGfxTinyGL(OSystem *system) {
@ -105,7 +103,7 @@ void TinyGLRenderer::setupCameraPerspective(float pitch, float heading, float fo
glFOV = 36.0; // Somewhat good value for fov == 60
// NOTE: tinyGL viewport implementation needs to be checked as it doesn't behave the same as openGL
tglViewport(0, 30, kOriginalWidth, kFrameHeight);
tglViewport(0, kTopBorderHeight, kOriginalWidth, kFrameHeight);
tglMatrixMode(TGL_PROJECTION);
tglLoadIdentity();
tgluPerspective(glFOV, (TGLfloat)kOriginalWidth / (TGLfloat)kFrameHeight, 1.0, 10000.0);
@ -150,21 +148,18 @@ void TinyGLRenderer::drawRect2D(const Common::Rect &rect, uint32 color) {
}
void TinyGLRenderer::drawTexturedRect2D(const Common::Rect &screenRect, const Common::Rect &textureRect,
Texture *texture, float transparency) {
TinyGLTexture *glTexture = static_cast<TinyGLTexture *>(texture);
const float tLeft = textureRect.left / (float) glTexture->internalWidth;
const float tWidth = textureRect.width() / (float) glTexture->internalWidth;
const float tTop = textureRect.top / (float) glTexture->internalHeight;
const float tHeight = textureRect.height() / (float) glTexture->internalHeight;
Texture *texture, float transparency, bool additiveBlending) {
const float sLeft = screenRect.left;
const float sTop = screenRect.top;
const float sWidth = screenRect.width();
const float sHeight = screenRect.height();
if (transparency >= 0.0) {
tglBlendFunc(TGL_SRC_ALPHA, TGL_ONE_MINUS_SRC_ALPHA);
if (additiveBlending) {
tglBlendFunc(TGL_SRC_ALPHA, TGL_ONE);
} else {
tglBlendFunc(TGL_SRC_ALPHA, TGL_ONE_MINUS_SRC_ALPHA);
}
tglEnable(TGL_BLEND);
} else {
transparency = 1.0;
@ -203,11 +198,6 @@ void TinyGLRenderer::draw2DText(const Common::String &text, const Common::Point
int w = textureRect.width();
int h = textureRect.height();
float cw = textureRect.width() / (float) glFont->internalWidth;
float ch = textureRect.height() / (float) glFont->internalHeight;
float cx = textureRect.left / (float) glFont->internalWidth;
float cy = textureRect.top / (float) glFont->internalHeight;
blitScreen(glFont, x, y, textureRect.left, textureRect.top, w, h, 1.0f, true);
x += textureRect.width() - 3;
@ -318,6 +308,16 @@ Graphics::Surface *TinyGLRenderer::getScreenshot() {
s->create(kOriginalWidth, kOriginalHeight, Graphics::PixelFormat(4, 8, 8, 8, 8, 0, 8, 16, 24));
Graphics::PixelBuffer buf(s->format, (byte *)s->getPixels());
_fb->copyToBuffer(buf);
//Vertical flip in place:
Graphics::PixelBuffer startLine(s->format, kOriginalWidth, DisposeAfterUse::YES);
Graphics::PixelBuffer endLine(s->format, kOriginalWidth, DisposeAfterUse::YES);
for(int y = 0; y < kOriginalHeight / 2; y++)
{
startLine.copyBuffer(0, y * kOriginalWidth, kOriginalWidth, buf);
endLine.copyBuffer(0, (kOriginalHeight - y - 1) * kOriginalWidth, kOriginalWidth, buf);
buf.copyBuffer(y * kOriginalWidth, 0, kOriginalWidth, endLine);
buf.copyBuffer((kOriginalHeight - y - 1) * kOriginalWidth, 0, kOriginalWidth, startLine);
}
return s;
}
@ -325,7 +325,7 @@ void TinyGLRenderer::screenPosToDirection(const Common::Point screen, float &pit
double x, y, z;
// Screen coords to 3D coords
gluUnProject(screen.x, kOriginalHeight - screen.y, 0.9, _cubeModelViewMatrix, _cubeProjectionMatrix, (TGLint *)_cubeViewport, &x, &y, &z);
tgluUnProject(screen.x, kOriginalHeight - screen.y, 0.9, _cubeModelViewMatrix, _cubeProjectionMatrix, (TGLint *)_cubeViewport, &x, &y, &z);
// 3D coords to polar coords
Math::Vector3d v = Math::Vector3d(x, y, z);
@ -391,4 +391,4 @@ void TinyGLRenderer::blitScreen(Texture *texture, int dstX, int dstY, int srcX,
}
}
} // end of namespace Myst3
} // end of namespace Myst3

View File

@ -47,7 +47,7 @@ public:
void freeTexture(Texture *texture);
virtual void drawRect2D(const Common::Rect &rect, uint32 color);
virtual void drawTexturedRect2D(const Common::Rect &screenRect, const Common::Rect &textureRect, Texture *texture, float transparency = -1.0);
virtual void drawTexturedRect2D(const Common::Rect &screenRect, const Common::Rect &textureRect, Texture *texture, float transparency = -1.0, bool additiveBlending = false);
virtual void drawTexturedRect3D(const Math::Vector3d &topLeft, const Math::Vector3d &bottomLeft,
const Math::Vector3d &topRight, const Math::Vector3d &bottomRight,
Texture *texture);

View File

@ -742,6 +742,8 @@ void tglFrustum(double left, double right, double bottom, double top,
void tglOrtho(double left, double right, double bottom, double top, double zNear, double zFar);
void tgluPerspective(double fovy, double aspect, double zNear, double zFar);
void tgluOrtho2D(double left, double right, double bottom, double top);
void tgluUnProject(double winx,double winy, double winz, const double modelMatrix[16], const double projMatrix[16], const int viewport[4],
double *objx, double *objy, double *objz);
// lists
unsigned int tglGenLists(int range);

View File

@ -193,7 +193,7 @@ void glopFrustum(GLContext *c, GLParam *p) {
void glopOrtho(GLContext *context, GLParam *p) {
float *r;
M4 m;
TinyGL::Matrix4 m;
float left = p[1].f;
float right = p[2].f;
float bottom = p[3].f;
@ -209,14 +209,47 @@ void glopOrtho(GLContext *context, GLParam *p) {
float ty = -(top + bottom) / (top - bottom);
float tz = -(zFar + zNear) / (zFar - zNear);
r = &m.m[0][0];
r = &m._m[0][0];
r[0] = a; r[1] = 0; r[2] = 0; r[3] = 0;
r[4] = 0; r[5] = b; r[6] = 0; r[7] = 0;
r[8] = 0; r[9] = 0; r[10] = c; r[11] = 0;
r[12] = tx; r[13] = ty; r[14] = tz; r[15] = 0;
gl_M4_MulLeft(context->matrix_stack_ptr[context->matrix_mode], &m);
*context->matrix_stack_ptr[context->matrix_mode] *= m;
gl_matrix_update(context);
}
} // end of namespace TinyGL
// Code take from openGL wiki and adapted: http://www.opengl.org/wiki/GluProject_and_gluUnProject_code
void tgluUnProject(double winx, double winy, double winz, const double modelMatrix[16], const double projMatrix[16], const int viewport[4], double *objx, double *objy, double *objz) {
//Transformation matrices
TinyGL::Vector4 in, out;
TinyGL::Matrix4 A;
TinyGL::Matrix4 m;
TinyGL::Matrix4 model, projection;
for(int i = 0; i < 16; i++)
{
((float *)model._m)[i] = modelMatrix[i];
((float *)projection._m)[i] = projMatrix[i];
}
//Calculation for inverting a matrix, compute projection x modelview
//and store in A[16]
A = model * projection;
//Now compute the inverse of matrix A
m = A.inverse();
//Transformation of normalized coordinates between -1 and 1
in.X = (winx - (float)viewport[0]) / (float)viewport[2] * 2.0 - 1.0;
in.Y = (winy - (float)viewport[1]) / (float)viewport[3] * 2.0 - 1.0;
in.Z = 2.0 * winz - 1.0;
in.W = 1.0;
//Objects coordinates
m.transform(in,out);
if (out.W == 0.0f)
return;
out.W = 1.0 / out.W;
*objx = out.X * out.W;
*objy = out.Y * out.W;
*objz = out.Z * out.W;
}