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'.
Related
I'm trying to capture the pixels of an OpenGL application (specifically, MEmu) and later convert it to an OpenCV Mat. I used the hwnd2mat() function from this post as a reference but ran into some problems.
Only the window frame is captured, as seen here:
Further investigation led me to believe that the problem is that StretchBlt (or BitBlt) can't capture the OpenGL pixels.
I tried to use glReadPixels (and convert to Mat using this), but it is not reading any pixels. The wglCreateContext returns NULL, probably because my application does not own the DC of MEmu. Therefore, wglMakeCurrent does nothing and the pixels are not read.
I was able to create a workaround modified version of hwnd2mat that gets the WindowRect of MEmu's hwnd but later uses GetDC(NULL) to capture only the portion of the screen where MEmu is located. This works but any windows that get on top of MEmu get captured aswell.
I can work with this, sure, but was wondering if there is a way to use glReadPixels on a window that I don't own or a way to ensure that hwnd2mat works on the contents of the window that is using OpenGL.
I'm trying to create an game / application using GLFW and OpenGL 3.3. I'd like to be able to detect collision with the sides of the window, but it seems that the drawable area of the window differs from the size of the window set using glfwCreateWindow().
So my question is, how do I get that drawable area, ie. the size of the window minus the border? I'd rather not have to use the WinAPI so as to make it more cross-platform, and glfwGetWindowFrameSize() is in GLFW 3.1, which isn't completed yet.
Edit: My question makes it seem like I need to use GLFW do accomplish this, which isn't true. I just wanted to note that I'm using GLFW as a window / input handler.
You want glfwGetFramebufferSize.
glfwGetVideoMode returns the video mode of the specified monitor, not the size of your window. For fullscreen windows, they happen to be the same, but for other windows they are likely to be very different.
From the looks of it, you do not need to know the size of the window, I'm assuming in pixels? If you want to do collision detection with the border of the window, you just need to detect the the NDC of your vertex, and once it reaches x or y = (-1, 1) then you would've had a collision. Nonetheless, if you want to get the size in pixels of your OpenGL context then use glfwGetVideoMode().
Just like to add a bit question similar to this link. Is there anyway I could do to draw outside the client window using OpenGL without any native commands to be used? or is this beyond OpenGL previleges?
Other ways I could think of is to draw a sub window and remove the built in borders and button on it, then draw what I wanted there?
I didn't understand the functionality of glutSwapBuffer properly. In my code if I don't use the glutSwapBuffer than no background color came in window and it remain transparent, capturing whatever is there in its background. I think that the background color is actually assigned by glClearColor, than how come without using glutSwapBuffer I didn't get any background color.
This question comes up over and over, I think what you are describing is actually what happens when you draw exclusively into the front-buffer in a compositing window manager.
Without swapping buffers, it does not draw your window correctly, so the window appears transparent. Double buffering is required for compositing window managers and it seems it is also required for many hybrid integrated/discrete GPU implementations (e.g. nVIDIA Optimus). In short, there is no real reason to use single-buffered rendering on a desktop platform these days.
To be certain, does your situation resemble this? This screenshot shows what happens when a window that only uses single-buffering is moved in a compositing window manager.
If so, a more thorough explanation can be found here.
opengl usually is configured to use double buffering.
You first draw to one buffer... then Swap it with the second and present it on the screen.
Without calling glutSwapBuffer you will not see anything and it is correct behavior.
about double (and more) buffering in opengl
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.