class FOpenglEs
{
public: /**
* 初始化 OpenGLES3.0
*/
bool initOpenGLES30(HWND hwnd)
{
EGLConfig config;
EGLint majorVersion;
EGLint minorVersion;
EGLint contextAttribs[] = { EGL_CONTEXT_CLIENT_VERSION, , EGL_NONE }; if ( hwnd == NULL )
{
return GL_FALSE;
}
EGLNativeDisplayType displaytype = GetDC(hwnd); m_Display = eglGetDisplay( displaytype );
if ( m_Display == EGL_NO_DISPLAY )
{
return GL_FALSE;
} // Initialize EGL
if ( !eglInitialize ( m_Display, &majorVersion, &minorVersion ) )
{
return GL_FALSE;
} GLuint flags = ES_WINDOW_RGB;
{
EGLint numConfigs = ;
EGLint attribList[] =
{
EGL_RED_SIZE, ,
EGL_GREEN_SIZE, ,
EGL_BLUE_SIZE, ,
EGL_ALPHA_SIZE, ( flags & ES_WINDOW_ALPHA ) ? : EGL_DONT_CARE,
EGL_DEPTH_SIZE, ( flags & ES_WINDOW_DEPTH ) ? : EGL_DONT_CARE,
EGL_STENCIL_SIZE, ( flags & ES_WINDOW_STENCIL ) ? : EGL_DONT_CARE,
EGL_SAMPLE_BUFFERS, ( flags & ES_WINDOW_MULTISAMPLE ) ? : ,
// if EGL_KHR_create_context extension is supported, then we will use
// EGL_OPENGL_ES3_BIT_KHR instead of EGL_OPENGL_ES2_BIT in the attribute list
EGL_RENDERABLE_TYPE, GetContextRenderableType ( m_Display),
EGL_NONE
}; // Choose config
if ( !eglChooseConfig (m_Display, attribList, &config, , &numConfigs ) )
{
return GL_FALSE;
} if ( numConfigs < )
{
return GL_FALSE;
}
} // Create a surface
m_Surface = eglCreateWindowSurface (m_Display, config,
hwnd, NULL ); if ( m_Surface == EGL_NO_SURFACE )
{
return GL_FALSE;
} // Create a GL context
m_Context = eglCreateContext (m_Display, config,
EGL_NO_CONTEXT, contextAttribs ); if ( m_Context == EGL_NO_CONTEXT )
{
return GL_FALSE;
} // Make the context current
if ( !eglMakeCurrent (m_Display, m_Surface,
m_Surface, m_Context ) )
{
return GL_FALSE;
} return true; } EGLint GetContextRenderableType ( EGLDisplay eglDisplay )
{
#ifdef EGL_KHR_create_context
const char *extensions = eglQueryString ( eglDisplay, EGL_EXTENSIONS ); // check whether EGL_KHR_create_context is in the extension string
if ( extensions != NULL && strstr( extensions, "EGL_KHR_create_context" ) )
{
// extension is supported
return EGL_OPENGL_ES3_BIT_KHR;
}
#endif
// extension is not supported
return EGL_OPENGL_ES2_BIT;
}
/**
* 销毁OpenGLES3.0
*/
void destroyOpenGLES20()
{ } void SwapBuffers()
{
eglSwapBuffers(m_Display,m_Surface);
} void setViewPort( int x,int y,int width,int height )
{
glViewport(GLint(x),GLint(y),GLsizei(width),GLsizei(height));
} void clear(unsigned int mask)
{
//! GL_DEPTH_BUFFER_BIT
//! GL_COLOR_BUFFER_BIT
//! GL_COLOR_BUFFER_BIT
//! GL_STENCIL_BUFFER_BIT
//! GL_ACCUM_BUFFER_BIT;
//! GL_TRANSFORM_BIT
//! GL_ENABLE_BIT
//! GL_HINT_BIT
//! GL_EVAL_BIT
glClear(mask);
} void clearColor(float r,float g,float b,float a)
{
glClearColor(r,g,b,a);
} void CreateOglBuffer(OglBuffer* buf)
{
glGenBuffers(, &buf->m_VertexBufferId);
glBindBuffer(GL_ARRAY_BUFFER, buf->m_VertexBufferId); glBufferData(GL_ARRAY_BUFFER, sizeof(FVertex)* buf->m_vertexs.size(), &buf->m_vertexs[].m_Pos.x, GL_DYNAMIC_DRAW); glBindBuffer(GL_ARRAY_BUFFER, ); glGenBuffers(, &buf->m_IndexBufferId);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buf->m_IndexBufferId); glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(FMeshTriangle) * buf->m_Indexs.size(), &buf->m_Indexs[].index0, GL_DYNAMIC_DRAW); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,); glGenVertexArrays(,&buf->m_VaoBufferId);
glBindVertexArray(buf->m_VaoBufferId); glBindBuffer(GL_ARRAY_BUFFER,buf->m_VertexBufferId); glEnableVertexAttribArray();
glEnableVertexAttribArray();
glVertexAttribPointer(,,GL_FLOAT,(GLboolean)false,sizeof(FVertex),);
glVertexAttribPointer(,,GL_FLOAT,(GLboolean)false,sizeof(FVertex),(GLvoid*)(sizeof(float)*)); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,buf->m_IndexBufferId); glBindVertexArray();
glBindBuffer(GL_ARRAY_BUFFER,);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,);
glDisableVertexAttribArray();
glDisableVertexAttribArray();
printf("vertex:%d bufId:%d \n",buf->m_vertexs.size(),buf->m_VertexBufferId);
printf("index:%d bufId:%d \n",buf->m_Indexs.size(),buf->m_IndexBufferId); } void bindVao(OglBuffer* buf)
{
glBindVertexArray(buf->m_VaoBufferId);
} void destroyVertexBuffer( OglBuffer* buf )
{ glDeleteVertexArrays(,&buf->m_VaoBufferId);
glDeleteBuffers(,&buf->m_IndexBufferId);
glDeleteBuffers(,&buf->m_VertexBufferId); } void drawBuffers(const OglBuffer* buf)
{
glBindVertexArray(buf->m_VaoBufferId);
glDrawElements(GL_TRIANGLES,buf->m_Indexs.size() *,GL_UNSIGNED_INT,);
} public:
/// Display handle
EGLNativeDisplayType eglNativeDisplay; /// Window handle
EGLNativeWindowType eglNativeWindow; EGLConfig m_Config;
EGLSurface m_Surface;
EGLContext m_Context;
EGLDisplay m_Display; /// Window width
GLint m_width; /// Window height
GLint m_height;
};
class FVertex
{
public:
FVertex()
{ }
vec3 m_Pos;
vec3 m_Normal;
vec2 m_Uv;
vec3 m_tangent;
vec3 m_bitangent; }; class OglBuffer
{
public:
OglBuffer()
{
m_VaoBufferId = ;
m_VertexBufferId =;
m_IndexBufferId =; } Fuint m_VaoBufferId;
Fuint m_VertexBufferId;
Fuint m_IndexBufferId; std::vector<FVertex> m_vertexs;
std::vector<FMeshTriangle> m_Indexs; };

