Ejemplo n.º 1
0
//=================================================================================================================================
///
/// Funtion to create Window.
///
/// \param width the width of the window.
/// \param height the height of the window.
///
/// \return 0=fail; 1=pass
//=================================================================================================================================
HWND CreateWind( int width, int height )
{
   WNDCLASS             wc;                  // Windows Class Structure
   HWND hWnd;
   HINSTANCE hInstance;

   hInstance         = GetModuleHandle( NULL );             // Grab An Instance For Our Window
   wc.style          = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;  // Redraw On Size, And Own DC For Window.
   wc.lpfnWndProc    = WNDPROC( WndProc );                  // WndProc Handles Messages
   wc.cbClsExtra     = 0;                                   // No Extra Window Data
   wc.cbWndExtra     = 0;                                   // No Extra Window Data
   wc.hInstance      = hInstance;                           // Set The Instance
   wc.hIcon          = LoadIcon( NULL, IDI_WINLOGO );       // Load The Default Icon
   wc.hCursor        = LoadCursor( NULL, IDC_ARROW );       // Load The Arrow Pointer
   wc.hbrBackground  = NULL;                                // No Background Required For GL
   wc.lpszMenuName   = NULL;                                // We Don't Want A Menu
   wc.lpszClassName  = "OpenGL";                            // Set The Class Name

   if ( ! RegisterClass( &wc ) )                            // Attempt To Register The Window Class
   {
      MessageBox( NULL, "Failed To Register The Window Class.", "ERROR", MB_OK | MB_ICONEXCLAMATION );
      return FALSE;
   }

   if ( ! ( hWnd=CreateWindowEx(
      WS_EX_APPWINDOW | WS_EX_WINDOWEDGE,       // Extended Style For The Window
      "OpenGL",                                 // Class Name
      "Triangle ES App",                        // Window Title
      WS_OVERLAPPEDWINDOW |                     // Defined Window Style
      WS_CLIPSIBLINGS |                         // Required Window Style
      WS_CLIPCHILDREN,                          // Required Window Style
      0, 0,                                     // Window Position
      width,                                    // Window Width
      height,                                   // Window Height
      NULL,                                     // No Parent Window
      NULL,                                     // No Menu
      hInstance,                                // Instance
      NULL ) ) )                                // Dont Pass Anything To WM_CREATE
   {
      return 0;
   }

   if ( CreateEGLContext( hWnd, hInstance ) == false )
   {
      MessageBox( NULL, "Failed to create a context.", "ERROR", MB_OK|MB_ICONSTOP );
      exit( 0 );
   }

   CenterWindow(hWnd, NULL, width, height);
   ShowWindow( hWnd, SW_SHOW );
   SetForegroundWindow( hWnd );  // Slightly Higher Priority
   SetFocus( hWnd );             // Sets Keyboard Focus To The Window
   


   //ResizeScene( width, height );

   return hWnd;
}
Ejemplo n.º 2
0
///
//  esCreateWindow()
//
//      title - name for title bar of window
//      width - width of window to create
//      height - height of window to create
//      flags  - bitwise or of window creation flags 
//          ES_WINDOW_ALPHA       - specifies that the framebuffer should have alpha
//          ES_WINDOW_DEPTH       - specifies that a depth buffer should be created
//          ES_WINDOW_STENCIL     - specifies that a stencil buffer should be created
//          ES_WINDOW_MULTISAMPLE - specifies that a multi-sample buffer should be created
//          ES_WINDOW_POST_SUB_BUFFER_SUPPORTED - specifies that EGL_POST_SUB_BUFFER_NV is supported.
//
GLboolean ESUTIL_API esCreateWindow ( ESContext *esContext, LPCTSTR title, GLint width, GLint height, GLuint flags )
{
   UNREFERENCED_PARAMETER(title);
   UNREFERENCED_PARAMETER(width);
   UNREFERENCED_PARAMETER(height);

   EGLint configAttribList[] =
   {
       EGL_RED_SIZE,       5,
       EGL_GREEN_SIZE,     6,
       EGL_BLUE_SIZE,      5,
       EGL_ALPHA_SIZE,     (flags & ES_WINDOW_ALPHA) ? 8 : EGL_DONT_CARE,
       EGL_DEPTH_SIZE,     (flags & ES_WINDOW_DEPTH) ? 8 : EGL_DONT_CARE,
       EGL_STENCIL_SIZE,   (flags & ES_WINDOW_STENCIL) ? 8 : EGL_DONT_CARE,
       EGL_SAMPLE_BUFFERS, (flags & ES_WINDOW_MULTISAMPLE) ? 1 : 0,
       EGL_NONE
   };
   EGLint surfaceAttribList[] =
   {
       EGL_POST_SUB_BUFFER_SUPPORTED_NV, flags & (ES_WINDOW_POST_SUB_BUFFER_SUPPORTED) ? EGL_TRUE : EGL_FALSE,
       EGL_NONE, EGL_NONE
   };
   
   if ( esContext == NULL )
   {
      return GL_FALSE;
   }

   esContext->width = width;
   esContext->height = height;

   //if ( !WinCreate ( esContext, title) )
   //{
   //   return GL_FALSE;
   //}

  
   if ( !CreateEGLContext ( esContext->hWnd,
                            &esContext->eglDisplay,
                            &esContext->eglContext,
                            &esContext->eglSurface,
                            configAttribList,
                            surfaceAttribList ) )
   {
      return GL_FALSE;
   }
   

   return GL_TRUE;
}
Ejemplo n.º 3
0
//  esCreateWindow()
//
//      title - name for title bar of window
//      width - width of window to create
//      height - height of window to create
//      flags  - bitwise or of window creation flags 
//          ES_WINDOW_ALPHA       - specifies that the framebuffer should have alpha
//          ES_WINDOW_DEPTH       - specifies that a depth buffer should be created
//          ES_WINDOW_STENCIL     - specifies that a stencil buffer should be created
//          ES_WINDOW_MULTISAMPLE - specifies that a multi-sample buffer should be created
GLboolean ESUTIL_API esCreateWindow ( ESContext *esContext, const char* title, GLint width, GLint height, GLuint flags )
{
   EGLint attribList[] =
   {
       EGL_RED_SIZE,       5,
       EGL_GREEN_SIZE,     6,
       EGL_BLUE_SIZE,      5,
       EGL_ALPHA_SIZE,     (flags & ES_WINDOW_ALPHA) ? 8 : EGL_DONT_CARE,
       EGL_DEPTH_SIZE,     (flags & ES_WINDOW_DEPTH) ? 24 : EGL_DONT_CARE,
       EGL_STENCIL_SIZE,   (flags & ES_WINDOW_STENCIL) ? 8 : EGL_DONT_CARE,
       EGL_SAMPLE_BUFFERS, (flags & ES_WINDOW_MULTISAMPLE) ? 1 : 0,
       EGL_NONE
   };
   
   if ( esContext == NULL )
   {
      return GL_FALSE;
   }

// create window (only for windows)
#ifdef _WIN32
   esContext->width = width;
   esContext->height = height;

   if ( !WinCreate ( esContext, title) )
   {
      return GL_FALSE;
   }
#endif

   if ( !CreateEGLContext ( esContext->hWnd,
                            &esContext->eglDisplay,
                            &esContext->eglContext,
                            &esContext->eglSurface,
                            attribList) )
   {
      return GL_FALSE;
   }

#ifdef __ANDROID__
	// get size
	eglQuerySurface(esContext->eglDisplay, esContext->eglSurface, EGL_WIDTH, &esContext->width);
	eglQuerySurface(esContext->eglDisplay, esContext->eglSurface, EGL_HEIGHT, & esContext->height);
#endif

   return GL_TRUE;
}
Ejemplo n.º 4
0
bool OpenGLES_CreateContext(SDL_Window* window, App::StartupParams* params)
{
   SDL_SysWMinfo info;
   SDL_VERSION(&info.version); // initialize info structure with SDL version info
   SDL_bool get_win_info = SDL_GetWindowWMInfo(window, &info);
   Assert(get_win_info);
   EGLNativeWindowType hWnd = info.info.win.window;

   es_context.width = params->width;
   es_context.height = params->height;
   es_context.hWnd = hWnd;

   EGLint configAttribList[] =
   {
      EGL_RED_SIZE,       8,
      EGL_GREEN_SIZE,     8,
      EGL_BLUE_SIZE,      8,
      EGL_ALPHA_SIZE,     8 /*: EGL_DONT_CARE*/,
      EGL_DEPTH_SIZE,     24,
      EGL_STENCIL_SIZE,   8,
      EGL_SAMPLE_BUFFERS, 0,
      EGL_NONE
   };
   EGLint surfaceAttribList[] =
   {
      //EGL_POST_SUB_BUFFER_SUPPORTED_NV, flags & (ES_WINDOW_POST_SUB_BUFFER_SUPPORTED) ? EGL_TRUE : EGL_FALSE,
      //EGL_POST_SUB_BUFFER_SUPPORTED_NV, EGL_FALSE,
      EGL_NONE, EGL_NONE
   };

   if (!CreateEGLContext(es_context.hWnd,
         &es_context.eglDisplay,
         &es_context.eglContext,
         &es_context.eglSurface,
         configAttribList,
         surfaceAttribList))
   {
      Log::Error("Failed to create OpenGL ES 2.0 context");
	  return false;
   }

   const char* extensions = (const char*) glGetString(GL_EXTENSIONS);

   return true;
}
Ejemplo n.º 5
0
    bool DiWin32EGLWindow::Create(uint32& width, uint32& height, const DiString& title, bool fullscreen)
    {
        ::EGLContext eglContext = 0;
        if (!mEglConfig)
        {
            uint32 samples = 0;
            int minAttribs[] = 
            {
                EGL_LEVEL, 0,
                EGL_DEPTH_SIZE, 16,
                EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
                EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
                EGL_NATIVE_RENDERABLE, EGL_FALSE,
                EGL_DEPTH_SIZE, EGL_DONT_CARE,
                EGL_NONE
            };

            int maxAttribs[] = 
            {
                EGL_SAMPLES, samples,
                EGL_STENCIL_SIZE, INT_MAX,
                EGL_NONE
            };

            mEglConfig = mGLSupport->SelectGLConfig(minAttribs, maxAttribs);
        }

        bool ret = _Create(width, height, title, fullscreen);

        mContext = CreateEGLContext();
        mContext->BeginContext();
        ::EGLSurface oldDrawableDraw = eglGetCurrentSurface(EGL_DRAW);
        ::EGLSurface oldDrawableRead = eglGetCurrentSurface(EGL_READ);
        ::EGLContext oldContext = eglGetCurrentContext();

        int glConfigID;
        mGLSupport->GetGLConfigAttrib(mEglConfig, EGL_CONFIG_ID, &glConfigID);

        DI_INFO("EGLWindow::create used FBConfigID = %d", glConfigID);
        return ret;
    }
