Hi ,
Find my code:
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
MSG msg;
WNDCLASS wc;
hInst = hInstance;
bool done = false;
if(hWnd = FindWindow(szAppName,szAppName))
{
SetForegroundWindow((HWND)((ULONG) hWnd | 0x00000001));
return 0;
}
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(hInstance, NULL);
wc.hCursor = 0;
wc.hbrBackground = 0;
wc.lpszMenuName = NULL;
wc.lpszClassName = szAppName;
if(!RegisterClass(&wc))
{
return false;
}
hWnd = CreateWindow(szAppName,
szAppName,
WS_VISIBLE|WS_SYSMENU,
200,
150,
400,
200,
NULL, NULL,
hInst, NULL);
if (!hWnd)
{
return FALSE;
}
if(!InitOGLES())
{
return FALSE;
}
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
while(!done)
{
if(PeekMessage(&msg,NULL,0,0,PM_REMOVE))
{
RETAILMSG(DEBUG,(_T("Entered13
")));
if(msg.message == WM_QUIT)
{
done = true;
}
else
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
else
Render();
}
Clean();
return 0;
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_PAINT:
ValidateRect(hWnd,NULL);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
BOOL InitOGLES()
{
EGLConfig configs;
EGLint matchingConfigs;
const EGLint configAttribs[] =
{
EGL_RED_SIZE, 8,
EGL_GREEN_SIZE, 8,
EGL_BLUE_SIZE, 8,
EGL_ALPHA_SIZE, EGL_DONT_CARE,
EGL_DEPTH_SIZE, 16,
EGL_STENCIL_SIZE, EGL_DONT_CARE,
EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
EGL_NONE, EGL_NONE
};
EGLint contextAttribs[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE, EGL_NONE };
hDC = GetDC(hWnd);
glesDisplay = eglGetDisplay(hDC);
eglInitialize(glesDisplay, NULL, NULL);
assert(eglGetError() == EGL_SUCCESS);
eglBindAPI(EGL_OPENGL_API);
assert(eglGetError() == EGL_SUCCESS);
eglChooseConfig(glesDisplay, configAttribs, &configs, 1, &matchingConfigs);
assert(eglGetError() == EGL_SUCCESS);
assert(matchingConfigs == 1);
glesSurface = eglCreateWindowSurface(glesDisplay, configs, hWnd, NULL);
assert(eglGetError() == EGL_SUCCESS);
glesContext=eglCreateContext(glesDisplay,configs,NULL,contextAttribs);
assert(eglGetError() == EGL_SUCCESS);
eglMakeCurrent(glesDisplay, glesSurface, glesSurface, glesContext);
assert(eglGetError() == EGL_SUCCESS);
glClearColorx(0, 0, 0, 0);
glShadeModel(GL_SMOOTH);
RECT r;
GetWindowRect(hWnd, &r);
glViewport(r.left, r.top, r.right - r.left, r.bottom - r.top);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrthox(FixedFromInt(-50), FixedFromInt(50),FixedFromInt(-50), FixedFromInt(50), FixedFromInt(-50), FixedFromInt(50));
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
return TRUE;
}
void Render()
{
static int rotation = 0;
GLshort vertexArray[9] = {-25,-25,0, 25,-25,0, 0,25,0 };
GLubyte colorArray[12] = {1,0,0,1, 0,1,0,1, 0,0,1,1};
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslatex(0, 0, FixedFromInt(-10));
glRotatex(FixedFromInt(rotation++), 0, ONE,0);
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3, GL_SHORT, 0, vertexArray);
glEnableClientState(GL_COLOR_ARRAY);
glColorPointer(4,GL_UNSIGNED_BYTE, 0, colorArray);
glDrawArrays(GL_TRIANGLES, 0, 3);
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_COLOR_ARRAY);
eglSwapBuffers(glesDisplay, glesSurface);
}
Regards,
Sowmya