C++ OpenGL / FreeType scrolling font
Looking for opinions on the best way to scroll text, Im using the freetype lib with OpenGL/c++ on Slackware.
I am basically using the nehe example for the freetype se开发者_JAVA技巧tup/print methods. http://nehe.gamedev.net/tutorial/freetype_fonts_in_opengl/24001/
So say for example, i wanted some text to slowly erode from the bottom up,pixel by pixel, any ideas?
Although i have not fully examined their code, would it be best to alter the TexCoord/Vertex data?
glBegin(GL_QUADS);
glTexCoord2d(0,0); glVertex2f(0,bitmap.rows);
glTexCoord2d(0,y); glVertex2f(0,0);
glTexCoord2d(x,y); glVertex2f(bitmap.width,0);
glTexCoord2d(x,0); glVertex2f(bitmap.width,bitmap.rows);
glEnd();
glPopMatrix();
glTranslatef(face->glyph->advance.x >> 6 ,0,0);
Any advise at all would be helpful
You could use clip planes for that. They will determine the area where the text will be rendered. You can move the clip planes each frame so that clipped/visible area is changes and your text will slowly erode from the bottom up, pixel by pixel
.
This code clips the text from right and left:
procedure TRenderUI.SetupClipX(X1,X2:smallint);
var cp:array[0..3]of real; //Function uses 8byte floats //ClipPlane X+Y+Z=-D
begin
glEnable(GL_CLIP_PLANE0);
glEnable(GL_CLIP_PLANE1);
FillChar(cp, SizeOf(cp), 0);
cp[0] := 1; cp[3] := -X1; //Upper edge
glClipPlane(GL_CLIP_PLANE0, @cp);
cp[0] := -1; cp[3] := X2; //Lower edge
glClipPlane(GL_CLIP_PLANE1, @cp);
end;
//Release all clipping planes
procedure TRenderUI.ReleaseClip;
begin
glDisable(GL_CLIP_PLANE0);
glDisable(GL_CLIP_PLANE1);
end;
You can use up to 4 clipping planes simultaneously.
精彩评论