PDA

View Full Version : Texture



afrochan
02-27-2016, 01:41 PM
Hello everyone this is my second time posting on here, and I did learn a lot from my last time so hopefully this time will be the same

I am working on opengl and opencv kinda at the same time right now. The main use of opencv in this project is to provide texture to my object that I will create in opengl and it could be a video or an image.

when I run the code it work, However, the texture doesn't show the image and I try the operation with both glTextImage2D and gluBuild2DMipmaps without result


I have copied the entire code below

I run it on visual studio 2013, in order for it to run first

-right click the project
-go to properties
-characterset should be set at "Not set"


-right click the project
-go to manage nuget
-type glut in the search box and install the very first one


-right click the project
-go to manage nuget
-type opencv in the search box and install the first one

all the necessary header are included

thanks in advance



#include "stdafx.h"
#include "GL\glut.h"
#include <iostream>
#include <string>
#include <fstream>
#include "opencv\highgui.h"
#pragma warning (disable:4996)

CvCapture *cp;
IplImage *image;
void loadImage();
GLuint texture;







GLuint texturing_video()
{
cp = cvCreateFileCapture("C:\\Users\\Admin\\Downloads\\I-Miss-You-Avril-Lavigne-with-lyrics.mp4");
if (cp != NULL)
{
image = cvQueryFrame(cp);
GLuint text;
glEnable(GL_TEXTURE_2D);
glGenTextures(1, &text);
glBindTexture(GL_TEXTURE_2D, text);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);

//glTexEnvf(GL_TEXTURE_2D, GL_TEXTURE_ENV_MODE, GL_DECAL);

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
gluBuild2DMipmaps(GL_TEXTURE_2D, 2, 8, 8, GL_LUMINANCE, GL_UNSIGNED_BYTE, image);



//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
//glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 4, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE, image);

return texture;
}
//return texture;
}

GLuint texturing_Image()
{
image = cvLoadImage("G:\\pic\\14weurk.jpg");
GLuint text;
glEnable(GL_TEXTURE_2D);
glGenTextures(1, &text);
glBindTexture(GL_TEXTURE_2D, text);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);

glTexEnvf(GL_TEXTURE_2D, GL_TEXTURE_ENV_MODE, GL_DECAL);

//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_LINEAR);
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);

//gluBuild2DMipmaps(GL_TEXTURE_2D, 1, 68, 68, GL_RGB, GL_UNSIGNED_BYTE, image);



glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 4, 4, 0, GL_BGR_EXT, GL_UNSIGNED_BYTE, image);
return text;
}

void loadImage()
{

//cvNamedWindow("helloworld", CV_WINDOW_AUTOSIZE);
//cvShowImage("helloworld", image);
//cvWaitKey(0);
//cvDestroyWindow("helloworld");
}


void display(void){

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClearColor(1, 1, 1, 1);


texture=texturing_video();
//glBindTexture(GL_TEXTURE_2D,texture);

glutSolidTeapot(1.0);

glBindTexture(GL_TEXTURE_2D, texture);

glBegin(GL_QUADS);

glTexCoord2f(0.0, 0.0);

glVertex3f(1.0, -1.0, 0.0);

glTexCoord2f(1.0, 0.0);

glVertex3f(1.0, 1.0, 0.0);

glTexCoord2f(1.0, 1.0);

glVertex3f(2.41421, 1.0, -1.41421);

glTexCoord2f(1.0, .0);

glVertex3f(2.41421, -1.0, -1.41421);

glEnd();

glutSwapBuffers();

}


void myReshape(int w, int h){

glViewport(0, 0, w, h);

glMatrixMode(GL_PROJECTION);

glLoadIdentity();

gluPerspective(60.0, 1.0*(GLfloat)w / (GLfloat)h, 1.0, 30.0);

glMatrixMode(GL_MODELVIEW);

glLoadIdentity();

glTranslatef(0.0, 0.0, -3.6);

}





int main(int argc, char** argv)

{

glutInit(&argc, argv);

glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);

glutCreateWindow("Texture Mapping - Programming Techniques");


glutReshapeFunc(myReshape);

glutDisplayFunc(display);

glutMainLoop();


return 0;

}

BinaryFissionGames
02-28-2016, 04:46 AM
So, here's some fixed code, any comments that have to exclamation marks after them are where I changed things, and hopefully you can understand what I've done from the comments. The main mistake you made in this code is using your "image" variable as raw image data, when it's a structure that contains the image data.


#include "stdafx.h"
#include "GL\glut.h"
#include <iostream>
#include <string>
#include <fstream>
#include "opencv\highgui.h"
#pragma warning (disable:4996)

CvCapture *cp;
IplImage *image;
void loadImage();
GLuint texture;

