Exemplo n.º 1
0
void SetExtGLFuncs(void)
{
 //----------------------------------------------------//

 SetFixes();                                           // update fix infos

 //----------------------------------------------------//

  {
   if(bAdvancedBlend) bUseMultiPass=TRUE;              // -> pseudo-advanced with 2 passes
   else               bUseMultiPass=FALSE;             // -> or simple 'bright color' mode
//   bGLBlend=FALSE;                                     // -> no ext blending!
   glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); glError();
  }

 if(bOpaquePass)                                        // opaque mode?
  {
   if(dwActFixes&32) 
    {
     TCF[0]=CP8RGBA_0;
     PalTexturedColourFn=CP8RGBA;                      // -> init col func
    }
   else
    {
     TCF[0]=XP8RGBA_0;
     PalTexturedColourFn=XP8RGBA;                      // -> init col func
    }

   TCF[1]=XP8RGBA_1;
   glAlphaFuncx(GL_GREATER,0.49f); glError();

  }
 else                                                  // no opaque mode?
  {
   TCF[0]=TCF[1]=P8RGBA;
   PalTexturedColourFn=P8RGBA;                         // -> init col func
   glAlphaFuncx(GL_NOTEQUAL,0); glError();             // --> set alpha func

  }

 //----------------------------------------------------//

 LoadSubTexFn=LoadSubTexturePageSort;                  // init load tex ptr

 bBlendEnable=FALSE;                                   // init blending: off
 glDisable(GL_BLEND); glError();


 SetScanTrans();                                       // init scan lines (if wanted)
}
Exemplo n.º 2
0
/*
 * Draw a bitmap character
 */
void FGAPIENTRY 
glutBitmapCharacterTex(void* fontID, int x, int y, int character)
{
#if (GL_OES_VERSION_1_1 >= 1)
    const GLubyte* face;
    SFG_Font* font = fghFontByID(fontID);
	GLint v[] = {0, 0, _INT2FIXED(64), _INT2FIXED(64)}; //face[0], font->Height};
	GLubyte buff[64*64];
	GLuint tid;

	if(!font)
		return;

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

    /*
     * Find the character we want to draw (???)
     */
    face = font->Characters[ character - 1 ];
	
	memset(buff, 0, 64*64*sizeof(GLubyte));
	BitsToBytes(face+1, face[0], font->Height, buff, 64, 64);

	glGenTextures(1, &tid);
    glBindTexture(GL_TEXTURE_2D, tid);

    glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA,
                            64, 64, 0, GL_ALPHA, GL_UNSIGNED_BYTE,
                            buff);

    glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

	glEnable(GL_TEXTURE_2D);

    glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
	glEnable(GL_ALPHA_TEST);
    glAlphaFuncx(GL_EQUAL, 0);

	glTexParameterxv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, v);

	glDrawTexxOES(_INT2FIXED(x), _INT2FIXED(y), _INT2FIXED(0), _INT2FIXED(16), _INT2FIXED(16)); //face[0], font->Height);

    glDisable(GL_ALPHA_TEST);
    glDisable(GL_TEXTURE_2D);

	glDeleteTextures(1, &tid);
#endif
}
Exemplo n.º 3
0
/*
 * Draw a bitmap character
 */
void 
__glutBitmapCharacter(SFG_Font* font, int character)
{
	int i, nbpoints;
	GLshort *points;
	const GLubyte *face;
	GLushort indices[64*64];

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

    /*
     * Find the character we want to draw (???)
     */
    face = font->Characters[ character - 1 ];

	points = (GLshort*)malloc(font->Height * face[0] * 2 * sizeof(GLshort));
	nbpoints = BitsToIndexedShorts(face+1, face[0], font->Height, points, 0, 0);

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

	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(points);
}
void glAlphaFuncxLogged(GLenum func, GLclampx ref) {
	printf("glAlphaFuncx(%s, %i)\n", GLEnumName(func), ref);
	glAlphaFuncx(func, ref);
}
Exemplo n.º 5
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);
}
Exemplo n.º 6
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);
}