Ejemplo n.º 6
0
///
//  esCreateWindow()
//
//      title - name for title bar of window
//      width - width of window to create
//      height - height of window to create
//      flags  - bitwise or of window creation flags 
//          ES_WINDOW_ALPHA       - specifies that the framebuffer should have alpha
//          ES_WINDOW_DEPTH       - specifies that a depth buffer should be created
//          ES_WINDOW_STENCIL     - specifies that a stencil buffer should be created
//          ES_WINDOW_MULTISAMPLE - specifies that a multi-sample buffer should be created
//
GLboolean ESUTIL_API esCreateWindow ( ESContext *esContext, LPCTSTR title, GLint width, GLint height, GLuint flags )
{
   EGLint attribList[] =
   {
       EGL_RED_SIZE,       5,
       EGL_GREEN_SIZE,     6,
       EGL_BLUE_SIZE,      5,
       EGL_ALPHA_SIZE,     (flags & ES_WINDOW_ALPHA) ? 8 : EGL_DONT_CARE,
       EGL_DEPTH_SIZE,     (flags & ES_WINDOW_DEPTH) ? 8 : EGL_DONT_CARE,
       EGL_STENCIL_SIZE,   (flags & ES_WINDOW_STENCIL) ? 8 : EGL_DONT_CARE,
       EGL_SAMPLE_BUFFERS, (flags & ES_WINDOW_MULTISAMPLE) ? 1 : 0,
       EGL_NONE
   };
   
   if ( esContext == NULL )
   {
      return GL_FALSE;
   }

   esContext->width = width;
   esContext->height = height;

   if ( !WinCreate ( esContext, title) )
   {
      return GL_FALSE;
   }

  
   if ( !CreateEGLContext ( esContext->hWnd,
                            &esContext->eglDisplay,
                            &esContext->eglContext,
                            &esContext->eglSurface,
                            attribList) )
   {
      return GL_FALSE;
   }
   

   return GL_TRUE;
}
Ejemplo n.º 7
0
EGLBoolean InitEGL( char* title, float screenWidth, float screenHeight, GLuint flags )
{
	WinCreate( title, screenWidth, screenHeight );
	CreateEGLContext( flags );
	return EGL_TRUE;
}
Ejemplo n.º 8
0
int initGraphics( int w, int h, int fullscreen )
{
	int result = SDL_Init( /*SDL_INIT_TIMER |*/ SDL_INIT_AUDIO | SDL_INIT_VIDEO );

	SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
	SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);

	g_window = SDL_CreateWindow(NULL, 100, 100, w, h, SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN/* | SDL_WINDOW_BORDERLESS*/ | (fullscreen ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0));

