Ejemplo n.º 1
0
void OSystem_Android::clearScreen(FixupType type, byte count) {
	assert(count > 0);

	bool sm = _show_mouse;
	_show_mouse = false;

	GLCALL(glDisable(GL_SCISSOR_TEST));

	for (byte i = 0; i < count; ++i) {
		// clear screen
		GLCALL(glClearColorx(0, 0, 0, 1 << 16));
		GLCALL(glClear(GL_COLOR_BUFFER_BIT));

		switch (type) {
		case kClear:
			break;

		case kClearSwap:
			JNI::swapBuffers();
			break;

		case kClearUpdate:
			_force_redraw = true;
			updateScreen();
			break;
		}
	}

	if (!_show_overlay)
		GLCALL(glEnable(GL_SCISSOR_TEST));

	_show_mouse = sm;
	_force_redraw = true;
}
Ejemplo n.º 2
0
bool InitOGLES()
{  
  EGLConfig configs[10];
  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
  };
  
  hDC = GetWindowDC(hWnd);
  glesDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);	 
  
  if(!eglInitialize(glesDisplay, NULL, NULL)) 
    return false;
	
  if(!eglChooseConfig(glesDisplay, configAttribs, &configs[0], 10,  &matchingConfigs)) 
   return false;
	
  if(matchingConfigs < 1)  return false;	  

  glesSurface = eglCreateWindowSurface(glesDisplay, configs[0], hWnd, NULL);	
  if(!glesSurface) return false;
  
  glesContext=eglCreateContext(glesDisplay,configs[0],0,NULL);

  if(!glesContext) return false;

  eglMakeCurrent(glesDisplay, glesSurface, glesSurface, glesContext); 
    
  glClearColorx(0,0,0,0);
  glShadeModel(GL_SMOOTH);  
  glEnable(GL_DEPTH_TEST);
  glEnable(GL_CULL_FACE);

  RECT r;
  GetClientRect(hWnd, &r);  
  //kWindowWidth = r.right - r.left;
  //kWindowHeight = r.bottom - r.top;
  glViewport(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);	//r.left, r.top, WindowWidth, WindowHeight);
  
  // we need the fastest rendering as possible
  glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST);

  return true;
}
Ejemplo n.º 3
0
static void prepareFrame(int width, int height)
{
    glViewport(0, 0, width, height);

    glClearColorx((GLfixed)(0.1f * 65536),
                  (GLfixed)(0.2f * 65536),
                  (GLfixed)(0.3f * 65536), 0x10000);
    glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(45, (float)width / height, 0.5f, 150);

    glMatrixMode(GL_MODELVIEW);

    glLoadIdentity();
}
Ejemplo n.º 4
0
static void ogl_setClearColor(int r, int g, int b) {
	glClearColorx(r<<8, g<<8, b<<8, 255<<8);
}
Ejemplo n.º 5
0
int main(void) {
    EGLDisplay m_eglDisplay;
    EGLContext m_eglContext;
    EGLSurface m_eglSurface;
    EGLint attributeList[] = { EGL_RED_SIZE, 1, EGL_DEPTH_SIZE, 1, EGL_NONE };
    EGLint		aEGLAttributes[] = {
        EGL_RED_SIZE, 8,
        EGL_GREEN_SIZE, 8,
        EGL_BLUE_SIZE, 8,
        EGL_DEPTH_SIZE, 16,
        EGL_RENDERABLE_TYPE, EGL_OPENGL_ES_BIT,
        EGL_NONE
    };
    EGLint		aEGLContextAttributes[] = {
        EGL_CONTEXT_CLIENT_VERSION, 1,
        EGL_NONE
    };
    EGLConfig m_eglConfig[1];
    EGLint nConfigs;
    unsigned char mIndices[] = { 0, 1, 2 };
    signed short mVertices[] = {
        -50, -29, 0,
        50, -29, 0,
        0,  58, 0
    };
    HWND hwnd;
    HDC hdc;
    MSG sMessage;
    int bDone = 0;

    // Platform init.
    platform(&hwnd, 640, 480);
    ShowWindow(hwnd, SW_SHOW);
    SetForegroundWindow(hwnd);
    SetFocus(hwnd);

    // EGL init.
    hdc = GetDC(hwnd);
    m_eglDisplay = eglGetDisplay(hdc);
    eglInitialize(m_eglDisplay, NULL, NULL);
    eglChooseConfig(m_eglDisplay, aEGLAttributes, m_eglConfig, 1, &nConfigs);
    printf("EGLConfig = %p\n", m_eglConfig[0]);
    m_eglSurface = eglCreateWindowSurface(m_eglDisplay, m_eglConfig[0], (NativeWindowType)hwnd, 0);
    m_eglContext = eglCreateContext(m_eglDisplay, m_eglConfig[0], EGL_NO_CONTEXT, aEGLContextAttributes);
    printf("EGLContext = %p\n", m_eglContext);
    eglMakeCurrent(m_eglDisplay, m_eglSurface, m_eglSurface, m_eglContext);

    glEnableClientState(GL_VERTEX_ARRAY);
    glVertexPointer(3, GL_SHORT, 0, mVertices);

    /* Set projection matrix so screen extends to (-160, -120) at bottom left 
    * and to (160, 120) at top right, with -128..128 as Z buffer. */

    glMatrixMode(GL_PROJECTION);
    glOrthox(-160<<16, 160<<16, -120<<16, 120<<16, -128<<16, 128<<16);

    glMatrixMode(GL_MODELVIEW);

    glClearColorx(0x10000, 0x10000, 0, 0);
    glColor4x(0x10000, 0, 0, 0);

    // Main event loop
    while(!bDone)
    {
        // Do Windows stuff:
        if(PeekMessage(&sMessage, NULL, 0, 0, PM_REMOVE))
        {
            if(sMessage.message == WM_QUIT)
            {
                bDone = 1;
            }
            else 
            {
                TranslateMessage(&sMessage);
                DispatchMessage(&sMessage);
            }
        }

        glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
        glDrawElements(GL_TRIANGLES, 3, GL_UNSIGNED_BYTE, mIndices);
        glRotatex(2<<16, 0, 0, 0x10000);
        eglSwapBuffers(m_eglDisplay, m_eglSurface);
        Sleep(30);
    }

    // Exit.
    eglMakeCurrent(m_eglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
    eglDestroyContext(m_eglDisplay, m_eglContext);
    eglDestroySurface(m_eglDisplay, m_eglSurface);
    eglTerminate(m_eglDisplay);

    ReleaseDC(hwnd, hdc);
    DestroyWindow(hwnd);


    return 0;
}
void glClearColorxLogged(GLclampx red, GLclampx green, GLclampx blue, GLclampx alpha) {
	printf("glClearColorx(%i, %i, %i, %i)\n", red, green, blue, alpha);
	glClearColorx(red, green, blue, alpha);
}
Ejemplo n.º 7
0
//----------------------------------------------------------------------------
BOOL InitOGLES()
{  
  EGLConfig configs[10];
  EGLint matchingConfigs;	

  /*configAttribs is a integers list that holds the desired format of 
   our framebuffer. We will ask for a framebuffer with 24 bits of 
   color and 16 bits of z-buffer. We also ask for a window buffer, not 
   a pbuffer or pixmap buffer*/	
  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
  };
  
  hDC = GetWindowDC(hWnd);
  glesDisplay = eglGetDisplay(hDC);	 //Ask for an available display

  //Display initialization (we don't care about the OGLES version numbers)
  if(!eglInitialize(glesDisplay, NULL, NULL)) 
    return FALSE;
	
  /*Ask for the framebuffer confiburation that best fits our 
  parameters. At most, we want 10 configurations*/
  if(!eglChooseConfig(glesDisplay, configAttribs, &configs[0], 10,  &matchingConfigs)) 
   return FALSE;
	
  //If there isn't any configuration enough good
  if (matchingConfigs < 1)  return FALSE;	  

  /*eglCreateWindowSurface creates an onscreen EGLSurface and returns 
  a handle  to it. Any EGL rendering context created with a 
  compatible EGLConfig can be used to render into this surface.*/
  glesSurface = eglCreateWindowSurface(glesDisplay, configs[0], hWnd, configAttribs);	
  if(!glesSurface) return FALSE;
  
  // Let's create our rendering context
  glesContext=eglCreateContext(glesDisplay,configs[0],0,configAttribs);

  if(!glesContext) return FALSE;

  //Now we will activate the context for rendering	
  eglMakeCurrent(glesDisplay, glesSurface, glesSurface, glesContext); 
    
  /*Remember: because we are programming for a mobile device, we cant 
  use any of the OpenGL ES functions that finish in 'f', we must use 
  the fixed point version (they finish in 'x'*/
  glClearColorx(0, 0, 0, 0);
  glShadeModel(GL_SMOOTH);  
  /*In order to set a viewport that fits entirely our window, we need 
  to know the window dimensions. They could be obtained through the   
  WinCE call GetWindowRect, using our window handle*/
  RECT r;
  GetWindowRect(hWnd, &r);  
  glViewport(r.left, r.top, r.right - r.left, r.bottom - r.top);	
	
  /*Setup of the projection matrix. We will use an ortho cube centered 
  at (0,0,0) with 100 units of edge*/
  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();    
  glOrthox(FixedFromInt(-50), FixedFromInt(50), 
           FixedFromInt(-50), FixedFromInt(50), 
           FixedFromInt(-50), FixedFromInt(50));
  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();
  return TRUE;
}
Ejemplo n.º 8
0
/*!
* \brief	Updates the OpenGL ES state
* \param	width	Rendering width.
* \param	height	Rendering height.
*//*-------------------------------------------------------------------*/
static void updateOpenGLESState(int width, int height)
{
    /* Define lights and materials for the OpenGL ES scene */
    static const GLfixed light_position[]	= { F2F(-50.f), F2F(50.f), F2F(50.f), F2F(0.0f) };
    static const GLfixed light_ambient[]	= { F2F(0.125f), F2F(0.125f), F2F(0.125f), F2F(1.0f) };
    static const GLfixed light_diffuse[]	= { F2F(0.7f), F2F(0.7f), F2F(0.7f), F2F(1.0f) };
    static const GLfixed material_spec[]	= { F2F(0.7f), F2F(0.7f), F2F(0.7f), F2F(0.0f) };
    static const GLfixed zero_vec4[]		= { F2F(0.0f), F2F(0.0f), F2F(0.0f), F2F(0.0f) };

    /* Define the aspect ratio for the perpective calculations so that 
    no distortion happens when the screen is resized */
    float aspect		= height ? (float)width/(float)height : 1.0f;

    glViewport			(0, 0, width, height);
    glScissor			(0, 0, width, height);

    /* Set the matrix mode to world coordinates */
    glMatrixMode		(GL_MODELVIEW);
    glLoadIdentity		();

    /* Setup lights and materials with the values given above */
    glLightxv			(GL_LIGHT0, GL_POSITION, light_position);
    glLightxv			(GL_LIGHT0, GL_AMBIENT, light_ambient);
    glLightxv			(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
    glLightxv			(GL_LIGHT0, GL_SPECULAR, zero_vec4);
    glMaterialxv		(GL_FRONT_AND_BACK, GL_SPECULAR, material_spec);

    /* Enable ligting, materials, backface culling and textures */
    glDisable			(GL_NORMALIZE);
    glEnable			(GL_LIGHTING);
    glEnable(GL_BLEND);
    glBlendFunc(GL_ONE, GL_ZERO);
    
    glEnable			(GL_LIGHT0);
    glEnable			(GL_COLOR_MATERIAL);
    glEnable			(GL_CULL_FACE);
    glEnable			(GL_TEXTURE_2D);

    /* Tell OpenGL to use nicest perspective correction */
    glHint				(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);

    /* Use flat shading and disable dithering */
    glShadeModel		(GL_FLAT);
    glDisable			(GL_DITHER);

    /* Setup the clear color and the current color for the OpenGL context */
    glClearColorx		(F2F(0.1f), F2F(0.2f), F2F(0.4f), F2F(1.f));
    glColor4x			(0x10000, 0x10000, 0x10000, 0x10000);

    /* Enable the use of vertex, normal and texture coordinate arrays */
    glEnableClientState	(GL_VERTEX_ARRAY);
    glEnableClientState	(GL_NORMAL_ARRAY);
    glEnableClientState	(GL_TEXTURE_COORD_ARRAY);

    /* Mipmaps do not work on all BREW devices, so disable it */
/*    glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);*/
    glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

    /* Update the projection matrix */
    glMatrixMode		(GL_PROJECTION);
    glLoadIdentity		();
    setGLESperspective	(60.f, aspect, 0.1f, 100.f);
}