• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.

Archived

This topic is now archived and is closed to further replies.

Spider_In_A_Web

OpengGl text, An easy way???

4 posts in this topic

Hello all, Iam quickly writing a small asteroids game using open Gl, and in need to get some text on screen, i currently have the text drawn using Windows GDI but this is far from a good solution, and i was wondering, does OpenGL have any text drawing features, or is there any good tut''s on this topic Cheers, Paul
0

Share this post


Link to post
Share on other sites
What I did was get a 256x256 gdi bitmap and draw all the ascii letters on to it, and draw each letter on a quad. Unfortunately I''m going to school right now so if you want some source or help I''ll get back to you tonight or tomorrow morning.

It was a pain in the ass to get it working, unless you do some tricky texcoord and texture carving work you can''t use any point size text you want.

------------
- outRider -
0

Share this post


Link to post
Share on other sites
For openGL, the best way is probably to use texture bitmap fonts. They are probably the most versatile and easy to use (After you get the basic stuff down). Basically you do what outrider was saying with the 256x256 bitmap and you use quads. There are many programs out that will generate this kind of bitmap from a font if you don''t want to do it the hard way. www.lmnopc.com has one that works rather well. As for what outRider was saying about point sizes. Thats not hard at all. Simply call a glScalef(x,y) and that scale the text smaller or larger depending on what values you put inside it. If you need more help, NeHe has some great tutorials on fonts at nehe.gamedev.net

-Shaun (Salec)
0

Share this post


Link to post
Share on other sites
Salec, true about the glScale(), but I meant working with larger point sizes when you're creating the font, which means you'd have to use a larger texture, which would leave empty spaces, which would require you to find texcoords that are not related to the image dimentions, and you'd have to carve the texture up for cards that don't support larger textures, etc etc. It was a while before I realized that you could glScale without much blurring and save yourself the work.

Anyway, here's some source for you.


FONT* CreateTTFont(HDC hDC, const char *pszFontname)
{
FONT *Font;
HFONT hFont;
HBITMAP hBmp;
HBRUSH hBrush;
LOGBRUSH LogBrush;
HDC hTempDC;
int x, y;
char cCurrentChar = 0;
BITMAPINFO BmpInfo;
bool bNullDC;
ABC CharWidths[256];

if (hDC == NULL)
{
hDC = CreateDC("DISPLAY", NULL, NULL, NULL);
hTempDC = CreateCompatibleDC(hDC);
bNullDC = true;
}
else
{
hTempDC = CreateCompatibleDC(hDC);
bNullDC = false;
}

hFont = CreateFont(-14, 0, 0, 0, FW_NORMAL, false, false, false, ANSI_CHARSET, OUT_TT_PRECIS, CLIP_DEFAULT_PRECIS, PROOF_QUALITY, FF_DONTCARE | DEFAULT_PITCH, pszFontname);
SelectObject(hTempDC, hFont);

SetBkMode(hTempDC, TRANSPARENT);
SetTextColor(hTempDC, 0xFFFFFF);

memset(&BmpInfo, 0, sizeof(BITMAPINFO));
BmpInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
BmpInfo.bmiHeader.biBitCount = 32;
BmpInfo.bmiHeader.biPlanes = 1;
BmpInfo.bmiHeader.biWidth = 256;
BmpInfo.bmiHeader.biHeight = 256;
BmpInfo.bmiHeader.biCompression = BI_RGB;

hBmp = CreateDIBSection(hTempDC, &BmpInfo, DIB_RGB_COLORS, NULL, NULL, NULL);
SelectObject(hTempDC, hBmp);

LogBrush.lbStyle = BS_SOLID;
LogBrush.lbColor = 0xFF00FF;

hBrush = CreateBrushIndirect(&LogBrush);
SelectObject(hTempDC, hBrush);

ExtFloodFill(hTempDC, 0, 0, 0x000000, FLOODFILLSURFACE);

GetCharABCWidths(hTempDC, 0, 255, CharWidths);

for (y = 0; y < 256; y += 16)
{
for (x = 0; x < 256; x += 16)
{
TextOut(hTempDC, x - CharWidths[cCurrentChar].abcA, y, &cCurrentChar, 1);
cCurrentChar++;
}
}

Font = (FONT *)malloc(sizeof(FONT));
Font->byStartChar = 0;
Font->nChars = 256;
Font->iFontTextureWidth = 256;
Font->iFontTextureHeight = 256;

memset(&BmpInfo, 0, sizeof(BITMAPINFO));
BmpInfo.bmiHeader.biSize = sizeof(BITMAPINFO);
GetDIBits(hTempDC, hBmp, 0, 0, NULL, &BmpInfo, DIB_RGB_COLORS);
Font->pFontTexture = (BYTE *)malloc(BmpInfo.bmiHeader.biWidth * BmpInfo.bmiHeader.biHeight * BmpInfo.bmiHeader.biBitCount / 8);
GetDIBits(hTempDC, hBmp, 0, BmpInfo.bmiHeader.biHeight, Font->pFontTexture, &BmpInfo, DIB_RGB_COLORS);

// If the pixel is black, then it has an alpha of 0, so it wont be drawn.
for (x = 0; x < 256 * 256 * 4; x += 4)
{
if (Font->pFontTexture[x] == 255 && Font->pFontTexture[x + 1] == 0 && Font->pFontTexture[x + 2] == 255)
Font->pFontTexture[x + 3] = 0;
else
Font->pFontTexture[x + 3] = 255;
}

glGenTextures(1, &Font->iFontTextureID);
glBindTexture(GL_TEXTURE_2D, Font->iFontTextureID);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
glTexEnvi(GL_TEXTURE_2D, GL_TEXTURE_ENV_MODE, GL_DECAL);
glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE4_ALPHA4, BmpInfo.bmiHeader.biWidth, BmpInfo.bmiHeader.biHeight, 0, GL_BGRA_EXT, GL_UNSIGNED_BYTE, Font->pFontTexture);