#ifdef GJ_OS_WINDOWS
	SDL_SysWMinfo info; 
	SDL_VERSION(&info.version); // initialize info structure with SDL version info 
	SDL_bool get_win_info = SDL_GetWindowWMInfo(g_window, &info); 
	SDL_assert_release(get_win_info); 
	EGLNativeWindowType hWnd = info.info.win.window; 

	g_context = new ESContext(); 

	g_context->width = w;
	g_context->height = h;
	g_context->hWnd = hWnd; 

	EGLint configAttribList[] = 
	{ 
		EGL_RED_SIZE,       8, 
		EGL_GREEN_SIZE,     8, 
		EGL_BLUE_SIZE,      8, 
		EGL_ALPHA_SIZE,     8 /*: EGL_DONT_CARE*/, 
		EGL_DEPTH_SIZE,     EGL_DONT_CARE, 
		EGL_STENCIL_SIZE,   EGL_DONT_CARE, 
		EGL_SAMPLE_BUFFERS, 0, 
		EGL_NONE 
	}; 
	EGLint surfaceAttribList[] = 
	{ 
		// attribute, value
		EGL_NONE, EGL_NONE 
	}; 

	if ( !g_context ) 
	{ 
		//throw std::runtime_error("can't create opengl es 2.0 context, NULL es_context"); 
	} 

	EGLBoolean is_context_created = CreateEGLContext(g_context->hWnd, 
		&g_context->eglDisplay, 
		&g_context->eglContext, 
		&g_context->eglSurface, 
		configAttribList, 
		surfaceAttribList); 

	if (is_context_created == 0) 
	{ 
		//throw std::runtime_error("can't create opengl es 2.0 context"); 
	} 
#else 
	g_context = SDL_GL_CreateContext(g_window); 
	//int result = SDL_GL_SetSwapInterval(0); 
	//SDL_assert(0 == result); 
#endif 

	initGLESExtensions();

	return 0;
}