0

I'm working on an assignment and I need to draw using only GL_POINTS. I realize this is an expensive approach but it's for the homework, so no GL_TRIANGLES / GL_POLYGON / GL_LINES etc.

First, I'm trying to understand the concept of using only points. Say I want to draw a square that's 100 x 100 pixels. Would I need four for-loops drawing 100 pixels each in straight lines to create the square? What if I want to fill the square with color?

I understand drawing a square using GL_POLYGON as that's fairly straight forward. We're using the GLUT library just to draw shapes with points.

chris thomas
  • 428
  • 5
  • 15
  • Probably should be moved to computergraphics.stackexchange. – geometrian Sep 23 '15 at 16:44
  • Thanks, I'll post there. – chris thomas Sep 23 '15 at 16:45
  • 1
    I was more flagging this question for a moderator to move it. If you'd like to do it yourself, delete this question here so you aren't cross-posting. – geometrian Sep 23 '15 at 16:46
  • That is a really weird assignment; I can't think of a reason to compose geometry using points rather than triangles. Nevertheless, you can modify the size of points using [`glPointSize`](https://www.opengl.org/sdk/docs/man2/xhtml/glPointSize.xml). – Colonel Thirty Two Sep 23 '15 at 17:48
  • just simply compute points on surface of your sphere and pass them as points to GL see [sphere triangulation](http://stackoverflow.com/a/29139125/2521214) and [Spherical coordinate system](https://en.wikipedia.org/wiki/Spherical_coordinate_system) to Cartesian coordinates equation (then just do 2 nested `for` loops for the `long,lat` angles and compute `x,y,z` that are passed to OpenGL). If you are bound to GLUT then I cant help I do not use it ... – Spektre Sep 24 '15 at 06:27
  • @ColonelThirtyTwo I can - it's an equivalent of writing your own software renderer. – Bartek Banachewicz Sep 24 '15 at 12:49
  • 1
    @BartekBanachewicz Then why would you use OpenGL? At least upload your rendered image to a texture/Pixel Buffer Object instead of drawing thousands of points. – Colonel Thirty Two Sep 24 '15 at 17:36

2 Answers2

0

I think the assignment basically forces you to write your own renderer. So, for example, you'd need to implement Bresenham algorithm for the lines and scanline rasterization for the triangles. Once you have that, you can triangulate every shape and just rasterize as multiple triangles.

Bartek Banachewicz
  • 38,596
  • 7
  • 91
  • 135
-1

To draw a square that is 100x100 pixels wide, you would only need to use in your application:

glEnable(GL_PROGRAM_POINT_SIZE);

Then in your vertex shader for the only vertex that you need (the center of the square):

gl_PointSize = pixel_size;

In your case:

gl_PointSize = 100;
Luis
  • 678
  • 8
  • 14