views:

60

answers:

2

I have a 2D list of vectors (say 20x20 / 400 points) and I am drawing these points on a screen like so:

for row in grid:
    for point in row:
        pygame.draw.circle(window, white, (particle.x, particle.y), 2, 0)

pygame.display.flip() #redraw the screen   

This works perfectly, however it's much slower then I expected.

I want to rewrite this in C++ and hopefully learn some stuff (I am doing a unit on C++ atm, so it'll help) on the way. What's the easiest way to approach this? I have looked at Direct X, and have so far followed a bunch of tutorials and have drawn some rudimentary triangles. However I can't find a simple (draw point).

+1  A: 

DirectX doesn't have functions for drawing just one point. It operates on vertex and index buffers only. If you want simpler way to make just one point, you'll need to write a wrapper.
For drawing lists of points you'll need to use DrawPrimitive(D3DPT_POINTLIST, ...). however, there will be no easy way to just plot a point. You'll have to prepare buffer, lock it, fill with data, then draw the buffer. Or you could use dynamic vertex buffers - to optimize performance. There is a DrawPrimitiveUP call that is supposed to be able to render primitives stored in system memory (instead of using buffers), but as far as I know, it doesn't work (may silently discard primitives) with pure devices, so you'll have to use software vertex processing.

In OpenGL you have glVertex2f and glVertex3f. Your call would look like this (there might be a typo or syntax error - I didn't compiler/run it) :

glBegin(GL_POINTS);
glColor3f(1.0, 1.0, 1.0);//white
for (int y = 0; y < height; y++)
    for (int x = 0; x < width; x++)
        glVertex2f(points[y][x].x, points[y][x].y);//plot point
glEnd();

OpenGL is MUCH easier for playing around and experimenting than DirectX. I'd recommend to take a look at SDL, and use it in conjuction with OpenGL. Or you could use GLUT instead of SDL.

Or you could try using Qt 4. It has a very good 2D rendering routines.

SigTerm
+1  A: 

When I first dabbled with game/graphics programming I became fond of Allegro. It's got a huge range of features and a pretty easy learning curve.

Cogwheel - Matthew Orlando