Jump to content

DrawText()


MasteR
 Share

Recommended Posts

I'm after a little help.

 

I'm after a solution which will let DrawText() render text that occupies the same screen space regardless of resolution. I'd much prefer to sort this out without having to write my own OpenGL DrawText() function. 3rd party libraries are also an option as I can simply write my own if I have to.

 

Unlike DrawImage(), DrawText() does not have a width and height which can be scaled, glscalef scales properly but I'm at a loss as how to retain the texts correct screen position using this technique.

 

Thoughts/solutions?

AMD Athlon 64 X2 Dual Core 6000+ (3.0 GHz)

4 GB DDR2 RAM

2 x NVIDIA GeForce 9500 GT 512 MB (SLI 1.0 GB)

Windows XP Pro

Link to comment
Share on other sites

Well, the simplest way is to use your own co-ordinate system based on percentages.

 

Assign x_scale equal to ScreenWidth() / 100 and y_scale equal to ScreenHeight() / 100

call your DrawImage() and DrawText() functions which pass the co-ordinates as

 

x * x_scale

y * y_scale

 

Then layout your images and text using your percentage co-ordinate system.

So regardless of resolution your own co-ordinate system need never change.

 

If you need to scale the font then you'll need to make your own bitmap font functions.

But that's fun to do.

 

 

There are other ways you can do this but they are six of one and half a dozen of the other.

I use variations of this for various kinds of display that work across resolutions in my project.

 

Mostly I use OpenGL and change the co-ordinate system to have the origin in the centre

of the screen, everything is expressed as an offset from that as a percentage.

6600 2.4G / GTX 460 280.26 / 4GB Windows 7

Author: GROME Terrain Modeling for Unity, UDK, Ogre3D from PackT

Tricubic Studios Ltd. ~ Combat Helo

Link to comment
Share on other sites

In less words, if your draw functions looks like this : drawText( Text, xPos, yPos ..etc ), then drawText( "testtext", ScreenWidth * 0.5, ScreenHeight * 0.5, ..etc ) would draw "testtext" at the center of the screen ( where ScreenWidth/Height is the width, height of the application ).

Link to comment
Share on other sites

Worked out a solution,

 

Following Flexman's train of thought (a solution I was already following for image rendering). Create a custom buffer with width = GraphicsWidth()/scale and height = GraphicsHeight/scale.

 

Do all your drawing to this custom buffer then copy to the back buffer.

AMD Athlon 64 X2 Dual Core 6000+ (3.0 GHz)

4 GB DDR2 RAM

2 x NVIDIA GeForce 9500 GT 512 MB (SLI 1.0 GB)

Windows XP Pro

Link to comment
Share on other sites

  • 2 weeks later...

Just saw this, I use my own open gl functions for all 2d objects le 2d functions are limited and what you will find is that as soon as you start using them you need to do things they don't support. Save yourself a lot frustration and build up a suite of your own 2d open gl functions. Once you understand the basic princiles it's actually very simple and offers many options for improvement.

If it's not Tactical realism then you are just playing..

Link to comment
Share on other sites

Just saw this, I use my own open gl functions for all 2d objects le 2d functions are limited and what you will find is that as soon as you start using them you need to do things they don't support. Save yourself a lot frustration and build up a suite of your own 2d open gl functions. Once you understand the basic princiles it's actually very simple and offers many options for improvement.

If it's not Tactical realism then you are just playing..

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...