tags:

views:

387

answers:

4

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.

A: 

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.

dicroce
That's a good idea, but you would think there are some mature applications out there to do the job for you.
Sam152
A: 

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?

Chris H
A: 

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.

matt
A: 

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.

don