GLuint texturing_video()
{
cp = cvCreateFileCapture("C:\\Users\\Admin\\Downloads\\ I-Miss-You-Avril-Lavigne-with-lyrics.mp4");
if (cp != NULL)
{
image = cvQueryFrame(cp);
GLuint text;
glEnable(GL_TEXTURE_2D);
glGenTextures(1, &text);
glBindTexture(GL_TEXTURE_2D, text);

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);

//glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, image->width, image->height, 0, GL_RGBA, GL_UNSIGNED_BYTE, image->imageData);
//glTexEnvf(GL_TEXTURE_2D, GL_TEXTURE_ENV_MODE, GL_DECAL);

//!! I changed this to 3 components, change it back to 2 for black and white images
//!! notice the usage of image->imageData, not image. Also, I use the width and height from the struct you got from cvQueryFrame.
gluBuild2DMipmaps(GL_TEXTURE_2D, 3, image->width, image->height, GL_RGB, GL_UNSIGNED_BYTE, image->imageData);


//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
//glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, image->width, image->height, 0, GL_BGR_EXT, GL_UNSIGNED_BYTE, image->imageData);

return text; // !! return the actual variable, not the global variable texture
}
return 0; //!! Return 0 if you have an invalid texture, it's a pretty distinct number for texIDs
}

GLuint texturing_Image()
{
image = cvLoadImage("G:\\pic\\14weurk.jpg");
GLuint text;
glEnable(GL_TEXTURE_2D);
glGenTextures(1, &text);
glBindTexture(GL_TEXTURE_2D, text);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);

glTexEnvf(GL_TEXTURE_2D, GL_TEXTURE_ENV_MODE, GL_DECAL);

//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_LINEAR);
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);

//gluBuild2DMipmaps(GL_TEXTURE_2D, 1, 68, 68, GL_RGB, GL_UNSIGNED_BYTE, image);



glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
//!! notice the usage of image->imageData, not image. Also, I use the width and height from the struct you got from cvLoadImage.
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, image->width, image->height, 0, GL_BGR_EXT, GL_UNSIGNED_BYTE, image->imageData);
return text;
}

void loadImage()
{

//cvNamedWindow("helloworld", CV_WINDOW_AUTOSIZE);
//cvShowImage("helloworld", image);
//cvWaitKey(0);
//cvDestroyWindow("helloworld");
}


void display(void) {

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClearColor(1, 1, 1, 1);

texture = texturing_video();
glBindTexture(GL_TEXTURE_2D,texture);
//glBindTexture(GL_TEXTURE_2D,0);//!! Uncomment this to take the texture off the teapot.
glutSolidTeapot(1.0);

//glBindTexture(GL_TEXTURE_2D, texture); //!! Uncomment this if you took the texture off the teapot.
//!! notice that I changed the texture coordinates around. In openGL, the upper left corner of the texture is u=0, v=0. the lower left is u=0, v=1, and so on.
//!! I also re-arranged the vertices to go counterclockwise, which is how Opengl likes them by default.
glBegin(GL_QUADS);
glTexCoord2f(0.0, 1.0);

glVertex3f(1.0, -1.0, 0.0);

glTexCoord2f(1.0, 1.0);

glVertex3f(2.41421, -1.0, -1.41421);

glTexCoord2f(1.0, 0.0);

glVertex3f(2.41421, 1.0, -1.41421);

glTexCoord2f(0.0, 0.0);

glVertex3f(1.0, 1.0, 0.0);

glEnd();

glutSwapBuffers();

}


void myReshape(int w, int h) {

glViewport(0, 0, w, h);

glMatrixMode(GL_PROJECTION);

glLoadIdentity();

gluPerspective(60.0, 1.0*(GLfloat)w / (GLfloat)h, 1.0, 30.0);

glMatrixMode(GL_MODELVIEW);

glLoadIdentity();

glTranslatef(0.0, 0.0, -3.6);

}





int main(int argc, char** argv)

{

glutInit(&argc, argv);

glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);

glutCreateWindow("Texture Mapping - Programming Techniques");


glutReshapeFunc(myReshape);

glutDisplayFunc(display);

glutMainLoop();


return 0;

}

afrochan
02-28-2016, 06:18 AM
So, here's some fixed code, any comments that have to exclamation marks after them are where I changed things, and hopefully you can understand what I've done from the comments. The main mistake you made in this code is using your "image" variable as raw image data, when it's a structure that contains the image data.


#include "stdafx.h"
#include "GL\glut.h"
#include <iostream>
#include <string>
#include <fstream>
#include "opencv\highgui.h"
#pragma warning (disable:4996)

CvCapture *cp;
IplImage *image;
void loadImage();
GLuint texture;

