WinCE OpenGL绘制立方体和纹理贴图
VISIBLE,0,::GetSystemMetrics(SM_CXSCREEN),::GetSystemMetrics(SM_CYSCREEN),NULL,hInstance,NULL);
if (!hWnd)
{ return FALSE;}
if(!InitOGLES(hWnd))
{ printf(InitOGLES failed\n);return FALSE;} CreateSurface();
ShowWindow(hWnd, SW_SHOW);UpdateWindow(hWnd);
return TRUE;}
// // 函数: WndProc(HWND, UINT, WPARAM, LPARAM)
// // 目的: 处理主窗口的消息。
// // WM_COMMAND - 处理应用程序菜单// WM_PAINT - 绘制主窗口// WM_DESTROY - 发送退出消息并返回// LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{ PAINTSTRUCT ps;HDC hdc;
switch (message)
{ case WM_CREATE:break;case WM_PAINT:hdc = BeginPaint(hWnd, ps);
// TODO: 在此添加任意绘图代码……
EndPaint(hWnd, ps);break;case WM_DESTROY:{ Clean();PostQuitMessage(0);} break;
default:return DefWindowProc(hWnd, message, wParam, lParam);} return 0;}
BOOL InitOGLES(HWND hWnd)
{ EGLint matchingConfigs;EGLint majorVersion = 0;EGLint minorVersion = 0;
glesDisplay = eglGetDisplay(GetDC(hWnd)); //Ask for an available display if( glesDisplay == EGL_NO_DISPLAY || eglGetError() != EGL_SUCCESS )
return FALSE;
EGLConfig *configs_list;EGLint num_configs;// Display initialization (we don't care about the OGLES version numbers)
if( eglInitialize( glesDisplay, majorVersion, minorVersion) == EGL_FALSE)
{ printf(eglInitialize failed, eglGetError = 0x%04x\n,eglGetError());return FALSE;} // find out how many configurations are supported if ( eglGetConfigs( glesDisplay, NULL, 0, num_configs)==EGL_FALSE || eglGetError() != EGL_SUCCESS )
return FALSE;configs_list = (EGLConfig*) malloc(num_configs * sizeof(EGLConfig));if (configs_list == NULL)
return FALSE;// Get Configurations if( eglGetConfigs( glesDisplay, configs_list, num_configs, num_configs)== EGL_FALSE || eglGetError() != EGL_SUCCESS )
return FALSE;// Obtain the first configuration with a depth buffer of 16 bits EGLint attrs[] = { EGL_RED_SIZE, 5,EGL_GREEN_SIZE, 6,EGL_BLUE_SIZE, 5,EGL_DEPTH_SIZE, 16,EGL_NONE };if (!eglChooseConfig(glesDisplay, attrs, configs_list, num_configs, matchingConfigs))
{ return eglGetError();} // If there isn't any configuration enough good if (matchingConfigs 1)
return FALSE;/*eglCreateWindowSurface creates an onscreen EGLSurface and returns a handle to it. Any EGL rendering context created with a compatible EGLConfig can be used to render into this surface.*/ glesSurface = eglCreateWindowSurface(glesDisplay, configs_list[0], hWnd, 0);if(!glesSurface)
return FALSE;
// Let's create our rendering context glesContext=eglCreateContext(glesDisplay, configs_list[0], 0, 0);if(!glesContext)
return FALSE;//Now we will activate the context for rendering eglMakeCurrent(glesDisplay, glesSurface, glesSurface, glesContext);
/*Remember: because we are programming for a mobile device, we cant use any of the OpenGL ES functions that finish in 'f', we must use the fixed point version (they finish in 'x'*/ glClearColorx(0, 0, 0, 0);glShadeModel(GL_SMOOTH);
RECT rc;GetWindowRect(hWnd, rc);UINT width = rc.right - rc.left;UINT height = rc.bottom - rc.top;// 设置OpenGL场景的大小glViewport(rc.left, rc.top, width, height);
// 设置投影矩阵glMatrixMode(GL_PROJECTION);glLoadIdentity();
// 投影变换(透视投影)
float ratio = (float) width / height;glFrustumf(-ratio, ratio, -1, 1, 2, 10);//glOrthox(FixedFromInt(-50),FixedFromInt(50), FixedFromInt(-50), FixedFromInt(50), FixedFromInt(-50), FixedFromInt(50));
// 选择模型观察矩阵glMatrixMode(GL_MODELVIEW);// 重置模型观察矩阵glLoadIdentity();
return TRUE;}
void CreateSurface()
{ glDisable(GL_DI
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)
- Linux嵌入式系统开发平台选型探讨(11-09)
- Windows CE 进程、线程和内存管理(二)(11-09)
