English 中文(简体)
Are there any easy ways to generate OpenGL code for drawing shapes from a GUI?
原标题:

I have enjoyed learning to use OpenGL under the context of games programming, and I have experimented with creating small shapes. I m wondering if there are any resources or apps that will generate code similar to the following with a simple paint-like interface.

glColor3f(1.0, 0.0, 0.0);
glBegin(GL_LINE_STRIP);
glVertex2f(1, 0);
glVertex2f(2, 3);
glVertex2f(4, 5);
glEnd();

I m having trouble thinking of the correct dimensions to generate shapes and coming up with the correct co-ordinates.

To clarify, I m not looking for a program I can just freely draw stuff in and expect it to create good code to use. Just more of a visual way of representing and modifying the sets of coordinates that you need.

I solved this to a degree by drawing a shape in paint and measuring the distances between the pixels relative to a single point, but it s not that elegant.

最佳回答

It sounds like you are looking for a way to import 2d geometry into your application. The best approach in my opinion would be to develop a content pipeline. It goes something like this:

  1. You would create your content in a 3d modeling program like Google s Sketchup. In your case you would draw 2d shapes using polygons.

  2. You need a conversion tool to get the data out of the original format and into a format that your target application can understand. One way to get polygon and vertex data out of Sketchup is to export to Collada and have your tool read and process it. (The simplest format would be a list of triangles or lines.)

  3. Write a geometry loader in your code that reads the data created by your conversion tool. You need to write opengl code that uses vertex arrays to display the geometry.

问题回答

The coordinates you ll use just depend on how you define your viewport and the resolution you re operating in. In fact, you might think about collecting the coordinates of the mouse clicks in whatever arbitrary coordinate system you want and then mapping those coordinates to opengl coordinates.

What kind of library are you expecting?

something like drawSquare(dx,dy);? drawCircle(radius);?

drawPoly(x1,y1,x2,y2....);?

Isn t that exactly the same as glVertex but with a different name? Where is the abstraction?

I made one of these... it would take a bitmap image, and generate geometry from it. try looking up triangulation.

the first step is generating the edge of the shape, converting it from pixels to vertices and edges, find all the edge pixels and put a vertex at each one, then based on either the distance between vertices, or (better) the difference in gradient between edges to cull out vertices and reduce the poly count of the mesh.

if your shape drawing program works with vector graphics rather than pixels, i.e. plotting points and having lines drawn between them, then you can skip that first step and you just need to do triangulation.

the second step, once you have your edges and vertices is triangulation, in order to generate triangles, ear clipping is a simple method for instance.

as for the coordinates to use? that’s entirely up to you as others have said, to keep it simple, Id just work in pixel coordinates.

you can then scale and translate as needed to transform the shape for use.





相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签