Font->iFontListID = CreateFontDisplayLists(Font->iFontTextureID, CharWidths);

DeleteObject(hFont);
DeleteObject(hBmp);
DeleteObject(hBrush);
DeleteDC(hTempDC);
if (bNullDC)
DeleteDC(hDC);

return Font;
}

int CreateFontDisplayLists(int iFontTextureID, ABC *CharWidths)
{
int iFontListID;
int x, y;
int CurrentChar = 0;

iFontListID = glGenLists(256);

for (y = 16; y > 0; y--)
{
for (x = 0; x < 16; x++)
{
glNewList(iFontListID + CurrentChar, GL_COMPILE);
glTranslatef((float)CharWidths[CurrentChar].abcA, 0.0f, 0.0f);
glBegin(GL_TRIANGLE_STRIP);
glTexCoord2f(GRID_DIVISOR * x, GRID_DIVISOR * (y - 1)); glVertex2f(0.0f, 0.0f);
glTexCoord2f(GRID_DIVISOR * (x + 1), GRID_DIVISOR * (y - 1)); glVertex2f(16.0f, 0.0f);
glTexCoord2f(GRID_DIVISOR * x, GRID_DIVISOR * y); glVertex2f(0.0f, 16.0f);
glTexCoord2f(GRID_DIVISOR * (x + 1), GRID_DIVISOR * y); glVertex2f(16.0f, 16.0f);
glEnd();
glTranslatef((float)(CharWidths[CurrentChar].abcB + CharWidths[CurrentChar].abcC), 0.0f, 0.0f);
glEndList();
CurrentChar++;
}
}

return iFontListID;
}


The size of the font was 14 I think, thats because with overhanging and underhanging some characters were 16 pts high. So on a 256x256 texture you could fit 256 characters each with a cell of 16x16. GRID_DIVISOR was 16/256, 0.0625, which is needed for the texcoords since they have to be clamped to [0, 1].

------------
- outRider -

Edited by - outRider on October 18, 2001 10:15:24 AM
0

Share this post


Link to post
Share on other sites