用的时候直接这样就好了,比较方便

g_Opengles.setViewPort(,,,);
g_Opengles.clearColor(0.1,,0.1,);
g_Opengles.clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); m_Shader.useProgram(); m_Shader.setUniformMatrix4fv("_MVP",&m_ProjectMatrix.m00); g_Opengles.drawBuffers(&m_Buff); g_Opengles.SwapBuffers();

shader ,不能用varying,只能用in  out这样

const char* vs  =
{
"#version 300 es \n"
"layout(location = 0) in vec4 vPosition; \n"
"layout(location = 1) in vec3 vNormal; \n"
"uniform mat4 _MVP; \n"
"out vec3 oNormal; \n"
"void main() \n"
"{ \n"
" gl_Position = _MVP * vPosition; \n"
" oNormal = vNormal; \n"
"} \n"
};
const char* ps =
{
"#version 300 es \n"
"precision mediump float; \n"
"out vec4 fragColor; \n"
"in vec3 oNormal; \n"
"void main() \n"
"{ \n"
" \n"
" float dotN = dot(oNormal,vec3(0,1,0)); \n"
" float realColor = max(0.0,dotN); \n"
" fragColor = vec4 ( realColor, realColor, realColor, 1.0 ); \n"
"} \n"
};

OpenGL es3.0 初始化及渲染的更多相关文章

  1. OpenGL ES3.0

    到今天,喜欢上了非常酷的图片处理和游戏,经了解,大部分都要使用opengl es,所以准备开始学习,然后深入学习cocos2d,GPUImage.平台为IOS OpenGL ES OpenGL ES ...

  2. [工作积累] OpenGL ES3.0: glInvalidateFramebuffer

    https://www.khronos.org/opengles/sdk/docs/man3/html/glInvalidateFramebuffer.xhtml 这个在GLES2.0上只有Exten ...

  3. OpenGL ES3使用MSAA(多重采样抗锯齿)的方法

    昨晚花费了我2个多小时的时间终于把OpenGL ES3.0中的MSAA给搞定了.在OpenGL ES2.0中,Khronos官方没有引入标准的MSAA全屏抗锯齿的方法,而Apple则采用了自己的GL_ ...

  4. Cocos2d-x中使用OpenGL ES2.0编写shader

    这几天在看子龙山人的关于OpenGL的文章,先依葫芦画瓢,能看到些东西,才能慢慢深入了解,当入门文章不错,但是其中遇到的一些问题,折腾了一些时间,为了方便和我一样的小白们,在这篇文章中进行写补充. O ...

  5. iOS开发——图形编程OC篇&OpenGL ES2.0编程步骤

    OpenGL ES2.0编程步骤 OpenGL ES (OpenGL for Embedded Systems) 是 OpenGL 三维图形 API 的子集,针对手机.PDA和游戏主机等嵌入式设备而设 ...

  6. OpenGL ES2.0入门详解

    引自:http://blog.csdn.net/wangyuchun_799/article/details/7736928  1.决定你要支持的OpenGL ES的版本.目前,OpenGL ES包含 ...

  7. OpenGL 4.0的Tessellation Shader(细分曲面着色器)

    细分曲面着色器(Tessellation Shader)处于顶点着色器阶段的下一个阶段,我们可以看以下链接的OpenGL渲染流水线的图:https://www.opengl.org/wiki/Rend ...

  8. OpenGL ES2.0编程三步曲 -转

    原地址:http://blog.csdn.net/myarrow/article/details/7707943 1. 保存全局变量的数据结构 以下例子程序均基于Linux平台. typedef st ...

  9. OpenGL ES2.0 基本编程

    1. EGL OpenGL ES命令须要一个rendering context和一个drawing surface. Rendering Context: 保存当前的OpenGL ES状态. Draw ...

