opengles 开发l流程
来源:互联网 发布:任子行网络审计 编辑:程序博客网 时间:2024/06/04 00:42
- {
- 1:获取 Display
- 2:初始化 egl
- 3:选择 Config
- 4:创建 Surface
- 5:创建上下文对象
- 6:查看 Display Surface Context 是否创建成功
- 7:绘制
- 8:销毁 OpenGLES
- }
- #include <EGL/egl.h>
- #include <gles2/gl2.h>
- #include "freeImage/FreeImage.h"
-
- class WinApp {
- public:
- WinApp(HINSTANCE hInstance);
- virtual~WinApp(void);
- virtual LRESULT onEvent(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
- static LRESULT CALLBACK wndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
- int main(int wWidth,int wHegith);
-
-
- bool configurationInit();
- void draw();
- void destroy();
- private:
- HINSTANCE _hInstance;
- HWND _hWnd;
- protected;
-
- int _width;
- int _height;
-
- EGLDisplay _display;
- EGLContext _context;
- EGLSurface _surface;
- EGLConfig _config;
- };
1.下载AMD的OpenGL ES2.0的模拟器,地址: http://www.opengles-book.com/ESEmulator.2009-04-28-v1.4.APRIL_2009_RELEASE.msi
2.下载OpenGL ES2.0实例代码,用《OpenGL ES2.0 Programming guide》里的例子代码,地址: http://www.opengles-book.com/OpenGL_ES_Programming_Guide_v1.0.2.zip.
3.下载Visual Studio, 会写点程序的都懂。
教程:
1. 解压上面下载的例子代码。
2.安装OpenGL ES2.0模拟器, 将安装目录下的AMD\OpenGL ES 2.0 Emulator v1.1\bin 以及AMD\OpenGL ES 2.0 Emulator v1.1\lib 里的 libEGL.dll 、 libGLESv2.dll 和 libEGL.lib 、libGLESv2.lib分别拷贝至VS的bin和lib文件夹下。
3.接着打开例子代码里的工程就可以了。
之后就可以通过修改例子来实现在windows上练习实践opengles2.0了。这样的好处是用c/c++实现编程,之后方便移植至Android、iOS等系统,再者还可以利用起强大的VS。
- #include "WinApp.h"
-
- bool WinApp::configurationInit(){
-
- _display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
-
-
- EGLint major;
- EGLint minor;
- eglInitialize(_display, &major, &minor);
-
-
-
- const EGLint attribs[] ={
-
- EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
- EGL_BLUE_SIZE, 8,
- EGL_GREEN_SIZE, 8,
- EGL_RED_SIZE, 8,
- EGL_DEPTH_SIZE,24,
- EGL_NONE
- };
- EGLint format(0);
- EGLint numConfigs(0);
-
-
- eglChooseConfig(_display, attribs, &_config, 1, &numConfigs);
-
- eglGetConfigAttrib(_display, _config, EGL_NATIVE_VISUAL_ID, &format);
-
-
- 4:创建 Surface
- _surface = eglCreateWindowSurface(_display, _config, _hWnd, NULL);
-
-
- EGLint attr[] ={ EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE, EGL_NONE };
-
- _context = eglCreateContext(_display, _config, EGL_NO_CONTEXT, attr);
-
-
- if (eglMakeCurrent(_display, _surface, _surface, _context) == EGL_FALSE){
- return false;
- }
-
-
- eglQuerySurface(_display, _surface, EGL_WIDTH, &_width);
- eglQuerySurface(_display, _surface, EGL_HEIGHT, &_height);
-
- return true;
- }
-
- void WinApp::draw(){
-
-
- glClearColor(0,0,1,1);
-
-
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- glViewport(0,0,_width,_height);
-
-
- eglSwapBuffers(_display,_surface);
- }
-
- void WinApp::destroy(){
- if (_display != EGL_NO_DISPLAY){
-
- eglMakeCurrent(_display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
- if (_context != EGL_NO_CONTEXT){
-
- eglDestroyContext(_display, _context);
- }
-
- if (_surface != EGL_NO_SURFACE){
-
- eglDestroySurface(_display, _surface);
- }
-
- eglTerminate(_display);
- }
-
- _display = EGL_NO_DISPLAY;
- _context = EGL_NO_CONTEXT;
- _surface = EGL_NO_SURFACE;
- }
-
-
-
- WinApp::WinApp(HINSTANCE hInstance):_hInstance(hInstance){
- WNDCLASSEX winClass;
- winClass.lpszClassName = _T("CELLWinApp");
- winClass.cbSize = sizeof(winClass);
- winClass.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
- winClass.lpfnWndProc = wndProc;
- winClass.hInstance = hInstance;
- winClass.hIcon = 0;
- winClass.hIconSm = 0;
- winClass.hCursor = LoadCursor(hInstance, IDC_ARROW);
- winClass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
- winClass.lpszMenuName = NULL;
- winClass.cbClsExtra = 0;
- winClass.cbWndExtra = 0;
-
-
- RegisterClassEx(&winClass);
- }
-
- LRESULT CALLBACK WinApp::wndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam){
-
- WinApp* pThis = (WinApp*)GetWindowLong(hWnd,GWL_USERDATA);
- if (pThis) {
- return pThis->onEvent(hWnd,msg,wParam,lParam);
- }
- if (WM_CREATE == msg){
-
- CREATESTRUCT* pCreate = (CREATESTRUCT*)lParam;
-
- DWORD_PTR pCreateParams = (DWORD_PTR)pCreate->lpCreateParams;
-
-
-
-
-
-
- SetWindowLong(hWnd,GWL_USERDATA,pCreateParams);
- }
- return DefWindowProc( hWnd, msg, wParam, lParam );
- }
-
-
- LRESULT WinApp::onEvent(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam){
- switch (msg){
- case WM_CLOSE:
- case WM_DESTROY:
- {
- ::PostQuitMessage(0);
- }
- break;
- case WM_LBUTTONDOWN:
-
- break;
- case WM_RBUTTONDOWN:
-
- break;
- case WM_MOUSEMOVE:
- break;
- case WM_KEYDOWN:
- switch (wParam){
- case VK_LEFT:
- break;
- default:
- break;
- }
- break;
- default:
- return DefWindowProc( hWnd, msg, wParam, lParam );
- }
-
- return S_OK;
- }
-
- WinApp::~WinApp(void){
-
- UnregisterClass(_T("CELLWinApp"),_hInstance);
- destroy();
- }
-
- int WinApp::main(int wWidth,int wHegith){
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- _hWnd = CreateWindowEx( NULL, _T("CELLWinApp"), _T("CELLWinApp"), WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, wWidth, wHegith, NULL, NULL, _hInstance,this );
- if (_hWnd == 0) {
- return -1;
- }
-
- ShowWindow(_hWnd,SW_SHOW);
-
- configurationInit();
-
-
- MSG msg = {0};
- while(msg.message != WM_QUIT) {
-
- if (msg.message == WM_DESTROY || msg.message == WM_CLOSE){
- break;
- }
-
-
- if( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) ){
- TranslateMessage( &msg );
- DispatchMessage( &msg );
- }else{
-
- draw();
- }
- }
-
- return 0;
- }
画出一个蓝色的界面就可以了
0 0