GLuint texturing_video()
{
cp = cvCreateFileCapture("C:\\Users\\Admin\\Downloads\\ I-Miss-You-Avril-Lavigne-with-lyrics.mp4");
if (cp != NULL)
{
image = cvQueryFrame(cp);
GLuint text;
glEnable(GL_TEXTURE_2D);
glGenTextures(1, &text);
glBindTexture(GL_TEXTURE_2D, text);

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);

//glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, image->width, image->height, 0, GL_RGBA, GL_UNSIGNED_BYTE, image->imageData);
//glTexEnvf(GL_TEXTURE_2D, GL_TEXTURE_ENV_MODE, GL_DECAL);

//!! I changed this to 3 components, change it back to 2 for black and white images
//!! notice the usage of image->imageData, not image. Also, I use the width and height from the struct you got from cvQueryFrame.
gluBuild2DMipmaps(GL_TEXTURE_2D, 3, image->width, image->height, GL_RGB, GL_UNSIGNED_BYTE, image->imageData);


//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
//glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, image->width, image->height, 0, GL_BGR_EXT, GL_UNSIGNED_BYTE, image->imageData);

return text; // !! return the actual variable, not the global variable texture
}
return 0; //!! Return 0 if you have an invalid texture, it's a pretty distinct number for texIDs
}

GLuint texturing_Image()
{
image = cvLoadImage("G:\\pic\\14weurk.jpg");
GLuint text;
glEnable(GL_TEXTURE_2D);
glGenTextures(1, &text);
glBindTexture(GL_TEXTURE_2D, text);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);

glTexEnvf(GL_TEXTURE_2D, GL_TEXTURE_ENV_MODE, GL_DECAL);

//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_LINEAR);
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);

//gluBuild2DMipmaps(GL_TEXTURE_2D, 1, 68, 68, GL_RGB, GL_UNSIGNED_BYTE, image);



glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
//!! notice the usage of image->imageData, not image. Also, I use the width and height from the struct you got from cvLoadImage.
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, image->width, image->height, 0, GL_BGR_EXT, GL_UNSIGNED_BYTE, image->imageData);
return text;
}

void loadImage()
{

//cvNamedWindow("helloworld", CV_WINDOW_AUTOSIZE);
//cvShowImage("helloworld", image);
//cvWaitKey(0);
//cvDestroyWindow("helloworld");
}


void display(void) {

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClearColor(1, 1, 1, 1);

texture = texturing_video();
glBindTexture(GL_TEXTURE_2D,texture);
//glBindTexture(GL_TEXTURE_2D,0);//!! Uncomment this to take the texture off the teapot.
glutSolidTeapot(1.0);

//glBindTexture(GL_TEXTURE_2D, texture); //!! Uncomment this if you took the texture off the teapot.
//!! notice that I changed the texture coordinates around. In openGL, the upper left corner of the texture is u=0, v=0. the lower left is u=0, v=1, and so on.
//!! I also re-arranged the vertices to go counterclockwise, which is how Opengl likes them by default.
glBegin(GL_QUADS);
glTexCoord2f(0.0, 1.0);

glVertex3f(1.0, -1.0, 0.0);

glTexCoord2f(1.0, 1.0);

glVertex3f(2.41421, -1.0, -1.41421);

glTexCoord2f(1.0, 0.0);

glVertex3f(2.41421, 1.0, -1.41421);

glTexCoord2f(0.0, 0.0);

glVertex3f(1.0, 1.0, 0.0);

glEnd();

glutSwapBuffers();

}


void myReshape(int w, int h) {

glViewport(0, 0, w, h);

glMatrixMode(GL_PROJECTION);

glLoadIdentity();

gluPerspective(60.0, 1.0*(GLfloat)w / (GLfloat)h, 1.0, 30.0);

glMatrixMode(GL_MODELVIEW);

glLoadIdentity();

glTranslatef(0.0, 0.0, -3.6);

}





int main(int argc, char** argv)

{

glutInit(&argc, argv);

glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);

glutCreateWindow("Texture Mapping - Programming Techniques");


glutReshapeFunc(myReshape);

glutDisplayFunc(display);

glutMainLoop();


return 0;

}



Thanks a bunch, the function for the image work perfectly right now. But I don't know why the video is now working, I copied and pasted the code just as it, and thanks for pointing out "image->imagedata" I tried using image->heigh/width in earlier version but the page will just go white


yet thanks again for the changes,

BinaryFissionGames
02-28-2016, 12:39 PM
If your video code isn't working, it's probably because the file path you entered is incorrect.
Maybe you meant to use "C:\\Users\\Admin\\Downloads\\I-Miss-You-Avril-Lavigne-with-lyrics.mp4" instead of "C:\\Users\\Admin\\Downloads\\ I-Miss-You-Avril-Lavigne-with-lyrics.mp4"?

