const int numIndices = 12;
GlesCanvasTexture::GlesCanvasTexture(void)
- : __eglDisplay(EGL_DEFAULT_DISPLAY)
+ : __eglDisplay(EGL_NO_DISPLAY)
, __eglSurface(EGL_NO_SURFACE)
, __eglConfig(null)
- , __eglContext(EGL_NO_DISPLAY)
+ , __eglContext(EGL_NO_CONTEXT)
, __programObject(0)
, __indexPosition(0)
, __indexTexture(0)
, __pForm(null)
, __textureId(0)
, __pCanvasTexture(null)
- , __pCanvas(null)
, __pFont(null)
, __needUpdateTexture(false)
, __drawCount(0)
EGLint eglConfigList[] =
{
- EGL_RED_SIZE, 5,
- EGL_GREEN_SIZE, 6,
- EGL_BLUE_SIZE, 5,
+ EGL_RED_SIZE, 8,
+ EGL_GREEN_SIZE, 8,
+ EGL_BLUE_SIZE, 8,
EGL_ALPHA_SIZE, 0,
EGL_DEPTH_SIZE, 8,
EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
eglBindAPI(EGL_OPENGL_ES_API);
- if (__eglDisplay)
- {
- DestroyGL();
- }
-
__eglDisplay = eglGetDisplay((EGLNativeDisplayType)EGL_DEFAULT_DISPLAY);
TryCatch(__eglDisplay != EGL_NO_DISPLAY, , "eglGetDisplay() failed.");
{
result r = E_SUCCESS;
Rectangle rect = __pForm->GetBounds();
+ Canvas* pCanvas = null;
glGenTextures(1, &__textureId);
glBindTexture(GL_TEXTURE_2D, __textureId);
r = __pCanvasTexture->Construct(__textureId, rect.width, rect.height);
TryCatch(!IsFailed(r), , "__pCanvasTexture->Construct() failed.");
- __pCanvas = __pCanvasTexture->GetCanvasN();
+ pCanvas = __pCanvasTexture->GetCanvasN();
r = GetLastResult();
- TryCatch(__pCanvas != null && !IsFailed(r), , "__pCanvasTexture->GetCanvasN() failed. %s", GetErrorMessage(r));
+ TryCatch(pCanvas != null && !IsFailed(r), , "__pCanvasTexture->GetCanvasN() failed. %s", GetErrorMessage(r));
__pFont = new (std::nothrow) Font;
TryCatch(__pFont != null, , "Allocation of __pFont failed.");
r = __pFont->Construct(FONT_STYLE_BOLD, rect.width / 10);
TryCatch(!IsFailed(r), , "__pFont.Construct() failed. %s", GetErrorMessage(r));
- __pCanvas->SetFont(*__pFont);
- __pCanvas->SetBackgroundColor(Color::GetColor(COLOR_ID_BLACK));
- __pCanvas->Clear();
+ pCanvas->SetFont(*__pFont);
+ pCanvas->SetBackgroundColor(Color::GetColor(COLOR_ID_BLACK));
+ pCanvas->Clear();
DrawText(L"Touch the screen");
- __pCanvas->Show();
+ pCanvas->Show();
+ delete pCanvas;
return true;
CATCH:
+ delete pCanvas;
DestroyCanvasTexture();
return false;
glDeleteTextures(1, &__textureId);
}
- delete __pCanvas;
delete __pCanvasTexture;
delete __pFont;
}
if (__needUpdateTexture)
{
__needUpdateTexture = false;
- __pCanvas->Show();
+ if (__pCanvasTexture != null)
+ {
+ Canvas* pCanvas = __pCanvasTexture->GetCanvasN();
+ if (pCanvas != null)
+ {
+ pCanvas->Show();
+ delete pCanvas;
+ }
+ }
__drawCount = 0;
}
void
GlesCanvasTexture::DrawText(Tizen::Base::String string)
{
- Rectangle rect = __pCanvas->GetBounds();
- Dimension dimension;
- __pCanvas->SetFont(*__pFont);
- __pFont->GetTextExtent(string, string.GetLength(), dimension);
- __pCanvas->SetBackgroundColor(Color::GetColor(COLOR_ID_BLACK));
- __pCanvas->SetForegroundColor(Color::GetColor(COLOR_ID_BLACK));
- __pCanvas->DrawText(Point((rect.width - dimension.width) / 2 + 3, rect.height / 2 + 3), string, Color::GetColor(COLOR_ID_BLACK));
- __pCanvas->SetForegroundColor(Color::GetColor(COLOR_ID_WHITE));
- __pCanvas->DrawText(Point((rect.width - dimension.width) / 2 , rect.height / 2), string, Color::GetColor(COLOR_ID_BLACK));
+ if (__pCanvasTexture != null)
+ {
+ Canvas* pCanvas = __pCanvasTexture->GetCanvasN();
+ if (pCanvas != null)
+ {
+ Rectangle rect = pCanvas->GetBounds();
+ Dimension dimension;
+ pCanvas->SetFont(*__pFont);
+ __pFont->GetTextExtent(string, string.GetLength(), dimension);
+ pCanvas->SetBackgroundColor(Color::GetColor(COLOR_ID_BLACK));
+ pCanvas->SetForegroundColor(Color::GetColor(COLOR_ID_BLACK));
+ pCanvas->DrawText(Point((rect.width - dimension.width) / 2 + 3, rect.height / 2 + 3), string, Color::GetColor(COLOR_ID_BLACK));
+ pCanvas->SetForegroundColor(Color::GetColor(COLOR_ID_WHITE));
+ pCanvas->DrawText(Point((rect.width - dimension.width) / 2 , rect.height / 2), string, Color::GetColor(COLOR_ID_BLACK));
+ delete pCanvas;
+ }
+ }
}
void
GlesCanvasTexture::DrawEllipse(Point position, Color color)
{
- if (__pCanvas != null && __drawCount < MAX_DRAW_COUNT)
+ if (__drawCount < MAX_DRAW_COUNT)
{
- int size = 10 + Math::Rand() % 40;
- Rectangle rect(position.x - size, position.y -size, size * 2, size * 2);
- __pCanvas->FillEllipse(color, rect);
- DrawText(L"Touch the screen");
- __needUpdateTexture = true;
- __drawCount++;
+ if (__pCanvasTexture != null)
+ {
+ Canvas* pCanvas = __pCanvasTexture->GetCanvasN();
+ if (pCanvas != null)
+ {
+ int size = 10 + Math::Rand() % 40;
+ Rectangle rect(position.x - size, position.y -size, size * 2, size * 2);
+ pCanvas->FillEllipse(color, rect);
+ DrawText(L"Touch the screen");
+ __needUpdateTexture = true;
+ __drawCount++;
+ delete pCanvas;
+ }
+ }
}
}