📄 opengles2_0_egl_demo.cpp
字号:
// OpenGLES2_0_EGL_Demo.cpp : Defines the entry point for the application.
//
#include "stdafx.h"
#include "OpenGLES2_0_EGL_Demo.h"
#include <windows.h>
#include <commctrl.h>
#include <gles2/gl2.h>
#include <egl/egl.h>
#define MAX_LOADSTRING 100
// Global Variables:
HINSTANCE g_hInst; // current instance
#ifdef SHELL_AYGSHELL
HWND g_hWndMenuBar; // menu bar handle
#else // SHELL_AYGSHELL
HWND g_hWndCommandBar; // command bar handle
#endif // SHELL_AYGSHELL
EGLDisplay display;
EGLSurface surface;
EGLContext context;
EGLConfig config;
NativeDisplayType g_dpy;
HWND gHWND;
extern void AniPolkaRender();
extern int AniPolkaDemo();
extern int AniPolkaDeinit();
extern int PostProcessFBODemo();
extern void PostProcessFBORender();
extern int PostProcessFBODeinit();
extern int TeapotElementsDemo();
extern void TeapotElementsRender();
extern int TeapotElementsDeinit();
typedef int (*pfnDemoInit)(void);
typedef void (*pfnDemoRender)(void);
typedef int (*pfnDemoDeinit)(void);
typedef struct _DemoFunction {
pfnDemoInit pfnInit;
pfnDemoRender pfnRender;
pfnDemoDeinit pfnDeinit;
} DemoFunction;
DemoFunction DemoList[3] =
{
{AniPolkaDemo, AniPolkaRender, AniPolkaDeinit},
{PostProcessFBODemo, PostProcessFBORender, PostProcessFBODeinit},
{TeapotElementsDemo, TeapotElementsRender, TeapotElementsDeinit}
};
int selectedDemo=0;
// Forward declarations of functions included in this code module:
ATOM MyRegisterClass(HINSTANCE, LPTSTR);
BOOL InitInstance(HINSTANCE, int);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
INT_PTR CALLBACK About(HWND, UINT, WPARAM, LPARAM);
void initializeEGL();
void deinitializeEGL();
void render();
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
MSG msg;
DWORD dwFrames = 0;
DWORD dwPrevTicks = GetTickCount();
int stats_time = 0; // Assume no statistics
// Perform application initialization:
if (!InitInstance(hInstance, nCmdShow))
{
return FALSE;
}
initializeEGL();
printf("EGL Init Done!!\n");
HACCEL hAccelTable;
hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_OPENGLES2_0_EGL_DEMO));
// Main message loop:
/*
while (GetMessage(&msg, NULL, 0, 0))
{
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}*/
DemoList[selectedDemo].pfnInit();
for (;;)
{
if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
if (WM_QUIT == msg.message)
break;
TranslateMessage(&msg);
DispatchMessage(&msg);
}
else
{
render();
dwFrames++;
}
const DWORD dwTicks = GetTickCount();
if (stats_time > 0 && dwTicks - dwPrevTicks >= (DWORD)stats_time*1000)
{
TCHAR szMsg[16];
wsprintf(szMsg, TEXT("%d FPS\n"), (1000 * dwFrames) / (dwTicks - dwPrevTicks));
OutputDebugString(szMsg);
dwPrevTicks = GetTickCount();
dwFrames = 0;
}
}
DemoList[selectedDemo].pfnDeinit();
deinitializeEGL();
return (int) msg.wParam;
}
//
// FUNCTION: MyRegisterClass()
//
// PURPOSE: Registers the window class.
//
// COMMENTS:
//
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_OPENGLES2_0_EGL_DEMO));
wc.hCursor = 0;
wc.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
wc.lpszMenuName = 0;
wc.lpszClassName = szWindowClass;
return RegisterClass(&wc);
}
//
// FUNCTION: InitInstance(HINSTANCE, int)
//
// PURPOSE: Saves instance handle and creates main window
//
// COMMENTS:
//
// In this function, we save the instance handle in a global variable and
// create and display the main program window.
//
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
HWND hWnd;
TCHAR szTitle[MAX_LOADSTRING]; // title bar text
TCHAR szWindowClass[MAX_LOADSTRING]; // main window class name
g_hInst = hInstance; // Store instance handle in our global variable
#if defined(WIN32_PLATFORM_PSPC) || defined(WIN32_PLATFORM_WFSP)
// SHInitExtraControls should be called once during your application's initialization to initialize any
// of the device specific controls such as CAPEDIT and SIPPREF.
SHInitExtraControls();
#endif // WIN32_PLATFORM_PSPC || WIN32_PLATFORM_WFSP
LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
LoadString(hInstance, IDC_OPENGLES2_0_EGL_DEMO, szWindowClass, MAX_LOADSTRING);
#if defined(WIN32_PLATFORM_PSPC) || defined(WIN32_PLATFORM_WFSP)
//If it is already running, then focus on the window, and exit
hWnd = FindWindow(szWindowClass, szTitle);
if (hWnd)
{
// set focus to foremost child window
// The "| 0x00000001" is used to bring any owned windows to the foreground and
// activate them.
SetForegroundWindow((HWND)((ULONG) hWnd | 0x00000001));
return 0;
}
#endif // WIN32_PLATFORM_PSPC || WIN32_PLATFORM_WFSP
if (!MyRegisterClass(hInstance, szWindowClass))
{
return FALSE;
}
gHWND = hWnd = CreateWindow(szWindowClass, szTitle, WS_VISIBLE,
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL);
/*gHWND = hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPED|WS_CAPTION|WS_SYSMENU,
300, 200, 400, 240, NULL, NULL, hInstance, NULL);*/
if (!hWnd)
{
return FALSE;
}
#ifdef WIN32_PLATFORM_PSPC
// When the main window is created using CW_USEDEFAULT the height of the menubar (if one
// is created is not taken into account). So we resize the window after creating it
// if a menubar is present
if (g_hWndMenuBar)
{
RECT rc;
RECT rcMenuBar;
GetWindowRect(hWnd, &rc);
GetWindowRect(g_hWndMenuBar, &rcMenuBar);
rc.bottom -= (rcMenuBar.bottom - rcMenuBar.top);
MoveWindow(hWnd, rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top, FALSE);
}
#endif // WIN32_PLATFORM_PSPC
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
#ifndef SHELL_AYGSHELL
if (g_hWndCommandBar)
{
CommandBar_Show(g_hWndCommandBar, TRUE);
}
#endif // !SHELL_AYGSHELL
return TRUE;
}
//
// FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
//
// PURPOSE: Processes messages for the main window.
//
// WM_COMMAND - process the application menu
// WM_PAINT - Paint the main window
// WM_DESTROY - post a quit message and return
//
//
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
int wmId, wmEvent;
PAINTSTRUCT ps;
HDC hdc;
#if defined(SHELL_AYGSHELL) && !defined(WIN32_PLATFORM_WFSP)
static SHACTIVATEINFO s_sai;
#endif // SHELL_AYGSHELL && !WIN32_PLATFORM_WFSP
switch (message)
{
case WM_COMMAND:
wmId = LOWORD(wParam);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -