最近作业之余,开端学习OpenGL, 想到WINCE也是支撑OpenGL的,只不过是嵌入式的OpenGL ES.所以测验写了一个WINCE下的OpenGL测验程序,完成了制作立方体和纹路。作用图如下:
需求留意的是,WINCE体系上开发OpenGL程序需具有以下条件:
1. 处理器的支撑,嵌入式处理器需支撑3D加快烘托。
2. WINCE内核的支撑,定制内核时需增加OpenGL ES相关组件。
以下是详细的参阅代码:
view plain /******************************************************************** filename: WinceOpenGLDemo.cpp created: 2011-01-05 author: firehood purpose: 使用OpenGL ES完成了制作立方体和纹路作用*********************************************************************/
// WinceOpenGLDemo.cpp : 界说应用程序的进口点。
//
#include stdafx.h #include WinceOpenGLDemo.h #include
// OpenGL lib #pragma comment(lib, OpenGlLib\\libGLESv1_CM.lib)
#pragma comment(lib, OpenGlLib\\libEGL.lib)
// 全局变量:HINSTANCE g_hInst; // 当时实例TCHAR szAppName[] = LOpenGLES; /*The application name and the window caption*/ CImgLoader g_Image;// OpenGL variables EGLDisplay glesDisplay; // EGL display EGLSurface glesSurface; // EGL rendering surface EGLContext glesContext; // EGL rendering context
GLuint texture[6] = {0};
// 立方体定点坐标GLshort vertices[] = { -1,-1,1,1,-1,1,1,1,1,-1,1,1,
-1,-1,-1,-1,1,-1,1,1,-1,1,-1,-1,
-1,1,-1,-1,1,1,1,1,1,1,1,-1,
-1,-1,-1,1,-1,-1,1,-1,1,-1,-1,1,
1,-1,-1,1,1,-1,1,1,1,1,-1,1,
-1,-1,-1,-1,-1,1,-1,1,1,-1,1,-1 };
// 各个面纹路坐标GLshort texCoords[] = { 0,0,1,0,1,1,0,1,};
// 三角形索引数据GLbyte indices1[] = { 0,1,3,2,0,0,0,0,0,0,0,0 };GLbyte indices2[] = { 0,0,0,0,4,5,7,6,0,0,0,0,0,0,0,0 };GLbyte indices3[] = { 0,0,0,0,8,9,11,10,0,0,0,0,0,0,0,0 };GLbyte indices4[] = { 0,0,0,0,12,13,15,14,0,0,0,0,0,0,0,0 };GLbyte indices5[] = { 0,0,0,0,16,17,19,18,0,0,0,0 };GLbyte indices6[] = { 0,0,0,0,20,21,23,22 };
// 此代码模块中包括的函数的前向声明:ATOM MyRegisterClass(HINSTANCE, LPTSTR);BOOL InitInstance(HINSTANCE, int);LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
BOOL InitOGLES(HWND hWnd);void CreateSurface();BOOL LoadTexture(LPCTSTR lpFileName,GLuint *id);void Render();void Clean();
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPTSTR lpCmdLine,int nCmdShow)
{ MSG msg;
// 履行应用程序初始化:if (!InitInstance(hInstance, nCmdShow))
{ return FALSE;}
BOOL done = FALSE;// 主音讯循环:while(!done)
{ if(PeekMessage(msg,NULL,0,0,PM_REMOVE))
{ if(msg.message==WM_QUIT)
done = TRUE;else { TranslateMessage(msg);DispatchMessage(msg);} else { Render();};}
return (int) msg.wParam;}
// // 函数: MyRegisterClass()
// // 意图: 注册窗口类。
// // 注释:// ATOM MyRegisterClass(HINSTANCE hInstance, LPTSTR szWindowClass)
{ WNDCLASS wc;
wc.style = CS_HREDRAW | CS_VREDRAW;wc.lpfnWndProc = WndProc;wc.cbClsExtra = 0;wc.cbWndExtra = 0;wc.hInstance = hInstance;wc.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_WINCEOPENGLDEMO));wc.hCursor = 0;wc.hbrBackground = (HBRUSH) GetStockObject(NULL_BRUSH);wc.lpszMenuName = 0;wc.lpszClassName = szWindowClass;
return RegisterClass(wc);}
// // 函数: InitInstance(HINSTANCE, int)
// // 意图: 保存实例句柄并创立主窗口// // 注释:// // 在此函数中,咱们在全局变量中保存实例句柄并// 创立和显现主程序窗口。
// BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{ HWND hWnd;
g_hInst = hInstance; // 将实例句柄存储在全局变量中
if (!MyRegisterClass(hInstance, szAppName))
{ return FALSE;}
hWnd = CreateWindow(szAppName,WS_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)