gtk+ Image draw over image in c++ - c++

I would like to draw a simple (red) line over an image with gtkmm (in c++).
I have the image : Gtk::Image *image which is displayed in my window.
But I would like the line to change of position (I mean : draw another line) when a function is called. I need your help because I didn't find how to draw over an existing image...
Thank you for your help !
EDIT : A solution for me would be to overlay the image by an image with alpha channel... but I don't know how to to that :-/

You should not actually draw in the image, instead you draw in the window.
First put the image in the window (blitting or some other means) then draw the line.
See e.g. this link on how to draw straight lines.

Connect to the "expose-event" (GTK2) or "draw" (GTK3) signal of the GtkImage. I think you should use the C++ equivalent of g_signal_connect_after (which in in GObject), and not the g_signal_connect one, so you get a chance of drawing after the image has been drawn, so your drawing is on top of it. To draw you need to use cairomm, and Joachim already gave you a link to a cairomm tutorial.

Related

SDL function to clear only part of the screen?

I am using C++ and SDL 2. Is there any function in SDL or any available algorithm to clear only a part of the screen?
I tried using SDL_RenderSetViewPort() in the following way but it didn't work:
SDL_RenderSetViewPort(renderer,&rect);
SDL_RenderClear(renderer);
I thought that the specific texture present in the given rectangle part would be cleared but it didn't.
SDL_SetRenderDrawColor() with the clear color then SDL_RenderFillRect() with the desired region to 'clear'.

Drawing text with shadow on pixmap with QPainter

I am working on a project in C++ with Qt, and I am trying to find a way to apply a text shadow when drawing text on a QPixmap using QPainter.
I understand that QGraphicsDropShadowEffect is a thing, and I am using in other parts of my project, but I can't for the life of me find a way to apply a QGraphicsEffect when drawing with QPainter on a pixmap. Drawing the same text multiple times with different offsets and opacities doesn't quite cut it.
Are there any ways to do this?
If not, how could I go about making a function that does it, given a QGraphicsEffect to get the radius and color from?
Thanks in advance!
I don't think it is directly possible to "draw text with shadow", it is only possible to apply a shadow to something already drawn that would take in an element and use say its alpha channel to calculate the shadow.
You should use composition, either of the final products or during drawing. It should work if you use it on a text element. The other option would be to draw your text in black, apply Gaussian blur and then again draw the text on top of it with the desired offset.
Thanks for your answer ddriver, it made me search with some new keywords, which lead me to find a suiting solution for my project.
What I figured out is that you can simply create a QLabel with the text and effects you want (QGraphicsDropShadowEffect, in my case), and render it into a QPixmap using QWidget::grab(). You can then draw this new pixmap with QPainter as you would any other image, by converting your pixmap to a QImage and using QPainter's drawImage().

Drawing a line with open GL

I am a newbie with OpenGL. I need to draw a line with it. I browsed the web and found this code:
glBegin(GL_LINES);
glVertex2f(.25,0.25);
glVertex2f(.75,.75);
glEnd();
However, I don't see any line. The consoler appears only for some milliseconds. I need a program that will draw a line and at least visible for some moments.
Thanks in advance.
Bevor you can draw something, you first need some canvas to draw upon. That's be a window with a pixel framebuffer; without doing extra effort you don't have such.
So first step is to create a window which you can draw into, that gives you the canvas.
Next you need the actual pens to draw with. That would be a OpenGL context you have to create and connect with the window.
Only after you did that you can actually ask OpenGL to draw some line. If you just call the drawing commands, there's nothing going to happen, because you neither have the canvas to draw to, nor the pen to draw with.

SFML Text appears gigantic in small View

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...

Colored border of the transparent color key around text written on the transparent window

I created a Transparent Layered window with a color key that I use to make the window transparent.
So far it works all fine.
Writing text on it - using GDI+ - works, too...
The problem I encounter is, that the text has a thin border of the colorkey-color around the letters...
What I do in the WM_PAINT is:
1. Clear the drawing area Graphics::Clear(ColorKey);
2. Draw the text on it.
Screenshot of what i mean: http://imageshack.us/photo/my-images/709/cutp.jpg/
Anyone knows about how to avoid this?
Try calling Graphics::SetTextRenderingHint(TextRenderingHintSingleBitPerPixelGridFit).