新聞中心

        EEPW首頁 > 嵌入式系統 > 設計應用 > WinCE OpenGL繪制立方體和紋理貼圖

        WinCE OpenGL繪制立方體和紋理貼圖

        作者: 時間:2016-10-08 來源:網絡 收藏

        最近工作之余,開始學習OpenGL, 想到WINCE也是支持OpenGL的,只不過是嵌入式的OpenGL ES.于是嘗試寫了一個WINCE下的OpenGL測試程序,實現了繪制立方體和紋理。效果圖如下:

        本文引用地址:http://www.104case.com/article/201610/305941.htm

        需要注意的是,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 #include #include ImgLoader.h // OpenGL ES Includes #include #include #include #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 failedn);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)


        上一頁 1 2 3 下一頁

        關鍵詞:

        評論


        相關推薦

        技術專區

        關閉
        主站蜘蛛池模板: 郯城县| 双峰县| 阿克苏市| 阿坝县| 中阳县| 水城县| 侯马市| 柳州市| 玉田县| 怀远县| 洪湖市| 定结县| 深泽县| 专栏| 山西省| 南投县| 永吉县| 新巴尔虎左旗| 石嘴山市| 基隆市| 商都县| 锦州市| 张北县| 刚察县| 嘉鱼县| 曲沃县| 南川市| 罗源县| 巨鹿县| 盐边县| 兴化市| 夹江县| 体育| 奉化市| 营山县| 宽城| 偏关县| 肥西县| 三门县| 忻城县| 五指山市|