1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
|
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <GL\glut.h>
#include <GL\GL.h>
#include "cv.h"
#include "highgui.h"
GLuint texture; //the array for our texture
IplImage *imagenText1;
GLfloat angle = 0.0;
CvCapture *capture;
//The IplImage to OpenGl texture function
int loadTexture_Ipl(IplImage *image, GLuint *text) {
if (image==NULL) return -1;
glGenTextures(1, text);
glBindTexture( GL_TEXTURE_2D, *text ); //bind the texture to it's array
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, image->width, image->height,0, GL_BGR_EXT, GL_UNSIGNED_BYTE, image->imageData);
return 0;
}
void plane (void) {
glBindTexture( GL_TEXTURE_2D, texture ); //bind the texture
glBegin (GL_QUADS);
glTexCoord2d(0.0,0.0); glVertex2d(0.0,480.0); //with our vertices we have to assign a texcoord
glTexCoord2d(0.0,1.0); glVertex2d(0.0, 0.0); //so that our texture has some points to draw to
glTexCoord2d(1.0,1.0); glVertex2d(640.0, 0.0);
glTexCoord2d(1.0,0.0); glVertex2d(640.0, 480.0);
glEnd();
}
void display (void) {
glClearColor (0.0,0.0,0.0,1.0);
glClear (GL_COLOR_BUFFER_BIT);
glLoadIdentity();
//gluLookAt (0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
gluLookAt(0.0, 0.0, 5.0, 320.0, 240.0, 0.0, 0.0, 1.0, 0.0);
glEnable( GL_TEXTURE_2D ); //enable 2D texturing
plane();
imagenText1=cvQueryFrame(capture);
loadTexture_Ipl( imagenText1, &texture );
glutSwapBuffers();
}
void FreeTexture( GLuint texture )
{
glDeleteTextures( 1, &texture );
}
void reshape (int w, int h) {
glViewport (0, 0, (GLsizei)w, (GLsizei)h);
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
gluPerspective (60, (GLfloat)w / (GLfloat)h, 1.0, 100.0);
glMatrixMode (GL_MODELVIEW);
}
int main (int argc, char **argv) {
glutInit (&argc, argv);
glutInitDisplayMode (GLUT_RGB | GLUT_DOUBLE);
glutInitWindowSize(640, 480);
glutInitWindowPosition (100, 100);
glutCreateWindow ("A basic OpenGL Window");
glOrtho(0.0, 640.0, 480.0, 0.0, -1.0, 1.0);
glutDisplayFunc (display);
glutIdleFunc (display);
glutReshapeFunc (reshape);
glMatrixMode(GL_TEXTURE);
glLoadIdentity();
glScalef(-1.0f, -1.0f, 1.0f);
glMatrixMode(GL_MODELVIEW);
capture = cvCreateCameraCapture(CV_CAP_ANY);
char key = NULL;
int i=0;
glutMainLoop ();
//Free our texture
FreeTexture( texture );
return 0;
} |
Partager