From 466c062bc1ada71ffaa35db102e0bad0fb76ab59 Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Thu, 13 Jun 2013 14:41:06 -0700 Subject: [PATCH] Use a bound texture for the iris, load it with Qt rather than lodepng (we can probably just remove the lodepng dependency). --- interface/src/Avatar.cpp | 1 + interface/src/Head.cpp | 36 +++++++++++++++++++++--------------- interface/src/Head.h | 3 +++ 3 files changed, 25 insertions(+), 15 deletions(-) diff --git a/interface/src/Avatar.cpp b/interface/src/Avatar.cpp index a2ff33ca52..4d1eca808d 100644 --- a/interface/src/Avatar.cpp +++ b/interface/src/Avatar.cpp @@ -271,6 +271,7 @@ Avatar::~Avatar() { } void Avatar::init() { + _head.init(); _voxels.init(); _initialized = true; } diff --git a/interface/src/Head.cpp b/interface/src/Head.cpp index c7fac99d8b..b8f89fbde6 100644 --- a/interface/src/Head.cpp +++ b/interface/src/Head.cpp @@ -5,6 +5,9 @@ // Copyright (c) 2013 High Fidelity, Inc. All rights reserved. #include + +#include + #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 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) { diff --git a/interface/src/Head.h b/interface/src/Head.h index d331b98efc..2deb638eff 100644 --- a/interface/src/Head.h +++ b/interface/src/Head.h @@ -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();