Ejemplo n.º 1
0
void
OpenGL::SetupViewport(Point2D<unsigned> &size, DisplayOrientation_t orientation)
{
  window_size = size;

  glViewport(0, 0, size.x, size.y);

#ifdef USE_GLSL
  projection_matrix = glm::rotate(glm::mat4(),
                                  OrientationToRotation(orientation),
                                  glm::vec3(0, 0, 1));
  OrientationSwap(size, orientation);
  projection_matrix = glm::ortho<float>(0, size.x, size.y, 0, -1, 1);
  UpdateShaderProjectionMatrix();
#else
  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  glRotatef(OrientationToRotation(orientation), 0, 0, 1);
  OrientationSwap(size, orientation);
#ifdef HAVE_GLES
  glOrthox(0, size.x << 16, size.y << 16, 0, -(1<<16), 1<<16);
#else
  glOrtho(0, size.x, size.y, 0, -1, 1);
#endif

  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();
#endif

  viewport_size = size;

#ifdef SOFTWARE_ROTATE_DISPLAY
  OpenGL::display_orientation = orientation;
#endif
}
Ejemplo n.º 2
0
void resizeWindow(AndroidContext *rc)
{
    LOG( ANDROID_LOG_VERBOSE, TAG, "resizeWindow : start");
    /* Height / width ration */
    GLfloat ratio;

    /* Protect against a divide by zero */
    if (rc->height==0)
    {
    	rc->height=1;
    }

    ratio=(GLfloat)rc->width/(GLfloat)rc->height;

    /* Setup our viewport. */
    glViewport(0, 0, (GLsizei)rc->width, (GLsizei)rc->height);

    /* change to the projection matrix and set our viewing volume. */
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();

    /* Set our perspective */
    glOrthox(0, INT2FIX(rc->width), 0, INT2FIX(rc->height), INT2FIX(-1), INT2FIX(1));

    /* Make sure we're chaning the model view and not the projection */
    glMatrixMode(GL_MODELVIEW);

    /* Reset The View */
    glLoadIdentity();
    LOG( ANDROID_LOG_VERBOSE, TAG, "resizeWindow : end");
}
static inline void beginDrawingWireframe()
{
    glPushMatrix();
    glLoadIdentity();
    glOrthox( 0, SDL_ANDROID_sWindowWidth * 0x10000, SDL_ANDROID_sWindowHeight * 0x10000, 0, 0, 1 * 0x10000 );
    glPushMatrix();
    glEnableClientState(GL_VERTEX_ARRAY);
}
Ejemplo n.º 4
0
int SDL_ANDROID_CallJavaSwapBuffers()
{
	if( !glContextLost )
	{
		SDL_ANDROID_drawTouchscreenKeyboard();
	}
	
	// Clear part of screen not used by SDL - on Android the screen contains garbage after each frame
	if( SDL_ANDROID_ForceClearScreenRect.w != 0 && SDL_ANDROID_ForceClearScreenRect.h != 0 )
	{
		glPushMatrix();
		glLoadIdentity();
		glOrthox( 0, (SDL_ANDROID_sRealWindowWidth) * 0x10000, SDL_ANDROID_sRealWindowHeight * 0x10000, 0, 0, 1 * 0x10000 );
		glColor4x(0, 0, 0, 0x10000);
		glEnableClientState(GL_VERTEX_ARRAY);
		
		GLshort vertices[] = {	SDL_ANDROID_ForceClearScreenRect.x, SDL_ANDROID_ForceClearScreenRect.y,
								SDL_ANDROID_ForceClearScreenRect.x + SDL_ANDROID_ForceClearScreenRect.w, SDL_ANDROID_ForceClearScreenRect.y,
								SDL_ANDROID_ForceClearScreenRect.x + SDL_ANDROID_ForceClearScreenRect.w, SDL_ANDROID_ForceClearScreenRect.y + SDL_ANDROID_ForceClearScreenRect.h,
								SDL_ANDROID_ForceClearScreenRect.x, SDL_ANDROID_ForceClearScreenRect.y + SDL_ANDROID_ForceClearScreenRect.h };
		glVertexPointer(2, GL_SHORT, 0, vertices);
		glDrawArrays(GL_TRIANGLE_FAN, 0, 4);

		glDisableClientState(GL_VERTEX_ARRAY);
		glPopMatrix();
	}

	if( ! (*JavaEnv)->CallIntMethod( JavaEnv, JavaRenderer, JavaSwapBuffers ) )
		return 0;
	if( glContextLost )
	{
		glContextLost = 0;
		__android_log_print(ANDROID_LOG_INFO, "libSDL", "OpenGL context recreated, refreshing textures");
		SDL_ANDROID_VideoContextRecreated();
		appRestoredCallback();
		if(openALRestoredCallback)
			openALRestoredCallback();
	}
	if( showScreenKeyboardDeferred )
	{
		showScreenKeyboardDeferred = 0;
		(*JavaEnv)->CallVoidMethod( JavaEnv, JavaRenderer, JavaShowScreenKeyboard, (*JavaEnv)->NewStringUTF(JavaEnv, showScreenKeyboardOldText), showScreenKeyboardSendBackspace );
	}
	SDL_ANDROID_ProcessDeferredEvents();
	return 1;
}
Ejemplo n.º 5
0
void
OpenGL::SetupViewport(unsigned width, unsigned height)
{
  screen_width = width;
  screen_height = height;

  glViewport(0, 0, width, height);
  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
#ifdef HAVE_GLES
  glOrthox(0, width << 16, height << 16, 0, -(1<<16), 1<<16);
#else
  glOrtho(0, width, height, 0, -1, 1);
#endif

  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();
}
Ejemplo n.º 6
0
static void ANDROID_FlipHWSurfaceInternal()
{
	//__android_log_print(ANDROID_LOG_INFO, "libSDL", "ANDROID_FlipHWSurface()");
	if( SDL_CurrentVideoSurface->hwdata && SDL_CurrentVideoSurface->pixels && ! ( SDL_CurrentVideoSurface->flags & SDL_HWSURFACE ) )
	{
		SDL_Rect rect;
		rect.x = 0;
		rect.y = 0;
		rect.w = SDL_CurrentVideoSurface->w;
		rect.h = SDL_CurrentVideoSurface->h;
		SDL_UpdateTexture((struct SDL_Texture *)SDL_CurrentVideoSurface->hwdata, &rect, SDL_CurrentVideoSurface->pixels, SDL_CurrentVideoSurface->pitch);
		SDL_RenderCopy((struct SDL_Texture *)SDL_CurrentVideoSurface->hwdata, &rect, &rect);
		if( SDL_ANDROID_ShowScreenUnderFinger && SDL_ANDROID_ShowScreenUnderFingerRect.w > 0 )
		{
			SDL_RenderCopy((struct SDL_Texture *)SDL_CurrentVideoSurface->hwdata, &SDL_ANDROID_ShowScreenUnderFingerRectSrc, &SDL_ANDROID_ShowScreenUnderFingerRect);
			SDL_Rect frame = SDL_ANDROID_ShowScreenUnderFingerRect;
			// For some reason this code fails - it just outputs nothing to screen
			/*
			SDL_SetRenderDrawColor(0, 0, 0, SDL_ALPHA_OPAQUE);
			SDL_RenderFillRect(&SDL_ANDROID_ShowScreenUnderFingerRect);
			SDL_SetRenderDrawColor(255, 255, 255, SDL_ALPHA_OPAQUE);
			SDL_RenderDrawRect(&SDL_ANDROID_ShowScreenUnderFingerRectSrc);
			SDL_SetRenderDrawColor(0, 0, 0, SDL_ALPHA_OPAQUE);
			SDL_RenderDrawRect(&frame);
			*/
			// Do it old-fashioned way with direct GL calls
			glPushMatrix();
			glLoadIdentity();
			glOrthox( 0, SDL_ANDROID_sFakeWindowWidth * 0x10000, SDL_ANDROID_sFakeWindowHeight * 0x10000, 0, 0, 1 * 0x10000 );
			glColor4x(0, 0, 0, 0x10000);
			glEnableClientState(GL_VERTEX_ARRAY);
			glColor4x(0, 0, 0, 0x10000);
			GLshort vertices[] = {	frame.x, frame.y,
									frame.x + frame.w, frame.y,
									frame.x + frame.w, frame.y + frame.h,
									frame.x, frame.y + frame.h };
			glVertexPointer(2, GL_SHORT, 0, vertices);
			glDrawArrays(GL_LINE_LOOP, 0, 4);
			glDisableClientState(GL_VERTEX_ARRAY);
			glPopMatrix();
			glFlush();
		}
	}
};
Ejemplo n.º 7
0
void resizeWindow(AndroidContext *rc)
{
	LOG( ANDROID_LOG_VERBOSE, TAG, "resizeWindow : start");
	/* Height / width ration */
	GLfloat ratio;

	/* Protect against a divide by zero */
	if (rc->height==0)
	{
		rc->height=1;
	}

	ratio=(GLfloat)rc->width/(GLfloat)rc->height;

	/* Setup our viewport. */
	glViewport(0, 0, (GLsizei)rc->width, (GLsizei)rc->height);
#ifndef GPAC_USE_GLES2
	/* change to the projection matrix and set our viewing volume. */
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();

	/* Set our perspective */
	glOrthox(0, INT2FIX(rc->width), 0, INT2FIX(rc->height), INT2FIX(-1), INT2FIX(1));

	/* Make sure we're chaning the model view and not the projection */
	glMatrixMode(GL_MODELVIEW);

	/* Reset The View */
	glLoadIdentity();
#else
	GL_CHECK_ERR
	glUseProgram(rc->base_program);
	calculate_ortho(0, INT2FIX(rc->width), 0, INT2FIX(rc->height), INT2FIX(-1), INT2FIX(1), rc);
	load_matrix_shaders(rc->base_program, (Fixed *) rc->ortho.m, "gfProjectionMatrix");
	load_matrix_shaders(rc->base_program, (Fixed *) rc->identity.m, "gfModelViewMatrix");
	GL_CHECK_ERR
#endif
	LOG( ANDROID_LOG_VERBOSE, TAG, "resizeWindow : end");
}
Ejemplo n.º 8
0
void FGAPIENTRY 
glutBitmapCharacterPoints(void* fontID, int x, int y, int character)
{
	const GLubyte* face;
	SFG_Font* font = fghFontByID(fontID);

	if(!font)
		return;

    if(!(character >= 1)&&(character < 256))
		return;

    face = font->Characters[ character - 1 ];

	glMatrixMode(GL_PROJECTION);
	glPushMatrix();
	glLoadIdentity(); 

	glOrthox(0, _INT2FIXED(fgStructure.Window->State.Width), 0, 
		_INT2FIXED(fgStructure.Window->State.Height), 0, _INT2FIXED(1));
	
	glMatrixMode(GL_MODELVIEW);
	glPushMatrix();
    glLoadIdentity(); 

	glDisable(GL_DEPTH_TEST);
	
	glTranslatex(_INT2FIXED(x), _INT2FIXED(y), 0);
	__glutBitmapCharacter(font, character);
	glTranslatex(_INT2FIXED(face[0]), 0, 0);

	glEnable(GL_DEPTH_TEST);
	glMatrixMode(GL_PROJECTION);
	glPopMatrix();
	glMatrixMode(GL_MODELVIEW);
	glPopMatrix();
}
Ejemplo n.º 9
0
void
OpenGL::SetupViewport(Point2D<unsigned> size)
{
  window_size = size;
  viewport_size = size;

  glViewport(0, 0, size.x, size.y);

#ifdef USE_GLSL
  projection_matrix = glm::ortho<float>(0, size.x, size.y, 0, -1, 1);
  UpdateShaderProjectionMatrix();
#else
  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
#ifdef HAVE_GLES
  glOrthox(0, size.x << 16, size.y << 16, 0, -(1<<16), 1<<16);
#else
  glOrtho(0, size.x, size.y, 0, -1, 1);
#endif

  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();
#endif
}
Ejemplo n.º 10
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 glOrthoxLogged(GLfixed left, GLfixed right, GLfixed bottom, GLfixed top, GLfixed zNear, GLfixed zFar) {
	printf("glOrthox(%i, %i, %i, %i, %i, %i)\n", left, right, bottom, top, zNear, zFar);
	glOrthox(left, right, bottom, top, zNear, zFar);
}
Ejemplo n.º 12
0
void
TopCanvas::set()
{
  unsigned width = 640, height = 480;
#ifndef ANDROID
  Uint32 flags = SDL_ANYFORMAT;
#endif

#ifdef ENABLE_OPENGL
#ifndef ANDROID
  flags |= SDL_OPENGL;
#endif
#else /* !ENABLE_OPENGL */
  /* double buffering temporarily disabled on Android because
     Android's SDL port doesn't allow locking it then (which we need
     for SDL_gfx) */
  if (!is_android())
    flags |= SDL_DOUBLEBUF;

  /* we need async screen updates as long as we don't have a global
     frame rate */
  flags |= SDL_ASYNCBLIT;

  const SDL_VideoInfo *info = SDL_GetVideoInfo();
  assert(info != NULL);

  /* hardware surface temporarily disabled on Android because
     Android's SDL port doesn't allow locking it then (which we need
     for SDL_gfx) */
  if (!is_android() && info->hw_available)
    flags |= SDL_HWSURFACE;
  else
    flags |= SDL_SWSURFACE;
#endif /* !ENABLE_OPENGL */

  if (is_embedded()) {
#if defined(ANDROID)
    width = native_view->get_width();
    height = native_view->get_height();
#else
    flags |= SDL_FULLSCREEN;

    /* select a full-screen video mode */
    SDL_Rect **modes = SDL_ListModes(NULL, flags);
    if (modes == NULL)
      return;

    width = modes[0]->w;
    height = modes[0]->h;
#endif
  }

#ifdef ENABLE_OPENGL
#ifndef ANDROID
  ::SDL_SetVideoMode(width, height, 0, flags);
#endif
  OpenGL::SetupContext(width, height);
  Canvas::set(width, height);
#else
  Canvas::set(::SDL_SetVideoMode(width, height, 0, flags));
#endif

#ifdef ENABLE_OPENGL
  glViewport(0, 0, get_width(), get_height());
  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
#ifdef HAVE_GLES
  glOrthox(0, get_width()<<16, get_height()<<16, 0, -(1<<16), 1<<16);
#else
  glOrtho(0, get_width(), get_height(), 0, -1, 1);
#endif

  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();

  glDisable(GL_DEPTH_TEST);
  glDisable(GL_DITHER);
  glDisable(GL_LIGHTING);

  glEnableClientState(GL_VERTEX_ARRAY);
#endif
}
Ejemplo n.º 13
0
void FGAPIENTRY
glutTrueTypeStringPoints(WCHAR *fontname, int fontsize, int style, int x, int y, const WCHAR *string)
{
	int len, xx = 0, yy = 0, nbpoints = 0, i;
	GLshort *points;
	GLushort *indices;
	HFONT font;
	LOGFONTW	lf;	
	RECT rect;
	static HBITMAP bmp;
	static BYTE *img;
	static HDC hdc = NULL;
	static BITMAPINFO bi;
	SIZE sz;
	static EGLint width, height;

	if(!fontname || !string)
		return;
	if(!string[0])
		return;

	// Initialize static DC and DIB bitmap on the first call
	if(!hdc)
	{		
		// Create a device compatible DC
		hdc = CreateCompatibleDC(GetDC(fgStructure.Window->Window.Handle));	
		
		eglQuerySurface(fgDisplay.eglDisplay, fgStructure.Window->Window.Surface, EGL_WIDTH, &width);
		eglQuerySurface(fgDisplay.eglDisplay, fgStructure.Window->Window.Surface, EGL_HEIGHT, &height);

		// Create a DIB bitmap and attach it to the DC
		ZeroMemory(&bi, sizeof(BITMAPINFO));
		bi.bmiHeader.biSize=sizeof(BITMAPINFOHEADER);
		bi.bmiHeader.biWidth = width;
		bi.bmiHeader.biHeight = height; 
		bi.bmiHeader.biBitCount = 8;
		bi.bmiHeader.biPlanes = 1;
		bi.bmiHeader.biCompression = BI_RGB;
		
		bmp = CreateDIBSection(hdc, &bi, DIB_RGB_COLORS, &img, NULL, 0);
	
		SelectObject(hdc, bmp);
		
		SelectObject(hdc, GetStockObject(BLACK_BRUSH));

		SetBkMode(hdc, TRANSPARENT);
		SetTextColor(hdc, RGB(255, 255, 255));			
	}

	// Erase DC content	with the current black brush
	//Rectangle(hdc, 0, 0, width, height);
	ZeroMemory(img, width * height);

	// Create the font handle and attach it to the DC
	lf.lfCharSet = DEFAULT_CHARSET;
	lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
	lf.lfEscapement = 0;
	wcscpy(lf.lfFaceName, fontname);
	lf.lfHeight = -(fontsize * GetDeviceCaps(GetDC(fgStructure.Window->Window.Handle), LOGPIXELSY) / 72);
	lf.lfItalic = (style & 1) ? TRUE : FALSE;
	lf.lfOrientation = 0;
	lf.lfOutPrecision = OUT_DEFAULT_PRECIS;
	lf.lfPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE;
	lf.lfQuality = DEFAULT_QUALITY;
	lf.lfStrikeOut = FALSE;
	lf.lfUnderline = (style & 4) ? TRUE : FALSE;
	lf.lfWidth = 0;
	lf.lfWeight = (style & 2) ? FW_BOLD : FW_NORMAL;
	
	font = CreateFontIndirectW(&lf);

	SelectObject(hdc, font);

	// Draw text in white onto the bitmap
	len = wcslen(string);

	GetTextExtentPointW(hdc, string, len, &sz);

	rect.left = max(0, min(x, width));
	rect.top = max(0, min(y, height));
	rect.right = min(rect.left + sz.cx, width);
	rect.bottom = min(rect.top + sz.cy, height);

	DrawTextW(hdc, string, len, &rect, DT_LEFT | DT_BOTTOM);
	
	// Traverse the bitmap and add all white pixels into a points buffer
	points = (GLshort*)malloc(sz.cx * sz.cy * 2 * sizeof(short));

	for(yy = rect.top; yy < rect.bottom; yy++)
	{
		for(xx = rect.left; xx < rect.right; xx++)
		{
			if(img[xx + (height - yy) * width] != 0)
			{
				points[nbpoints * 2 + 0] = xx - x;
				points[nbpoints * 2 + 1] = (short)(rect.top + sz.cy - (yy - rect.top)) - y;
				nbpoints++;
			}
		}
	}

	// Delete GDI font object
	DeleteObject(font);
	
	// Prepare the index buffer
	indices = (GLushort*)malloc(nbpoints * sizeof(GLushort));
	for(i = 0; i < nbpoints; i++)
		indices[i] = i;

	// Draw the points buffer
	glMatrixMode(GL_PROJECTION);
	glPushMatrix();
	glLoadIdentity(); 

	glOrthox(0, _INT2FIXED(width), 
			0, _INT2FIXED(height), 
			0, _INT2FIXED(1));


	glMatrixMode(GL_MODELVIEW);
	glPushMatrix();
    glLoadIdentity(); 

	glDisable(GL_DEPTH_TEST);
	
	glTranslatex(_INT2FIXED(x), _INT2FIXED(y), 0);	
	
	glEnable(GL_ALPHA_TEST);
    glAlphaFuncx(GL_NOTEQUAL, 0);
	glDisableClientState(GL_TEXTURE_COORD_ARRAY);
    glDisableClientState(GL_COLOR_ARRAY);
    glDisableClientState(GL_NORMAL_ARRAY);
	glEnableClientState (GL_VERTEX_ARRAY);
    glVertexPointer(2, GL_SHORT, 0, points);

	glDrawElements(GL_POINTS,
                        nbpoints,
                        GL_UNSIGNED_SHORT,
                        indices);
	
	glDisable(GL_ALPHA_TEST);

	glEnable(GL_DEPTH_TEST);

	glPopMatrix();
	glMatrixMode(GL_PROJECTION);
	glPopMatrix();
	glMatrixMode(GL_MODELVIEW);

	free(indices);
	free(points);
}
Ejemplo n.º 14
0
void FGAPIENTRY 
glutBitmapStringPoints(void* fontID, int x, int y, const char *string)
{
    SFG_Font* font = fghFontByID(fontID);
	int numchar, xx = 0, yy = 0, nbpoints = 0, i, c;
	GLshort *points;
	GLushort *indices;

	if(!font || !string)
		return;
	if(!string[0])
		return;

	glMatrixMode(GL_PROJECTION);
	glPushMatrix();
	glLoadIdentity(); 

	glOrthox(0, _INT2FIXED(fgStructure.Window->State.Width), 0, 
		_INT2FIXED(fgStructure.Window->State.Height), 0, _INT2FIXED(1));

	glMatrixMode(GL_MODELVIEW);
	glPushMatrix();
    glLoadIdentity(); 

	glDisable(GL_DEPTH_TEST);
	
	glTranslatex(_INT2FIXED(x), _INT2FIXED(y), 0);

	numchar = (int)strlen((char*) string);

	points = (GLshort*)malloc(numchar * 
		font->Height * (*(font->Characters[ 'X' - 1 ])) *
		8 * sizeof(GLshort));

    for(c = 0; c < numchar; c++)
    {
		if(string[c] == '\n')
		{
			yy -= font->Height;
			xx = 0;
		}
		else
		{
			const GLubyte* face = font->Characters[ string[c] - 1 ];
			nbpoints += BitsToIndexedShorts(face+1, face[0], font->Height, points+(nbpoints*2), xx, yy);
			xx += face[0];
		}
	}

	glEnable(GL_ALPHA_TEST);
    glAlphaFuncx(GL_NOTEQUAL, 0);

	indices = (GLushort*)malloc(nbpoints*sizeof(GLushort));
	for(i = 0; i < nbpoints; i++)
		indices[i] = i;

	glDisableClientState(GL_TEXTURE_COORD_ARRAY);
    glDisableClientState(GL_COLOR_ARRAY);
    glDisableClientState(GL_NORMAL_ARRAY);
	glEnableClientState (GL_VERTEX_ARRAY);
    glVertexPointer(2, GL_SHORT, 0, points);

	glDrawElements(GL_POINTS,
                        nbpoints,
                        GL_UNSIGNED_SHORT,
                        indices);

	glDisable(GL_ALPHA_TEST);
	free(indices);
	free(points);

	glEnable(GL_DEPTH_TEST);
	
	glPopMatrix();
	glMatrixMode(GL_PROJECTION);
	glPopMatrix();
	glMatrixMode(GL_MODELVIEW);
}
Ejemplo n.º 15
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;
}