Hi all,
So I'm finally getting back to writing some code and I'm working on what will ultimately be a reusable piece of code. The full details aren't important but what I want to do is as follows:-
Use a PNG image containing a character set (fixed width, fixed height, ASCII character codes Row 1 0-15, Row 2 16-31 etc.) - Alpha provides transparency information
Use another PNG image containing 16x16 blocks of colour (organised in the same index sequence as character set) - This is loaded and the colours extracted from the cells
From these, I want to render fixed size text in a 2D orthographic (I think that's the term) way. With the background being one colour and the text being another (if I choose to colorise it - I may not want to change the color of the font texture, but I can simply bind that to vertices so I'm not too worried about that).
I thought by having the font in white I could colorise it using glColor prior to my glBegin(GL_QUAD) glVertex..... etc. that binds the glyph in the font texture to the four vertices. Unfortunately this changes the color of the fill behind it, so as I understand it, I need to use shaders to achieve what I want but I'm struggling.
So this image shows my source images (font and palette):-
Sample.png
And this, whilst basic shows what I'd like to do:-
OutputSample.png
My current code is this (this renders on a 24x24 grid using 16x16 blocks so there is an 8 pixel gap between them):-
Code:
glClearColor(0,0,0,0); // background color of the context
glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT); // clear background and depth buffer
glDisable(GL_BLEND);
glViewport(0,0,fRenderWidth,fRenderHeight);
glLoadIdentity; // set it to initial state
gluOrtho2D(0,fRenderWidth,fRenderHeight,0);
glEnable(GL_TEXTURE_2D);
glColor4f(1,1,1,1);
for y:=0 to 15 do //5 do
begin
ty:=y*24;
for x:=0 to 15 do //5 do
begin
tx:=x*24;
glDisable(GL_BLEND);
glBindTexture(GL_TEXTURE_2D,fPalettes[0]);
glBegin(GL_QUADS);
glTexCoord2f(x*ONE_16TH,y*ONE_16TH);
glVertex2i(tx,ty);
glTexCoord2f(x*ONE_16TH+ONE_16TH,y*ONE_16TH);
glVertex2i(tx+16,ty);
glTexCoord2f(x*ONE_16TH+ONE_16TH,y*ONE_16TH+ONE_16TH);
glVertex2i(tx+16,ty+16);
glTexCoord2f(x*ONE_16TH,y*ONE_16TH+ONE_16TH);
glVertex2i(tx,ty+16);
glEnd;
glBindTexture(GL_TEXTURE_2D,fCharacterSets[0].texture);
glUseProgram(fTextRender);
glBegin(GL_QUADS);
glTexCoord2f(x*ONE_16TH,y*ONE_16TH);
glVertex2i(tx,ty);
glTexCoord2f(x*ONE_16TH+ONE_16TH,y*ONE_16TH);
glVertex2i(tx+16,ty);
glTexCoord2f(x*ONE_16TH+ONE_16TH,y*ONE_16TH+ONE_16TH);
glVertex2i(tx+16,ty+16);
glTexCoord2f(x*ONE_16TH,y*ONE_16TH+ONE_16TH);
glVertex2i(tx,ty+16);
glEnd;
glUseProgram(0);
end;
end;
Bookmarks