MasteR Posted October 12, 2010 Share Posted October 12, 2010 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? Quote 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 More sharing options...
Flexman Posted October 12, 2010 Share Posted October 12, 2010 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. Quote 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 More sharing options...
Ywa Posted October 12, 2010 Share Posted October 12, 2010 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 ). Quote Link to comment Share on other sites More sharing options...
AggrorJorn Posted October 12, 2010 Share Posted October 12, 2010 Like said above, the position isn't really the problem. Unfortunately you can not change the size of letters. Quote Link to comment Share on other sites More sharing options...
MasteR Posted October 13, 2010 Author Share Posted October 13, 2010 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. Quote 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 More sharing options...
Chiblue Posted October 27, 2010 Share Posted October 27, 2010 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. Quote If it's not Tactical realism then you are just playing.. Link to comment Share on other sites More sharing options...
Chiblue Posted October 27, 2010 Share Posted October 27, 2010 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. Quote If it's not Tactical realism then you are just playing.. Link to comment Share on other sites More sharing options...
ESP Posted October 27, 2010 Share Posted October 27, 2010 Any chance of sharing the code? Any chance of sharing the code? Robin Robin Quote Programmer , Intel Quad core, NVIDIA GeForce GT 220, Windows 7 Pro, Galaxy Tab 2 ( 7" and 10"), LE2,LE3,3DWS Link to comment Share on other sites More sharing options...
MasteR Posted October 27, 2010 Author Share Posted October 27, 2010 Any chance of sharing the code? Robin The Buffer approach? Quote 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 More sharing options...
Recommended Posts
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.