opengl 的贴图功能是很基本的,不过也难住了我这个新手,所以特意写了一个示例程序,以便以后查阅。
程序很简单,只是在在 x, y 平面画一个框,然后贴上一张图。并且可以保存opengl窗口到图片。
程序:
//本程序的目的是展示贴图和保存图片
#include <Windows.h>
#include <gl/glut.h>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
using namespace cv;
// Rotation amounts
static GLfloat xRot = 0.0f;
static GLfloat yRot = 0.0f;
const int height = 600;
const int width = 800;
static GLbyte TextData[1000*1000*4];
static GLuint TexName;
static int picrows = 0;
static int piccols = 0;
void savepic()
{
GLint viewPort[4] = {0};
glGetIntegerv(GL_VIEWPORT, viewPort);
int winrows = viewPort[3];
int wincols = viewPort[2];
GLbyte *colorArr = new GLbyte[winrows*wincols*3];
glReadPixels(viewPort[0], viewPort[1], viewPort[2], viewPo