afrochan
02-28-2016, 03:39 PM
If your video code isn't working, it's probably because the file path you entered is incorrect.
Maybe you meant to use "C:\\Users\\Admin\\Downloads\\I-Miss-You-Avril-Lavigne-with-lyrics.mp4" instead of "C:\\Users\\Admin\\Downloads\\ I-Miss-You-Avril-Lavigne-with-lyrics.mp4"?

I have change it to your specification which mean I have eliminated the space and I even try to move the video to another file but it is still not working

afrochan
03-01-2016, 12:49 PM
If your video code isn't working, it's probably because the file path you entered is incorrect.
Maybe you meant to use "C:\\Users\\Admin\\Downloads\\I-Miss-You-Avril-Lavigne-with-lyrics.mp4" instead of "C:\\Users\\Admin\\Downloads\\ I-Miss-You-Avril-Lavigne-with-lyrics.mp4"?

Once again thank for the code you have provided me and I did some research after your post

I came across a code people might be interested (it is not MINE) not taking credit for it just posting it so that in case some one have the same problem they can refer to this code


GLfloat angle = 0.0;
GLuint listIndex;
GLuint texture;
CvCapture* capture;

GLuint ConvertIplToTexture(IplImage *image)
{
GLuint texture;

glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture);
/*glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_D ECAL);
glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTE R,GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTE R,GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL _REPEAT);
glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL _REPEAT);*/
gluBuild2DMipmaps(GL_TEXTURE_2D, 3, image->width, image->height,
GL_BGR_EXT, GL_UNSIGNED_BYTE, image->imageData);

return texture;
}

GLvoid DrawCube()
{
IplImage* frame;
frame = cvQueryFrame(capture);
texture = ConvertIplToTexture(frame);

glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texture);
glCallList(listIndex);
glDisable(GL_TEXTURE_2D);
}


void init(){
glEnable(GL_DEPTH_TEST);
glClearColor(0.0, 0.0, 0.0, 1.0);
}

void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
gluLookAt(0.0, 2.0, 1.5, 0.0, 0.0, -0.5, 0.0, -1.0, 0.0);

glRotatef(angle, 0.0, 1.0, 0.0);

DrawCube();

angle += 1.0;
glutSwapBuffers();

}

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);
}


//void keyboard(unsigned char key, int x, int y)
//{
// switch (key){
// case 27: case 'q':
// exit(0);
// break;
// }
//}


void initialize_opencv(){
capture = cvCreateFileCapture("G:\\Video_Music\\psquarefriend.mp4");
//capture = cvCaptureFromCAM(CV_CAP_ANY);
//IplImage *image = cvLoadImage("/home/luca/Scrivania/Uni/2 Magistrale/2 Anno/1 Ambienti Virtuali, Interattiva e Videogiochi/OpenGL/WorkSpace/Open Portal/texture/cube.png");
//texture = ConvertIplToTexture(image);
//cvReleaseImage(&image);

GLfloat vert[48] =
{ -0.5f, 0.0f, 0.5f, 0.5f, 0.0f, 0.5f, 0.5f, 1.0f, 0.5f, -0.5f, 1.0f, 0.5f,
-0.5f, 1.0f, -0.5f, 0.5f, 1.0f, -0.5f, 0.5f, 0.0f, -0.5f, -0.5f, 0.0f, -0.5f,
0.5f, 0.0f, 0.5f, 0.5f, 0.0f, -0.5f, 0.5f, 1.0f, -0.5f, 0.5f, 1.0f, 0.5f,
-0.5f, 0.0f, -0.5f, -0.5f, 0.0f, 0.5f, -0.5f, 1.0f, 0.5f, -0.5f, 1.0f, -0.5f
};

GLfloat texcoords[32] = { 0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0,
0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0,
0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0,
0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0
};

GLubyte cubeIndices[24] = { 0, 1, 2, 3, 4, 5, 6, 7, 3, 2, 5, 4, 7, 6, 1, 0, 8, 9, 10, 11, 12, 13, 14, 15 };

listIndex = glGenLists(1);
glNewList(listIndex, GL_COMPILE);

glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glEnableClientState(GL_VERTEX_ARRAY);

glTexCoordPointer(2, GL_FLOAT, 0, texcoords);
glVertexPointer(3, GL_FLOAT, 0, vert);

glDrawElements(GL_QUADS, 24, GL_UNSIGNED_BYTE, cubeIndices);
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glEndList();
}

int main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);
glutInitWindowSize(800, 600);
glutInitWindowPosition(100, 100);
glutCreateWindow("Cubi Rotanti con luce");

glEnable(GL_CULL_FACE);
initialize_opencv();
init();
glutDisplayFunc(display);
// glutKeyboardFunc(keyboard);
glutIdleFunc(display);
glutReshapeFunc(reshape);
glutMainLoop();
}