SFML Text appears gigantic in small View - c++

I've encountered a problem drawing SFML Text. In my application, I use views as a sort of coordinate system for my application. Thus, a typical view would be 10 x 10 or 20 x 20. All my normal drawing functions work fine, when drawing primitives and lines, etc., and the relevant code doesn't have to know about the coordinate system.
However, when I tried to draw text to the screen, I found that it appeared gigantic. When I reduced the font size drastically, it appeared extremely blurry and pixellated, as if it were trying to render to GIANT pixels that are 1x1 in my view.
Is there a way to draw text with a standard font size, in a way that it won't be affected by the view? Ideally, my text would width/size-wise on any view? How can I accomplish this?
Thanks for any input!
(P.S., I'm using SFML 2.0, for reference)

You can set another view (i.e. apply OpenGL transformation) and render text after it. Here is an example from sfml tutorial:
sf::View View(sf::FloatRect(600, 700, 1400, 1300));
App.SetView(View);
// Draw the game...
App.SetView(App.GetDefaultView());
// Draw the interface...

Related

Draw OpenGL to an offscreen bitmap

I've inherited a project which renders a 3D scene directly to the window using OpenGL. The code works fine, but we're now drawing an icon onto the 3D view to "Exit 3D view mode". This also works fine, but results in a lot of flickering as the view is rapidly rotated.
I'd like to be able to draw to an off-screen bitmap (ie. without a HWND), then draw my icon to the bitmap, then finally StretchBlt the bitmap to the window using double-buffering. We do this in other contexts (such as zooming into an image which does not need OpenGL) and it works great. My problem is that I am an OpenGL novice and all attempts at starting with the DC of the off-screen bitmap and creating a HWND from this DC fail, usually because of selecting a pixel format for the DC.
There are a few questions asking similar things here on StackOverflow (eg. this question without an accepted answer. Is this possible ? If so is there a relatively straightforward tutorial describing the procedure? If the process is extremely complex requiring detailed OpenGL knowledge, then I may just have to leave it and live with the flickering because it is a rarely used mode in our software.
Just draw the Icon using OpenGL using a textured quad.
All this draw to a bitmap copy to DC StretchBlt involves several roundtrips from and to graphics memory (wastes bandwidth) and StretchBlt will likely not be GPU accelerated. All in all what you want to do is inefficient and may even reduce quality.
I presume you have the icon stored in your executable as a resource. The most simple way to go about it is to create a memory DC (CreateCompatibleDC) with a DIBSECTION (CreateDIBSection), draw the icon to that and load the DIBSECTION data into a OpenGL texture. Then to draw the icon use glViewport to select the destination rectangle in window coordinates, use an identity transform to draw a rectangle covering the whole viewport (position values (-1,1)→(1,1), texture coordinate values (0,0)→(1,1) gives you the right outcome).
Important side fix: In case your program does silly things like setting viewport and the fixed function pipeline GL_PROJECTION matrix in a window resize handler you should clean up that anti pattern and move this to where it belongs: In the drawing code.

Is it possible to draw on an SFML window regardless of views?

I have a game I'm currently working on, and it uses multiple views (for a minimap for example).
Thing is, I would like to have a fading effect added at some point, so I thought I'd create a black image that is the size of the screen and change its alpha value with a timer. That part is not a problem.
What happens right now is the main area (ie window default view) is fading (because the opacity of the image is increasing), but the minimap (minimap view) is unaffected. This is normal behaviour for views, but is there a way to draw an image to the whole window, regardless of the views ?
Thanks in advance
To clarify, you have the default view where you'll draw the main game, then you'll have the minimap view where you would draw the minimap. At some point in the game you want the whole screen to fade to black. It sounds like you've been trying to draw a black image on the default view (changing the alpha) to make this effect work.
So, you need a third view that you draw your black image on to get this fading effect.

overlay support in windows/opengl environment

I have to display an image and text overlay, when text overlay contains many strings, but only one changes from frame to frame. I want to avoid redraw of the entire overlay and only update what has changed.
I tried wglCreateLayerContext but my GPU seems to not support it (PIXELFORMATDESCRIPTOR bReserved is 0).
What is the most efficient way to redraw only part of text overlay?
Redrawing the whole framebuffer is the canonical way in OpenGL. You can use Framebuffer Objects (FBO) to create several off-screen drawing surfaces, to which you render the individual layers. Then you composit the layers into a composite image presented on screen.
but only one changes from frame to frame. I want to avoid redraw of the entire overlay
Why? Figuring out what parts need redraw, masking them, do only a partial clear, updating it, etc. takes more time and effort than to simply redraw the whole text overlay.

Color Picker / Choser for an OpenGL Application

I am building an OpenGL application. I read through the GLUI tutorial on Code Project to create windows form controls on an OpenGL Application. But my requirement is to develop a color choser/picker, like an RGB chart or RGB cube to select a color. The tutorial on Code project shows the list of colors as a drop down box. However that wont really help me, as I require it to be present as a windows color picker. I know that color picker as a dialog box is a part of the windows application. Can anyone suggest me a way to use it with my OpenGL Application?
You can try fox-toolkit. It is a C++ based Toolkit for developing Graphical User Interfaces. It provides Color Picker and OpenGL widgets for 3D graphical manipulations.
On windows, you can call directly ChooseColor() from the windows API. It will open the native color color chooser.If you need a cross-platform solution, tiny file dialogs on sourceforge also has a color picker and no main loop.
You could render a Quad/Triangle/Cirle with different color on each vertex and activate smooth shading for interpolation between these points. Then just read back the color value from OpenGL at the mouse position.
edit: or like that where you calculate the color on the mouse position by yourself (reading values slows down OpenGL a lot!): http://sharathpatali.wordpress.com/2009/07/07/a-color-picker-for-pymt/
I did this with simple gradient image which i kept in memory. Then i just tracked my mouse position on the image, and simply read the data from the image (that was kept in RAM) and get the 32bit RGBA color value for it. This is easier than reading the pixels from screen (also faster and more reliable).
This also allows a lot more flexible way of presenting the palette, only your imagination is the limit on the looks of your palette. Note: you must use 32bit colors on the image, because if you want smooth edges, you simply just fade the alpha but keep the colors the same, so the colors wont get distorted at edges. Don't forget to enable blending when rendering the image.

New to OpenGL, working on "paint" program

I'm taking a computer graphics course this semester at college and our first assignment is to build a program that works much like Microsoft paint. We need to set options for drawing with shapes of different colors, sizes, and transparency parameters.
I'm having trouble finding information on how to program the ability to draw with a given shape on mouse drag. I'm not asking for the solution in code, but guidance on where to study functions that might accomplish this.
I'm completely new to OpenGL (but not C++) & I own "Computer Graphics with OpenGL" 4th ed. by Hearn & Baker. None of the topics suggest this capability.
What's probably asked from you is creating a single bufferd window, or switching to draw on the front buffer, and draw some shape at the mouse pointers location, when a button is pressed (and dragged), without clearing the frontbuffer inbetween. For added robustness draw to a Frame Buffer Object attached texture, so that dragging some window will not coorupt the user's drawing.
Keywords: Set Viewport to Window size. Ortho projection to window bounds, do not use glClear (except for resetting the picture).