mirror of
https://github.com/lubosz/overte.git
synced 2025-04-16 09:46:29 +02:00
Working on mesh rendering for faces.
This commit is contained in:
parent
a59fbfbf3e
commit
5c590638f3
5 changed files with 68 additions and 9 deletions
|
@ -75,7 +75,8 @@ add_subdirectory(external/fervor/)
|
|||
include_directories(external/fervor/)
|
||||
|
||||
# run qt moc on qt-enabled headers
|
||||
qt4_wrap_cpp(INTERFACE_SRCS src/Application.h src/Webcam.h src/avatar/AvatarVoxelSystem.h src/ui/BandwidthDialog.h)
|
||||
qt4_wrap_cpp(INTERFACE_SRCS src/Application.h src/Webcam.h src/avatar/AvatarVoxelSystem.h
|
||||
src/avatar/Face.h src/ui/BandwidthDialog.h)
|
||||
|
||||
# create the executable, make it a bundle on OS X
|
||||
add_executable(${TARGET_NAME} MACOSX_BUNDLE ${INTERFACE_SRCS})
|
||||
|
|
|
@ -22,7 +22,10 @@ uniform sampler2D depthTexture;
|
|||
|
||||
void main(void) {
|
||||
gl_TexCoord[0] = vec4(texCoordCorner + gl_Vertex.x * texCoordRight + gl_Vertex.y * texCoordUp, 0.0, 1.0);
|
||||
gl_FrontColor = vec4(1.0, 1.0, 1.0, 1.0);
|
||||
float depth = texture2D(depthTexture, gl_TexCoord[0].st).r;
|
||||
const float MIN_VISIBLE_DEPTH = 1.0 / 255.0;
|
||||
const float MAX_VISIBLE_DEPTH = 254.0 / 255.0;
|
||||
gl_FrontColor = vec4(1.0, 1.0, 1.0, step(MIN_VISIBLE_DEPTH, depth) * (1.0 - step(MAX_VISIBLE_DEPTH, depth)));
|
||||
gl_Position = gl_ModelViewProjectionMatrix * vec4(0.5 - gl_Vertex.x,
|
||||
gl_Vertex.y * length(texCoordUp) / length(texCoordRight), -texture2D(depthTexture, gl_TexCoord[0].st).r, 1.0);
|
||||
gl_Vertex.y * length(texCoordUp) / length(texCoordRight), depth * -2.0 + 1.0, 1.0);
|
||||
}
|
||||
|
|
|
@ -520,6 +520,11 @@ bool FrameGrabber::init() {
|
|||
|
||||
_userGenerator.GetSkeletonCap().SetSkeletonProfile(XN_SKEL_PROFILE_UPPER);
|
||||
|
||||
// make the depth viewpoint match that of the video image
|
||||
if (_depthGenerator.IsCapabilitySupported(XN_CAPABILITY_ALTERNATIVE_VIEW_POINT)) {
|
||||
_depthGenerator.GetAlternativeViewPointCap().SetViewPoint(_imageGenerator);
|
||||
}
|
||||
|
||||
_xnContext.StartGeneratingAll();
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -19,8 +19,9 @@ int Face::_texCoordCornerLocation;
|
|||
int Face::_texCoordRightLocation;
|
||||
int Face::_texCoordUpLocation;
|
||||
GLuint Face::_vboID;
|
||||
GLuint Face::_iboID;
|
||||
|
||||
Face::Face(Head* owningHead) : _owningHead(owningHead), _colorTextureID(0), _depthTextureID(0) {
|
||||
Face::Face(Head* owningHead) : _owningHead(owningHead), _renderMode(MESH), _colorTextureID(0), _depthTextureID(0) {
|
||||
}
|
||||
|
||||
bool Face::render(float alpha) {
|
||||
|
@ -48,6 +49,12 @@ bool Face::render(float alpha) {
|
|||
const int VERTEX_COUNT = VERTEX_WIDTH * VERTEX_HEIGHT;
|
||||
const int ELEMENTS_PER_VERTEX = 2;
|
||||
const int BUFFER_ELEMENTS = VERTEX_COUNT * ELEMENTS_PER_VERTEX;
|
||||
const int QUAD_WIDTH = VERTEX_WIDTH - 1;
|
||||
const int QUAD_HEIGHT = VERTEX_HEIGHT - 1;
|
||||
const int QUAD_COUNT = QUAD_WIDTH * QUAD_HEIGHT;
|
||||
const int TRIANGLES_PER_QUAD = 2;
|
||||
const int INDICES_PER_TRIANGLE = 3;
|
||||
const int INDEX_COUNT = QUAD_COUNT * TRIANGLES_PER_QUAD * INDICES_PER_TRIANGLE;
|
||||
|
||||
if (_program == 0) {
|
||||
_program = new ProgramObject();
|
||||
|
@ -77,12 +84,31 @@ bool Face::render(float alpha) {
|
|||
glBufferData(GL_ARRAY_BUFFER, BUFFER_ELEMENTS * sizeof(float), vertices, GL_STATIC_DRAW);
|
||||
delete[] vertices;
|
||||
|
||||
glGenBuffers(1, &_iboID);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _iboID);
|
||||
int* indices = new int[INDEX_COUNT];
|
||||
int* indexPosition = indices;
|
||||
for (int i = 0; i < QUAD_HEIGHT; i++) {
|
||||
for (int j = 0; j < QUAD_WIDTH; j++) {
|
||||
*indexPosition++ = i * VERTEX_WIDTH + j;
|
||||
*indexPosition++ = (i + 1) * VERTEX_WIDTH + j;
|
||||
*indexPosition++ = i * VERTEX_WIDTH + j + 1;
|
||||
|
||||
*indexPosition++ = i * VERTEX_WIDTH + j + 1;
|
||||
*indexPosition++ = (i + 1) * VERTEX_WIDTH + j;
|
||||
*indexPosition++ = (i + 1) * VERTEX_WIDTH + j + 1;
|
||||
}
|
||||
}
|
||||
glBufferData(GL_ELEMENT_ARRAY_BUFFER, INDEX_COUNT * sizeof(int), indices, GL_STATIC_DRAW);
|
||||
delete[] indices;
|
||||
|
||||
} else {
|
||||
glBindBuffer(GL_ARRAY_BUFFER, _vboID);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _iboID);
|
||||
}
|
||||
glBindTexture(GL_TEXTURE_2D, _depthTextureID);
|
||||
|
||||
glActiveTexture(GL_TEXTURE0 + 1);
|
||||
glActiveTexture(GL_TEXTURE1);
|
||||
glBindTexture(GL_TEXTURE_2D, _colorTextureID);
|
||||
|
||||
_program->bind();
|
||||
|
@ -94,9 +120,17 @@ bool Face::render(float alpha) {
|
|||
(points[1].x - points[0].x) / _textureSize.width, (points[1].y - points[0].y) / _textureSize.height);
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
glVertexPointer(2, GL_FLOAT, 0, 0);
|
||||
glPointSize(3.0f);
|
||||
glDrawArrays(GL_POINTS, 0, VERTEX_COUNT);
|
||||
glPointSize(1.0f);
|
||||
|
||||
if (_renderMode == POINTS) {
|
||||
glPointSize(3.0f);
|
||||
glDrawArrays(GL_POINTS, 0, VERTEX_COUNT);
|
||||
glPointSize(1.0f);
|
||||
|
||||
} else {
|
||||
glDrawRangeElementsEXT(GL_TRIANGLES, 0, VERTEX_COUNT - 1, INDEX_COUNT, GL_UNSIGNED_INT, 0);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||
}
|
||||
|
||||
glDisableClientState(GL_VERTEX_ARRAY);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
_program->release();
|
||||
|
@ -129,3 +163,7 @@ bool Face::render(float alpha) {
|
|||
return true;
|
||||
}
|
||||
|
||||
void Face::cycleRenderMode() {
|
||||
_renderMode = (RenderMode)((_renderMode + 1) % RENDER_MODE_COUNT);
|
||||
}
|
||||
|
||||
|
|
|
@ -9,6 +9,8 @@
|
|||
#ifndef __interface__Face__
|
||||
#define __interface__Face__
|
||||
|
||||
#include <QObject>
|
||||
|
||||
#include <opencv2/opencv.hpp>
|
||||
|
||||
#include "InterfaceConfig.h"
|
||||
|
@ -16,7 +18,9 @@
|
|||
class Head;
|
||||
class ProgramObject;
|
||||
|
||||
class Face {
|
||||
class Face : public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
|
||||
Face(Head* owningHead);
|
||||
|
@ -27,10 +31,17 @@ public:
|
|||
void setTextureRect(const cv::RotatedRect& textureRect) { _textureRect = textureRect; }
|
||||
|
||||
bool render(float alpha);
|
||||
|
||||
public slots:
|
||||
|
||||
void cycleRenderMode();
|
||||
|
||||
private:
|
||||
|
||||
enum RenderMode { POINTS, MESH, RENDER_MODE_COUNT };
|
||||
|
||||
Head* _owningHead;
|
||||
RenderMode _renderMode;
|
||||
GLuint _colorTextureID;
|
||||
GLuint _depthTextureID;
|
||||
cv::Size2f _textureSize;
|
||||
|
@ -41,6 +52,7 @@ private:
|
|||
static int _texCoordRightLocation;
|
||||
static int _texCoordUpLocation;
|
||||
static GLuint _vboID;
|
||||
static GLuint _iboID;
|
||||
};
|
||||
|
||||
#endif /* defined(__interface__Face__) */
|
||||
|
|
Loading…
Reference in a new issue