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