• entries
743
1924
• views
578736

# TextureFonts

79 views

To prove some progress, and to make Diablo_tk happy, here is the most complex polygon fish yet (this time with textures):

As well as free and snap to grid, the editor also now supports "snap to nearest vertex" mode. The little red circle is the cursor, which follows the mouse, but in the new mode it snaps to the nearest vertex if it is within the distance of the little green circles. Works quite well.

Just added a new TextureFontStream class to my graphics library for the polygon map editor.

It's a bit crap, but makes it a bit easier to send loads of variables to the screen as text:

void Engine::RenderSidePanel(){	float Width=150;	float FHt=Font.Height();	Graphics.SetTransform(0,0,0);	Graphics.RenderSolidQuad(1024-Width,0,Width,768,Argb(128,0,0,0));	TextureFontStream Fs(Font);	Fs(1024-Width+4,0) << CursorPos.X << "," << CursorPos.Y;	Fs(1024-Width+4,FHt*2) << "GridSize: " << GridSize;	Fs(1024-Width+4,FHt*3) << "LockMode: " << LockModeString();		Fs(1024-Width+4,FHt*5) << "Shapes: " << Shapes.Size();		Font.Render(Graphics);}

Doesn't really work properly, in that if you tagged two TextureFontStreams to the same Font, it would all go horribly wrong. This is due to the Font maintaining an internal vertex buffer that normally calling TextureFont::Add() writes letters to as textured quads.

So the TextureFontStream is really just a little interface to sit on top of the TextureFont.

I am tempted to move the VB into the TextureFontStream class to solve the problem above, but then you would have to use a TextureFontStream even if you didn't want to. Will think about for a bit.

But I think it is quite cool. Apart from the std::string overload, the others are just like a:

template TextureFontStream::operator<<(const T &t){    std::ostringstream Os; Os << t; return (*this) << Os.str();}

so the TextureFontStream can now cope with anything that std::ostream can cope with.

[LATER]

Decided I don't use templates enough. I need a system for passing parameters to commands that are queued for later processing in the Update() loop and came up with the following:

#include #include #include class param{private:    std::string v;public:    template param(const T &t){ std::ostringstream os; os << t; v=os.str(); }    template T convert() const { std::istringstream is(v); T t=T(); is >> t; return t; }};int main(){    param a("hello");    param b(23);    std::string s=a.convert();    int i=b.convert();    std::cout << s << "\n";    std::cout << i << "\n";}

I guess this is a bit like this boost::any I keep hearing about. Obviously needs to be extended to validate its paramter, but I think that will be quite a good solution.

This would have been nice while working on my 4e5 entry. As it was, I had to use a CAD program to make my levels, which was less than efficient.

Lookin' good! :D

Quote:
 Original post by Drilian This would have been nice while working on my 4e5 entry. As it was, I had to use a CAD program to make my levels, which was less than efficient. Lookin' good! :D

Oh yeah - I forgot you kind of wrote the book round here on 2D polygon graphics. Mop of Destiny has probably been a subconcious inspiration for my current project.

Looks awesome!

How exactly are you generating texture coordinates for your polygons?

Quote:
 To prove some progress, and to make Diablo_tk happy

Thankyou - I was about to start a project with giant space fish, but now I've seen this my giant space fish my appetite has - for now - been quenched.

Quote:
 How exactly are you generating texture coordinates for your polygons?

My guess is he's using real world vertex positions to calculate UVs so
uv.x = vert.x / resolution.width;
uv.y = vert.y / resolution.height;


Quote:
 Original post by Sir Sapo Looks awesome! How exactly are you generating texture coordinates for your polygons?

Yeah, as diablo_tk says below. Texture co-ord is just world co-ord divided by the texture width/height. With wrap mode, this all seams, er, seamlessly.

HopeDagger basically gave me this method in my last journal post. Have a look at the comments on the last entry for details.

HopeDagger also said something about then further scaling the co-ords down but I couldn't get that to work.

## Create an account

Register a new account