opengl全景图转换为天空盒图(成功)

前面哪个opengl程序实际上已经快成功了,只差一点点了。

发现只要前、后图对换,左、右图对换就可以了

所以这里除了对换外,把哪个要按2次键才能截到正确的图也改一下(延时)

具体看代码吧:

//53 全景球贴图 切分6图  
  
//左键(+ 移动)旋转,右键(+ 移动)缩放 1,2,3,4 切换地图,回车键(enter)全屏切换,按w、a、s、d、f、x、切换视角并截图  

#pragma comment( lib, "opengl32.lib" )                
#pragma comment( lib, "glut32.lib")
#include <GL/glut.h>
#include <GL/glu.h>
#include <math.h>       
#include <cstdlib>
#include <string>

#include "ArcBall.h"      
#include "Sky.h"

CSky m_sky;

void setWidthHeight(GLint width ,GLint height);
void screenshot(char* FileName);  //全窗口

int BuildTexture(char *szPathName, GLuint &texid);

//初始化,必须用全局变量的方式,不能用new
ArcBallT arcBall(600.0f,400.0f);
ArcBallT*    ArcBall =&arcBall;// new ArcBallT(600.0f,400.0f);//&arcBall;
#define PI 3.141592654

GLuint SkyTexture[10];//纹理
int width,height;//屏幕宽高
	int R=100;//地图球半径
	std::string direction;//方向
	bool Shot=false;

void reshape(int w, int h){
    glViewport(0,0, w, h);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
	//GLdouble zNear=R*cos(PI/2);
    gluPerspective(90.0f, (GLfloat)w / (GLfloat)h, 6.5f, R*2);//zNear
    glMatrixMode(GL_MODELVIEW);
    ball
    ArcBall->setBounds((GLfloat)w, (GLfloat)h);//1. 设置窗口边界
}
void init(){
    glClearColor(0.0f, 0.0f, 0.0f, 0.5f);
    glClearDepth(1.0f);
    glD
  • 1
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
将 RGB 转换为 MP4 视频可以使用 OpenCV 库中的 VideoWriter 类。VideoWriter 类可以将一系列像帧编码为视频格式,并将其保存为文件。 在 C++ 中使用 OpenGL ES 和 OpenCV,您可以将像或视频帧从 OpenGL 纹理中复制到内存中,然后将其写入 VideoWriter 对象中,以将其编码为视频。 具体实现步骤如下: 1. 使用 OpenGL ES 创建纹理对象,并将 RGB 像数据绑定到纹理上。 2. 使用 OpenCV 中的 cv::Mat 类创建一个与纹理大小相同的矩阵。 3. 使用 glReadPixels 将纹理数据读取到 cv::Mat 对象中。 4. 使用 VideoWriter 类将 cv::Mat 对象中的像帧编码为视频,并将其保存到文件中。 以下是代码示例: ```c++ #include <opencv2/opencv.hpp> #include <GLES3/gl3.h> using namespace cv; int main() { // 创建 OpenGL 纹理对象并绑定 RGB 像数据 GLuint textureId; glGenTextures(1, &textureId); glBindTexture(GL_TEXTURE_2D, textureId); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, data); // 创建 OpenCV Mat 对象 Mat frame(height, width, CV_8UC3); // 读取纹理数据到 Mat 对象中 glReadPixels(0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE, frame.data); // 创建 VideoWriter 对象并将像帧编码为视频 VideoWriter writer("output.mp4", VideoWriter::fourcc('X','2','6','4'), fps, Size(width, height)); writer.write(frame); // 释放资源 writer.release(); glDeleteTextures(1, &textureId); return 0; } ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值