Displaying chart. Can optionally set resolution. Bird is stretched, though
This commit is contained in:
parent
f982e4721d
commit
1de574af6d
26
main.cpp
26
main.cpp
|
@ -20,7 +20,6 @@ using namespace std;
|
||||||
using namespace std::chrono;
|
using namespace std::chrono;
|
||||||
using time_stamp = time_point<system_clock, microseconds>;
|
using time_stamp = time_point<system_clock, microseconds>;
|
||||||
|
|
||||||
Mat image;
|
|
||||||
GLuint imageTexture;
|
GLuint imageTexture;
|
||||||
GLint screenWidth = 0;
|
GLint screenWidth = 0;
|
||||||
GLint screenHeight = 0;
|
GLint screenHeight = 0;
|
||||||
|
@ -29,25 +28,27 @@ time_stamp ts;
|
||||||
void loadTexture (GLuint& imageTexture1)
|
void loadTexture (GLuint& imageTexture1)
|
||||||
{
|
{
|
||||||
string image_path = samples::findFile("chart.png");
|
string image_path = samples::findFile("chart.png");
|
||||||
Mat image = imread(image_path, IMREAD_COLOR);
|
Mat loaded = imread(image_path, IMREAD_COLOR);
|
||||||
|
Mat image = Mat::zeros(screenWidth, screenHeight, CV_8UC3);
|
||||||
|
cout << "created image" << endl;
|
||||||
if (image.empty()) {
|
if (image.empty()) {
|
||||||
cout << "image empty" << endl;
|
cout << "image empty" << endl;
|
||||||
} else {
|
} else {
|
||||||
cout << "loaded " << image_path << endl;
|
cout << "loaded " << image_path << endl;
|
||||||
flip(image, image, 0);
|
cout << " dim " << loaded.cols << "x" << loaded.rows << endl;
|
||||||
|
loaded.copyTo(image(Rect(0, 0, loaded.cols, loaded.rows)));
|
||||||
|
//flip(image, image, 0);
|
||||||
#if (CV_VERSION_MAJOR >= 4)
|
#if (CV_VERSION_MAJOR >= 4)
|
||||||
cvtColor(image, image, cv::COLOR_BGR2RGB);
|
cvtColor(image, image, cv::COLOR_BGR2RGB);
|
||||||
#else
|
#else
|
||||||
cvtColor(image, image, CV_BGR2RGB);
|
cvtColor(image, image, CV_BGR2RGB);
|
||||||
#endif
|
#endif
|
||||||
//glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
|
|
||||||
glGenTextures(1, &imageTexture1);
|
glGenTextures(1, &imageTexture1);
|
||||||
glBindTexture(GL_TEXTURE_2D, imageTexture1);
|
glBindTexture(GL_TEXTURE_2D, imageTexture1);
|
||||||
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||||
|
|
||||||
// Set texture clamping method
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
|
||||||
|
|
||||||
|
@ -60,6 +61,7 @@ void loadTexture (GLuint& imageTexture1)
|
||||||
GL_RGB, // Input image format (i.e. GL_RGB, GL_RGBA, GL_BGR etc.)
|
GL_RGB, // Input image format (i.e. GL_RGB, GL_RGBA, GL_BGR etc.)
|
||||||
GL_UNSIGNED_BYTE, // Image data type
|
GL_UNSIGNED_BYTE, // Image data type
|
||||||
image.ptr()); // The actual image data itself
|
image.ptr()); // The actual image data itself
|
||||||
|
cout << "display()" << endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,18 +73,18 @@ void getScreenDimensions ()
|
||||||
screenWidth = dims[2];
|
screenWidth = dims[2];
|
||||||
screenHeight = dims[3];
|
screenHeight = dims[3];
|
||||||
cout << screenWidth << "," << screenHeight << endl;
|
cout << screenWidth << "," << screenHeight << endl;
|
||||||
loadTexture(imageTexture);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void display(void)
|
void display(void)
|
||||||
{
|
{
|
||||||
getScreenDimensions();
|
getScreenDimensions();
|
||||||
|
loadTexture(imageTexture);
|
||||||
ts = time_point_cast<microseconds>(system_clock::now());
|
ts = time_point_cast<microseconds>(system_clock::now());
|
||||||
|
|
||||||
glClear(GL_COLOR_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
glEnable(GL_TEXTURE_2D);
|
glEnable(GL_TEXTURE_2D);
|
||||||
//glViewport(0, 0, screenWidth, screenHeight);
|
glViewport(0, 0, screenWidth, screenHeight);
|
||||||
glMatrixMode(GL_PROJECTION);
|
glMatrixMode(GL_PROJECTION);
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
|
|
||||||
|
@ -102,6 +104,16 @@ void display(void)
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
|
if (argc > 1)
|
||||||
|
{
|
||||||
|
screenWidth = atoi(argv[1]);
|
||||||
|
cout << "Set width: " << screenWidth << endl;
|
||||||
|
}
|
||||||
|
if (argc > 2)
|
||||||
|
{
|
||||||
|
screenHeight = atoi(argv[2]);
|
||||||
|
cout << "Set height: " << screenHeight << endl;
|
||||||
|
}
|
||||||
glutInit(&argc, argv);
|
glutInit(&argc, argv);
|
||||||
glutInitDisplayMode(GLUT_SINGLE);
|
glutInitDisplayMode(GLUT_SINGLE);
|
||||||
glutCreateWindow("opengl_opencv_example");
|
glutCreateWindow("opengl_opencv_example");
|
||||||
|
|
Loading…
Reference in New Issue