mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 01:03:57 +02:00
Use a bound texture for the iris, load it with Qt rather than lodepng (we can
probably just remove the lodepng dependency).
This commit is contained in:
parent
11fcd8f72f
commit
466c062bc1
3 changed files with 25 additions and 15 deletions
|
@ -271,6 +271,7 @@ Avatar::~Avatar() {
|
|||
}
|
||||
|
||||
void Avatar::init() {
|
||||
_head.init();
|
||||
_voxels.init();
|
||||
_initialized = true;
|
||||
}
|
||||
|
|
|
@ -5,6 +5,9 @@
|
|||
// Copyright (c) 2013 High Fidelity, Inc. All rights reserved.
|
||||
|
||||
#include <glm/gtx/quaternion.hpp>
|
||||
|
||||
#include <QImage>
|
||||
|
||||
#include "Application.h"
|
||||
#include "Avatar.h"
|
||||
#include "Head.h"
|
||||
|
@ -36,9 +39,7 @@ const float IRIS_RADIUS = 0.007;
|
|||
const float IRIS_PROTRUSION = 0.0145f;
|
||||
const char IRIS_TEXTURE_FILENAME[] = "resources/images/iris.png";
|
||||
|
||||
unsigned int IRIS_TEXTURE_WIDTH = 768;
|
||||
unsigned int IRIS_TEXTURE_HEIGHT = 498;
|
||||
vector<unsigned char> irisTexture;
|
||||
GLuint Head::_irisTextureID = 0;
|
||||
|
||||
Head::Head(Avatar* owningAvatar) :
|
||||
HeadData((AvatarData*)owningAvatar),
|
||||
|
@ -74,6 +75,19 @@ Head::Head(Avatar* owningAvatar) :
|
|||
}
|
||||
}
|
||||
|
||||
void Head::init() {
|
||||
if (_irisTextureID == 0) {
|
||||
switchToResourcesParentIfRequired();
|
||||
QImage image = QImage(IRIS_TEXTURE_FILENAME).convertToFormat(QImage::Format_RGB888);
|
||||
|
||||
glGenTextures(1, &_irisTextureID);
|
||||
glBindTexture(GL_TEXTURE_2D, _irisTextureID);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, image.width(), image.height(), 0, GL_RGB, GL_UNSIGNED_BYTE, image.constBits());
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
}
|
||||
}
|
||||
|
||||
void Head::reset() {
|
||||
_yaw = _pitch = _roll = 0.0f;
|
||||
_leanForward = _leanSideways = 0.0f;
|
||||
|
@ -469,22 +483,12 @@ void Head::renderEyeBrows() {
|
|||
|
||||
void Head::renderEyeBalls() {
|
||||
|
||||
if (::irisTexture.size() == 0) {
|
||||
switchToResourcesParentIfRequired();
|
||||
unsigned error = lodepng::decode(::irisTexture, IRIS_TEXTURE_WIDTH, IRIS_TEXTURE_HEIGHT, IRIS_TEXTURE_FILENAME);
|
||||
if (error != 0) {
|
||||
printLog("error %u: %s\n", error, lodepng_error_text(error));
|
||||
}
|
||||
}
|
||||
|
||||
// setup the texutre to be used on each iris
|
||||
GLUquadric* irisQuadric = gluNewQuadric();
|
||||
gluQuadricTexture(irisQuadric, GL_TRUE);
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
|
||||
gluQuadricOrientation(irisQuadric, GLU_OUTSIDE);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, IRIS_TEXTURE_WIDTH, IRIS_TEXTURE_HEIGHT,
|
||||
0, GL_RGBA, GL_UNSIGNED_BYTE, &::irisTexture[0]);
|
||||
glBindTexture(GL_TEXTURE_2D, _irisTextureID);
|
||||
|
||||
// render white ball of left eyeball
|
||||
glPushMatrix();
|
||||
|
@ -579,6 +583,8 @@ void Head::renderEyeBalls() {
|
|||
// delete the iris quadric now that we're done with it
|
||||
gluDeleteQuadric(irisQuadric);
|
||||
glPopMatrix();
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
}
|
||||
|
||||
void Head::renderLookatVectors(glm::vec3 leftEyePosition, glm::vec3 rightEyePosition, glm::vec3 lookatPosition) {
|
||||
|
|
|
@ -31,6 +31,7 @@ class Head : public HeadData {
|
|||
public:
|
||||
Head(Avatar* owningAvatar);
|
||||
|
||||
void init();
|
||||
void reset();
|
||||
void simulate(float deltaTime, bool isMine);
|
||||
void render(bool lookingInMirror, float alpha);
|
||||
|
@ -104,6 +105,8 @@ private:
|
|||
glm::vec3* _mohawkTriangleFan;
|
||||
glm::vec3* _mohawkColors;
|
||||
|
||||
static GLuint _irisTextureID;
|
||||
|
||||
// private methods
|
||||
void createMohawk();
|
||||
void renderHeadSphere();
|
||||
|
|
Loading…
Reference in a new issue