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. Kindle 转换器

    一款比较好用的Kindle转换器,支持txt, opf, htm, html, epub 到 mobi 的转换,支持拖放操作,支持批量操作.只需要选中多个待转换的文件,拖放到程序窗口即可. 曾经用过一 ...

  2. [ACM_数学] LA 3708 Graveyard [墓地雕塑 圈上新加点 找规律]

    Description   Programming contests became so popular in the year 2397 that the governor of New Earck ...

  3. [JS11] 状态栏滚动

    <html> <head> <meta http-equiv="Content-Type" content="text/html; char ...

  4. js随机点名

    定时器案例. <!-- Author: XiaoWen Create a file: 2016-12-08 12:27:32 Last modified: 2016-12-08 12:51:59 ...

  5. atitit. hb 原生sql跨数据库解决原理 获得hb 数据库类型运行期获得Dialect

    atitit. hb 原生sql跨数据库解决原理 获得hb 数据库类型运行期获得Dialect   #-----原理 Hibernate 运行期获得Dialect   2010-07-28 12:59 ...

  6. FIR.im Weekly - 上周微博热转资源精选

    LeakCanary: 让内存泄露无所遁形 Square 开源的 LeakCanary,国内开发者 @廖祜秋liaohuqiu 翻译了对应的官方博客,撰写了中文使用说明文档,同时还写了一个小 Demo ...

  7. CSS水平垂直居中总结

    行内元素水平居中 把行内元素包裹在块级父元素中,且父元素中的css设置text-align:center; <!DOCTYPE html> <html> <head> ...

  8. win7给C盘扩容

    win7给C盘扩容 需要给C盘在不重装系统的情况下进行扩容.在网上搜索了不少资料,包括使用系统自带的分区工具,PQ等软件,都没有成功.不小心看到了分区助手,使用之,迅速的解决了问题,而且解决的非常完美 ...

  9. Android中build target,minSdkVersion,targetSdkVersion,maxSdkVersion概念区分

    Android中build target,minSdkVersion,targetSdkVersion,maxSdkVersion概念区分 标签: build targetminSdkVersiont ...

  10. 利用EEPROM实现arduino的断电存储

    转载请注明:@小五义http://www.cnblogs.com/xiaowuyiQQ群:64770604 一.EEPROM简介 EEPROM (Electrically Erasable Progr ...