啄木鸟图形库的顶点封装类测试代码

2023-10-30 21:20

本文主要是介绍啄木鸟图形库的顶点封装类测试代码,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

啄木鸟图形库的顶点封装类测试代码,分别使用VBO和非VBO的形式实现ArrayOfStructs以及StructsOfArrays这两种顶点数据结构。CVertexIndexDrawArrayGLES2类将提供顶点的相关操作。通过配置VEXIDXDRAWITEM的值配置顶点缓冲,这个以后可以通过模型文件进行集中初始化。

效果图:

 shader的代码,使用GLSL ES 1.0搞的 (OPENGLES 2.0的程序不看shader还真的不知道具体怎么画的)

static const Char strVertexShader[] ="attribute vec4 aPosition;\n""attribute vec4 aColor;\n""uniform  mat4 uFixedViewMatrix;\n""varying vec4 vColor;\n""void main() {\n""gl_Position =  uFixedViewMatrix * aPosition;\n""vColor = aColor;""}\n";static const Char strFragmentShader[] ="precision mediump float;\n""varying vec4 vColor;\n""void main() {\n""gl_FragColor = vColor;\n""}\n";

测试程序主窗体代码

class CTestForm : public CPeckerActivityForm{
private:IPeckerCGDriver* m_pCGDriver;CGPUProgramGLES2 m_ShaderProgram;CVertexIndexDrawArrayGLES2 m_ArrayOfStructsWithOutVBODrawItems;CVertexIndexDrawArrayGLES2 m_StructsOfArraysWithOutVBODrawItems;CVertexIndexDrawArrayGLES2 m_ArrayOfStructsWithVBODrawItems;CVertexIndexDrawArrayGLES2 m_StructsOfArraysWithVBODrawItems;CMatrix4 m_MatView;CMatrix4 m_MatWorld;CMatrix4 m_MatProj;CMatrix4 m_MatScale;CMatrix4 m_MatOgMvp;UInt m_MvpMatHandle;typedef struct stVecCoord{Vector4f pos;Vector3f color;} VECCOR;
public:CTestForm(){m_pCGDriver = CPeckerCGDrivers::GetCGDriver();}virtual ~CTestForm(){;}virtual HResult InitDisplay(int w, int h){if (null == m_pCGDriver){return P_ERR;}static const VECCOR vecClr[] ={{{ -0.5f, 0.0f, 0.0f, 1.0f },{ 0.0f, 0.0f, 0.0f } },{{ -0.5f, 1.0f, 0.0f, 1.0f },{ 0.0f, 1.0f, 0.0f } },{{ 0.5f, 0.0f, 0.0f, 1.0f },{ 1.0f, 0.0f, 0.0f } },{{ 0.5f, 1.0f, 0.0f, 1.0f },{ 1.0f, 1.0f, 1.0f } } };static const GLfloat fPos[] ={ -0.5f, 0.0f, 0.0f, 1.0f, -0.5f, 1.0f, 0.0f, 1.0f, 0.5f, 0.0f, 0.0f,1.0f, 0.5f, 1.0f, 0.0f, 1.0f };static const GLfloat fColor[] ={ 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f,1.0f, 1.0f };m_ArrayOfStructsWithOutVBODrawItems.ClearDrawItem();VEXIDXDRAWITEM drawItem;// only vertex;//ArrayOfStructsdrawItem.m_BuffID = 0;drawItem.m_BuffTargetType = PG_ARRAY_BUFFER;drawItem.m_BuffUseType = PG_STATIC_DRAW;drawItem.m_DrawData = vecClr;drawItem.m_DrawBufLen = sizeof(vecClr);drawItem.m_FVFFormat = 0;drawItem.m_bNormalized = false;drawItem.m_nDataFormat = PG_FLOAT;drawItem.m_nAttrDataCount = 4;drawItem.m_nShaderAttrID = 0;drawItem.m_nOffset = 0;drawItem.m_Stride = sizeof(VECCOR);m_ArrayOfStructsWithOutVBODrawItems.AddDrawItem(drawItem);drawItem.m_BuffID = 0;drawItem.m_BuffTargetType = PG_ARRAY_BUFFER;drawItem.m_BuffUseType = PG_STATIC_DRAW;drawItem.m_DrawData = vecClr;drawItem.m_DrawBufLen = sizeof(vecClr);drawItem.m_FVFFormat = 0;drawItem.m_bNormalized = false;drawItem.m_nDataFormat = PG_FLOAT;drawItem.m_nAttrDataCount = 3;drawItem.m_nShaderAttrID = 1;drawItem.m_nOffset = sizeof(Vector4f);drawItem.m_Stride = sizeof(VECCOR);m_ArrayOfStructsWithOutVBODrawItems.AddDrawItem(drawItem);m_ArrayOfStructsWithOutVBODrawItems.InitDrawArray(NORMAL_VERTEX_DRAWITEM_MODE);//StructsOfArraysm_StructsOfArraysWithOutVBODrawItems.ClearDrawItem();drawItem.m_BuffID = 0;drawItem.m_BuffTargetType = PG_ARRAY_BUFFER;drawItem.m_BuffUseType = PG_STATIC_DRAW;drawItem.m_DrawData = fPos;drawItem.m_DrawBufLen = sizeof(fPos);drawItem.m_FVFFormat = 0;drawItem.m_bNormalized = false;drawItem.m_nDataFormat = PG_FLOAT;drawItem.m_nAttrDataCount = 4;drawItem.m_nShaderAttrID = 0;drawItem.m_nOffset = 0;drawItem.m_Stride = sizeof(Vector4f);m_StructsOfArraysWithOutVBODrawItems.AddDrawItem(drawItem);drawItem.m_BuffID = 0;drawItem.m_BuffTargetType = PG_ARRAY_BUFFER;drawItem.m_BuffUseType = PG_STATIC_DRAW;drawItem.m_DrawData = fColor;drawItem.m_DrawBufLen = sizeof(fColor);drawItem.m_FVFFormat = 0;drawItem.m_bNormalized = false;drawItem.m_nDataFormat = PG_FLOAT;drawItem.m_nAttrDataCount = 3;drawItem.m_nShaderAttrID = 1;drawItem.m_nOffset = 0;drawItem.m_Stride = sizeof(Vector3f);m_StructsOfArraysWithOutVBODrawItems.AddDrawItem(drawItem);m_StructsOfArraysWithOutVBODrawItems.InitDrawArray(NORMAL_VERTEX_DRAWITEM_MODE);//VBO ArrayOfStructsm_ArrayOfStructsWithVBODrawItems.ClearDrawItem();glGenBuffers(1, &(drawItem.m_BuffID));drawItem.m_BuffTargetType = PG_ARRAY_BUFFER;drawItem.m_BuffUseType = PG_STATIC_DRAW;drawItem.m_DrawData = vecClr;drawItem.m_DrawBufLen = sizeof(vecClr);drawItem.m_FVFFormat = 0;drawItem.m_bNormalized = false;drawItem.m_nDataFormat = PG_FLOAT;drawItem.m_nAttrDataCount = 4;drawItem.m_nShaderAttrID = 0;drawItem.m_nOffset = 0;drawItem.m_Stride = sizeof(VECCOR);m_ArrayOfStructsWithVBODrawItems.AddDrawItem(drawItem);glGenBuffers(1, &(drawItem.m_BuffID));drawItem.m_BuffTargetType = PG_ARRAY_BUFFER;drawItem.m_BuffUseType = PG_STATIC_DRAW;drawItem.m_DrawData = vecClr;drawItem.m_DrawBufLen = sizeof(vecClr);drawItem.m_FVFFormat = 0;drawItem.m_bNormalized = false;drawItem.m_nDataFormat = PG_FLOAT;drawItem.m_nAttrDataCount = 3;drawItem.m_nShaderAttrID = 1;drawItem.m_nOffset = sizeof(Vector4f);drawItem.m_Stride = sizeof(VECCOR);m_ArrayOfStructsWithVBODrawItems.AddDrawItem(drawItem);m_ArrayOfStructsWithVBODrawItems.InitDrawArray(VERTEX_VBO_DRAWITEM_MODE);//VBO StructsOfArraysm_StructsOfArraysWithVBODrawItems.ClearDrawItem();glGenBuffers(1, &(drawItem.m_BuffID));drawItem.m_BuffTargetType = PG_ARRAY_BUFFER;drawItem.m_BuffUseType = PG_STATIC_DRAW;drawItem.m_DrawData = fPos;drawItem.m_DrawBufLen = sizeof(fPos);drawItem.m_FVFFormat = 0;drawItem.m_bNormalized = false;drawItem.m_nDataFormat = PG_FLOAT;drawItem.m_nAttrDataCount = 4;drawItem.m_nShaderAttrID = 0;drawItem.m_nOffset = 0;drawItem.m_Stride = sizeof(Vector4f);m_StructsOfArraysWithVBODrawItems.AddDrawItem(drawItem);glGenBuffers(1, &(drawItem.m_BuffID));drawItem.m_BuffTargetType = PG_ARRAY_BUFFER;drawItem.m_BuffUseType = PG_STATIC_DRAW;drawItem.m_DrawData = fColor;drawItem.m_DrawBufLen = sizeof(fColor);drawItem.m_FVFFormat = 0;drawItem.m_bNormalized = false;drawItem.m_nDataFormat = PG_FLOAT;drawItem.m_nAttrDataCount = 3;drawItem.m_nShaderAttrID = 1;drawItem.m_nOffset = 0;drawItem.m_Stride = sizeof(Vector3f);m_StructsOfArraysWithVBODrawItems.AddDrawItem(drawItem);m_StructsOfArraysWithVBODrawItems.InitDrawArray(VERTEX_VBO_DRAWITEM_MODE);m_ShaderProgram.CreateShaderSysDefaultProgram(MVP_POS_COLOR_TYPE); //(POS_TYPE);ConstStringChars strUniformIName ={ "uFixedViewMatrix", strlen("uFixedViewMatrix") };m_MvpMatHandle = m_ShaderProgram.GetUniformID(strUniformIName);m_MatView = CMatrix4::LookAtRH(CVector3(0.0f, 0.0f, 5.0f),CVector3(0.0f, 0.0f, 0.0f), CVector3(0.0f, 1.0f, 0.0f));m_MatProj = CMatrix4::PerspectiveFov(PECKER_PI / 4.0f,(float) h / (float) w, 0.01f, 1.0f, true);m_MatWorld = CMatrix4::IdentityMatrix4(); //CMatrix4::RotationZ(-PECKER_PI);m_MatScale = CMatrix4::Scale(0.5f, 0.5f, 1.0f);m_MatOgMvp = m_MatProj * m_MatView * m_MatScale * m_MatWorld;m_pCGDriver->SetContextViewport(0, 0, w, h);return 0;}virtual HResult RenderFrame(struct stOsContextEngine* pContextEngine){if (null == m_pCGDriver){return P_ERR;}UInt iShaderAttr = glGetAttribLocation(m_ShaderProgram.GetProgramID(),"aPosition");m_pCGDriver->ClearColor(0.5f, 0.0f, 1.0f, 1.0f);m_pCGDriver->Clear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);HResult hSelectProRes = m_pCGDriver->SelectGPUProgram(&m_ShaderProgram);if (P_OK == hSelectProRes && P_OK == m_pCGDriver->Begin()){static char logInfo[256];static Float fAngle = 0.0f;CMatrix4 mvp = m_MatOgMvp * CMatrix4::Translation(1.5f, -1.5f, 0.0f);//* CMatrix4::RotationZ(fAngle);fAngle += 0.1f;if (fAngle > 6.29)fAngle = 0.0f;// ArrayOfStructs Without VBOm_ShaderProgram.SetUniformMatrixArray(m_MvpMatHandle, 1,(Matrix4*) mvp.GetData());m_ArrayOfStructsWithOutVBODrawItems.PreArrayDraw();m_ArrayOfStructsWithOutVBODrawItems.DrawVertexArray(PG_TRIANGLE_STRIP, 0, 4);m_ArrayOfStructsWithOutVBODrawItems.FinArrayDraw();// StructsOfArrays Without VBOmvp = m_MatOgMvp * CMatrix4::Translation(1.5f, 1.5f, 0.0f);//* CMatrix4::RotationZ(-fAngle);m_ShaderProgram.SetUniformMatrixArray(m_MvpMatHandle, 1,(Matrix4*) mvp.GetData());m_StructsOfArraysWithOutVBODrawItems.PreArrayDraw();m_StructsOfArraysWithOutVBODrawItems.DrawVertexArray(PG_TRIANGLE_STRIP, 0, 4);m_StructsOfArraysWithOutVBODrawItems.FinArrayDraw();// ArrayOfStructs With VBOmvp = m_MatOgMvp * CMatrix4::Translation(-1.5f, 1.5f, 0.0f);//	* CMatrix4::RotationZ(fAngle);m_ShaderProgram.SetUniformMatrixArray(m_MvpMatHandle, 1,(Matrix4*) mvp.GetData());m_ArrayOfStructsWithVBODrawItems.PreArrayDraw();m_ArrayOfStructsWithVBODrawItems.DrawVertexArray(PG_TRIANGLE_STRIP, 0, 4);m_ArrayOfStructsWithVBODrawItems.FinArrayDraw();// StructsOfArrays With VBOmvp = m_MatOgMvp * CMatrix4::Translation(-1.5f, -1.5f, 0.0f);//* CMatrix4::RotationZ(-fAngle);m_ShaderProgram.SetUniformMatrixArray(m_MvpMatHandle, 1,(Matrix4*) mvp.GetData());m_StructsOfArraysWithVBODrawItems.PreArrayDraw();m_StructsOfArraysWithVBODrawItems.DrawVertexArray(PG_TRIANGLE_STRIP, 0, 4);m_StructsOfArraysWithVBODrawItems.FinArrayDraw();m_pCGDriver->End();}else{static char logInfo[256];sprintf(logInfo, "SelectGPUProgram RES = %X", hSelectProRes);CPeckerLogger::GetSignleton()->LogOut(LOGINFO_ERROR, "RenderFrame",logInfo);}return 0;}//virtual HResult TermDisplay(struct stOsContextEngine* pContextEngine) = 0;virtual HResult SaveState(struct stOsContextEngine* pContextEngine){return 0;}virtual HResult LoadState(struct stOsContextEngine* pContextEngine){return 0;}virtual SInt OnInputEvent(Handle hEventHandle){return 0;}virtual void OnWndCmdProc(struct stOsContextEngine* pContextEngine,Long nCmdCode, Long wPrams){}
};

转载于:https://my.oschina.net/u/253717/blog/80705

这篇关于啄木鸟图形库的顶点封装类测试代码的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/310650

相关文章

GIS图形库更新2024.8.4-9.9

更多精彩内容请访问 dt.sim3d.cn ,关注公众号【sky的数孪技术】,技术交流、源码下载请添加微信:digital_twin123 Cesium 本期发布了1.121 版本。重大新闻,Cesium被Bentley收购。 ✨ 功能和改进 默认启用 MSAA,采样 4 次。若要关闭 MSAA,则可以设置scene.msaaSamples = 1。但是通过比较,发现并没有多大改善。

POJ3041 最小顶点覆盖

N*N的矩阵,有些格子有物体,每次消除一行或一列,最少要几次消灭完。 行i - >列j 连边,表示(i,j)处有物体,即 边表示 物体。 import java.io.BufferedReader;import java.io.InputStream;import java.io.InputStreamReader;import java.io.PrintWriter;impo

JavaSE——封装、继承和多态

1. 封装 1.1 概念      面向对象程序三大特性:封装、继承、多态 。而类和对象阶段,主要研究的就是封装特性。何为封装呢?简单来说就是套壳屏蔽细节 。     比如:对于电脑这样一个复杂的设备,提供给用户的就只是:开关机、通过键盘输入,显示器, USB 插孔等,让用户来和计算机进行交互,完成日常事务。但实际上:电脑真正工作的却是CPU 、显卡、内存等一些硬件元件。

哈希表的封装和位图

文章目录 2 封装2.1 基础框架2.2 迭代器(1)2.3 迭代器(2) 3. 位图3.1 问题引入3.2 左移和右移?3.3 位图的实现3.4 位图的题目3.5 位图的应用 2 封装 2.1 基础框架 文章 有了前面map和set封装的经验,容易写出下面的代码 // UnorderedSet.h#pragma once#include "HashTable.h"

封装MySQL操作时Where条件语句的组织

在对数据库进行封装的过程中,条件语句应该是相对难以处理的,毕竟条件语句太过于多样性。 条件语句大致分为以下几种: 1、单一条件,比如:where id = 1; 2、多个条件,相互间关系统一。比如:where id > 10 and age > 20 and score < 60; 3、多个条件,相互间关系不统一。比如:where (id > 10 OR age > 20) AND sco

OPENGL顶点数组, glDrawArrays,glDrawElements

顶点数组, glDrawArrays,glDrawElements  前两天接触OpenGL ES的时候发现里面没有了熟悉的glBegin(), glEnd(),glVertex3f()函数,取而代之的是glDrawArrays()。有问题问google,终于找到答案:因为OpenGL ES是针对嵌入式设备这些对性能要求比较高的平台,因此把很多影响性能的函数都去掉了,上述的几个函数都被移除了。接

Java封装构造方法

private/public的分装 被public修饰的成员变量或者是成员方法,可以被类的调用对象直接使用 而private修饰的成员变量和方法,不能被类的调用对象使用 例如: 可以看到我们是不能在main方法中直接调用被private修饰的变量 当然我们可以在我们定义的TestMode类中可以定一个方法show,然后在调用show方法实现 这里我们可以清楚了解 private 不光可以修

C++数据结构重要知识点(5)(哈希表、unordered_map和unordered_set封装)

1.哈希思想和哈希表 (1)哈希思想和哈希表的区别 哈希(散列、hash)是一种映射思想,本质上是值和值建立映射关系,key-value就使用了这种思想。哈希表(散列表,数据结构),主要功能是值和存储位置建立映射关系,它通过key-value模型中的key来定位数组的下标,将value存进该位置。 哈希思想和哈希表数据结构这两个概念要分清,哈希是哈希表的核心思想。 (2)unordered

OOP三个基本特征:封装、继承、多态

OOP三个基本特征:封装、继承、多态 C++编程之—面向对象的三个基本特征 默认分类 2008-06-28 21:17:04 阅读12 评论1字号:大中小     面向对象的三个基本特征是:封装、继承、多态。     封装 封装最好理解了。封装是面向对象的特征之一,是对象和类概念的主要特性。   封装,也就是把客观事物封装成抽象的类,并且类可以把自己的数据和方法只让可信

Android 优雅封装Glide

文章目录 Android 优雅封装Glide核心思想定义策略接口定义图片选项实现Glide策略图片管理类使用 Android 优雅封装Glide 核心思想 使用策略模式实现不同图片加载框架的切换,使用建造者设计模式处理不同参数,最后通过 ImageLoader 进行管理。 定义策略接口 interface ILoaderStrategy {fun loadImage(co