I am writing a small program in OpenGL on my Mac. I have a question considering subwindows. I have created two subwindows in my main window. Everything works fine to that point. I can draw in both of them. But i want something different. I want to draw (with my mouse) in one window and simultanously get a drawing in the other window.
Now its not even possible to get the same drawing in both windows. If i want to see something i always have to draw in that one particular window.
Do you have some ideas maybe how to do this. Or do you have an example perhaps. Unfortunately i couldnt find much information on the topic "subwindows".
OpenGL is not a scene graph. All what it gives you are the computer equivalents of pencils and crayons. So you draw something to a framebuffer, it will show up in only that one framebuffer.
You want to draw a scene from multiple vantage points? Then you have to draw that scene multiple times from those choosen vantage points to the designated viewports.
Related
Using OPENGL , I am making a simple animation where a small triangle will move through the path that I have created with mouse (glutMotionFunc).
So the problem is how can I animate a small triangle without redrawing the whole path using glutSwapBuffers();
And also ,how can I rotate that triangle only.
I don't want to use overlay as switching between these 2 layers takes much time.
If redrawing the whole path is really too expensive, you can do your rendering to an off-screen framebuffer. The mechanism to do this with OpenGL is called Frame Buffer Object (FBO)
Explaining how to use FBOs in detail is beyond the scope of an answer here, but you should be able to find tutorials. You will be using functions like:
glGenFramebuffers()
glBindFramebuffer()
glFramebufferRenderbuffer() or glFramebufferTexture()
This way, you can draw just the additional triangle to your FBO whenever a new triangle is added. To show your rendering on screen, you can copy the current content of the FBO to the primary framebuffer using glBlitFramebuffer().
You cant! Because it just does not makes sense!
The way computer screen work is the same as in films: fps! Frames per second. There is no thing as "animation" in screens, it is just a fast series of static images, but as our eyes cannot see things moving fast, it looks like it is moving.
This means that every time something changes in the thing you want to draw, you need to create a new "static image" of that stage, and that is done with all the glVertex and so pieces of code. Once you finish drawing you want to put it on the screen, so you swap your buffer.
I am wondering what kind of methods are commonly used when we do zoom in/out.
In my current project, I have to display millions of 2D rectangles on the screen, and I am using a fixed viewport and changing glortho2D variables when I have to zoom in/out.
I am wondering if this is a good way of doing it and what other solution can I use.
I also have another question which I think it is related to
how should I do zoom in/out.
As I said, I am currenly using a fixed viewport and changing glortho2D variables in my code, and I assumed that opengl will be able to figure out which rectangles are out of the screen and not render them. However, it seems like opengl is redrawing all the rectangles again and again. The rendering time of viewing millions of rectangles (zoom out) is equal to vewing hundreds of rectangles (zoom into a particular area), which is opposite of what I expected. I am wondering if it is related to the zooming methods I used or am I missing something important.
ie . I am using VBO while rendering the rectangles.
and I assumed that opengl will be able to figure out which rectangles are out of the screen
You assumed wrong
and not render them.
OpenGL is a rather dumb drawing API. There's no such thing like a scene in OpenGL. All it does is coloring pixels on the framebuffer one point, line or triangle at a time. When geometry lies outside the viewport it still has to be processed up to the point it gets clipped (and then discarded).
I'm making a 2D game that uses directx. Currently, I have a background texture (with more to come) that I draw to the screen. However, I only want a portion of the texture drawn to the screen. I know that I could use a rectangle with the draw function, but I need a greater degree of control. Is there a way to draw several triangles (using custom vertices) to the screen from my drawing? I've looked around the internet and this site, but I just can't seem to find what I want. I can give more information/code if needed. Thank you!
I am developing a paint-like application using C++ and Open GL. But every time i draw objects like circle, lines etc they don't ** stay ** on the page. By this I mean that every new object I draw is getting placed on a blank page. How do I get my drawn objects to persist?
OpenGL has no geometry persistency. Basically it's pencils, brushes and paint, with which you draw on a canvas called the "framebuffer". So after you drawn something and clear the framebuffer, it will not reappear in some magic way.
There are two solutions:
you keep a list of all drawing operations and at each redraw you repaint everything from that list.
After drawing something copy the image in the framebuffer to a texture and instead of glClear you fill the background with that texture.
Both techniques can be combined.
Just don't clear the framebuffer and anything you draw will stay on the screen. This is the same method I use to allow users to draw on my OpenGL models. This is only good for marking up an image, since by using this method you can't erase what you've drawn, unless your method of erasing is to draw using your background color.
Just what it says: I have some code that's drawing GLUT cubes, but they're all grey. How do I make them different colors?
Everything I've tried so far has failed. I think my problem is that I'm trying to use OpenGL functions to change their colors, but GLUT is maintaining it's own internal color or material data and I don't know how to make it change that data.
This is just filler graphics for a test-client for an online game, so they don't have to look good, I just need to be able to tell things apart. I know GLUT isn't considered great, so if anyone wants to post an example of drawing a cube with plain OpenGL instead of glutCube I'm all ears. I don't really care how I get the cubes on the screen, and it's not a part of the code I want to spend a lot of time on. I have a partner who's doing the real graphics; I just need to get something showing so that I can visualize what my code is doing.
The language I'm using OpenGL/GLUT from is called Io, but the API it exposes should be the same as if I were calling it from C.
It turns out that if I just do:
glEnable(GL_COLOR_MATERIAL)
then it makes the material track whatever color I set with glColor, even when lighting is enabled.
Just set the color beforehand with glColor(). If you're using lighting (i.e. GL_LIGHTING is enabled), though, then you'll instead have to use glMaterial() to set the cube's color.