随机推荐

  1. PL/SQL 创建视图语法

    使用create view 语句创建视图 create [or replace][force | noforce] view [user.] viewName (column [,column2].. ...

  2. Kali Linux系列教程之OpenVas安装

    Kali Linux系列教程之OpenVas安装 文 /玄魂 目录 Kali Linux系列教程之OpenVas安装 前言 1.  服务器层组件 2.客户层组件 安装过程 Initial setup ...

  3. grunt使用小记之uglify:最全的uglify使用DEMO

    grunt-contrib-uglify uglify是一个文件压缩插件,项目地址:https://github.com/gruntjs/grunt-contrib-uglify 本文将以一个DEMO ...

  4. httpwebrequest 请求压缩,接受压缩的字符流请求

    请看图,客户端和服务端都使用gzip压缩. 客户端参数以json字符串形式gzip压缩,以二进制流发送到服务端:服务端接收到请求,解压缩gzip后,进行业务逻辑处理:处理完后在将返回值以json形式, ...

  5. 三国杀3v3心法——总述篇

    昔日,独孤求败前辈精研剑法,将其中奥妙化为独孤九剑,破尽天下武功.其中开篇总诀式提纲挈领,从宏观的层面阐述剑道,是领悟后面八式的基石,而之后各式则深入微观,可各破一类具体的武功.笔者亦曾苦心研究三国杀 ...

  6. AdaBoost算法简介

    一.AdaBoost的损失函数 AdaBoost优化的是指数损失,即\begin{align*} \mathbb{E}_{\boldsymbol{x} \sim \mathfrak{D}, y}[e^ ...

  7. Windows Server 2008R2配置MySQL Cluster

    目录 配置环境 相关知识 配置过程 配置 ini参数解释 启动集群 检查配置 同步测试 故障测试 写在之后 配置环境 VMware:(版本10.0.01) 操作系统:Windows Server 20 ...

  8. C#:Oracle数据库带参PLSQL语句的正确性验证

    在有Oracle数据库C#项目中,有一个这样的需求:在界面上配置了带参数的PLSQL语句,但是要通过程序验证其正确性,那么该如何实现?这就是本文要探讨的内容. 一:通过OracleCommand对象的 ...

  9. 在Servlet使用getServletContext()获取ServletContext对象出现java.lang.NullPointerException(空指针)异常的解决办法

    今天遇到了一个在servlet的service方法中获取ServletContext对象出现java.lang.NullPointerException(空指针)异常,代码如下: 1 //获取Serv ...

  10. JavaScript的for循环编写九九乘法表

    for(var i = 1; i <= 10; i++) { for(var j = 1; j <= i; j++) { document.writeln(i + '*' + j + '= ...