Must init webcam after OpenGL.

This commit is contained in:
Andrzej Kapolka 2013-06-17 16:24:47 -07:00
parent c7ddc89803
commit 3c58f0c0a7
3 changed files with 15 additions and 8 deletions

View file

@ -1416,6 +1416,8 @@ void Application::init() {
QMetaObject::invokeMethod(_fullScreenMode, "trigger", Qt::QueuedConnection);
}
_webcam.init();
gettimeofday(&_timerStart, NULL);
gettimeofday(&_lastTimeIdle, NULL);
@ -2152,8 +2154,9 @@ void Application::displayOverlay() {
}
// render the webcam input frame
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, _webcam.getFrameTextureID());
glEnable(GL_TEXTURE_2D);
glColor3f(1.0f, 1.0f, 1.0f);
glBegin(GL_QUADS);
const int FRAME_PREVIEW_HEIGHT = 200;
int framePreviewWidth = _webcam.getFrameAspectRatio() * FRAME_PREVIEW_HEIGHT;

View file

@ -5,6 +5,8 @@
// Created by Andrzej Kapolka on 6/17/13.
// Copyright (c) 2013 High Fidelity, Inc. All rights reserved.
#include <QtDebug>
#include <opencv2/opencv.hpp>
#include <Log.h>
@ -17,19 +19,20 @@ Webcam::Webcam() {
return;
}
// bump up the capture property
cvSetCaptureProperty(_capture, CV_CAP_PROP_FPS, 60);
// get the dimensions of the frames
// get the dimensions, fps of the frames
_frameWidth = cvGetCaptureProperty(_capture, CV_CAP_PROP_FRAME_WIDTH);
_frameHeight = cvGetCaptureProperty(_capture, CV_CAP_PROP_FRAME_HEIGHT);
int fps = cvGetCaptureProperty(_capture, CV_CAP_PROP_FPS);
printLog("Opened camera [width=%d, height=%d, fps=%d].", _frameWidth, _frameHeight, fps);
}
void Webcam::init() {
// initialize the texture that will contain the grabbed frames
glGenTextures(1, &_frameTextureID);
glBindTexture(GL_TEXTURE_2D, _frameTextureID);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, _frameWidth, _frameHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, 0);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glBindTexture(GL_TEXTURE_2D, 0);
glBindTexture(GL_TEXTURE_2D, 0);
}
Webcam::~Webcam() {
@ -43,7 +46,6 @@ void Webcam::grabFrame() {
if (image == 0) {
return;
}
glBindTexture(GL_TEXTURE_2D, _frameTextureID);
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, _frameWidth, _frameHeight, GL_RGB, GL_UNSIGNED_BYTE, image->imageData);
glBindTexture(GL_TEXTURE_2D, 0);
}

View file

@ -19,6 +19,8 @@ public:
Webcam();
~Webcam();
void init();
int getFrameWidth() const { return _frameWidth; }
int getFrameHeight() const { return _frameHeight; }
float getFrameAspectRatio() const { return _frameWidth / (float)_frameHeight; }