woolfik

08-27-2015, 06:44 AM

Hello

I'm new on this forum so if this subject was here before I need to say sorry.

I'm new in OpenGL and still lerning this technology. I have an array of array of points. Each point has it coordinates (X,Y,Z) and color. I writing my application in delphi so sample code will be in delphi (but You can send codes in other languages). I have such code:

glBegin(GL_LINE_STRIP)

for I := 0 to High(Stars) - 1 do //stars is my array of array of points

begin

for j := 0 to High(stars[i]) - 1 do

begin

glColor3ub(stars[i,j].R,stars[i,j].g, stars[i,j].b);

glVertex3i(stars[i,j].x,stars[i,j].y, stars[i,j].distance);

end;

glEnd;

end;

And when zoom is not to big it show me what I need (some kind of map) but when zoom is big it show me only color points on white scene. Is there any tool in OpenGL that will connect points with colors? I would like to have area between points connected by color of each point?

Carmine

08-27-2015, 05:07 PM

If I understand your question correctly, you're going to have to use glBegin(GL_TRIANGLES), not glBegin(GL_LINE_STRIP), to get the effect you want. OpenGL will interpolate color across the inside of a triangle based on the vertex colors. This means you are going to have to 'triangulate' your point set which is not a trivial process. See 'Delauney Triangulation' for example.

See this link: nehe Tutorial - 'Adding Color' (http://nehe.gamedev.net/tutorial/lessons_01__05/22004/)

Good luck.

woolfik

08-28-2015, 12:17 AM

It is not as that simple. There are 4 screenshots in attatch. First is with glBegin(GL_POINTS) second is with glBegin(GL_POINTS) but in big zoom. When I change it on triangles that as You told me to it is worst then in GL_LINES or GL_LINE_STRIP.

GClements

08-28-2015, 12:45 AM

It's not simply a matter of changing the mode. You'll need to build the topology and use glDrawElements().

woolfik

08-28-2015, 01:20 AM

That I was think so. Can You show me some example base on my code from first post?

GClements

08-28-2015, 10:34 AM

That I was think so. Can You show me some example base on my code from first post?

Well, you don't have to use glDrawElements(); you can use glBegin/glEnd. But you need topology, i.e. which vertices form which triangle. You can't just use the first 3 vertices for the first triangle, then next 3 for the second triangle, etc. For a connected mesh, each vertex will be used in several triangles

If the vertices lie in a plane, you can use Delaunay triangulation (https://en.wikipedia.org/wiki/Delaunay_triangulation) to generate the topology.

But the fact that you're storing the coordinates in a 2D array suggests that the vertices may lie roughly on a grid. In which case, you may be able to use:

glBegin(GL_TRIANGLES)

for I := 0 to High(Stars) - 2 do //stars is my array of array of points

begin

for j := 0 to High(stars[i]) - 2 do

begin

glColor3ub(stars[i,j].R,stars[i,j].g, stars[i,j].b);

glVertex3i(stars[i,j].x,stars[i,j].y, stars[i,j].distance);

glColor3ub(stars[i+1,j].R,stars[i+1,j].g, stars[i+1,j].b);

glVertex3i(stars[i+1,j].x,stars[i+1,j].y, stars[i+1,j].distance);

glColor3ub(stars[i,j+1].R,stars[i,j+1].g, stars[i,j+1].b);

glVertex3i(stars[i,j+1].x,stars[i,j+1].y, stars[i,j+1].distance);

glColor3ub(stars[i,j+1].R,stars[i,j+1].g, stars[i,j+1].b);

glVertex3i(stars[i,j+1].x,stars[i,j+1].y, stars[i,j+1].distance);

glColor3ub(stars[i+1,j].R,stars[i+1,j].g, stars[i+1,j].b);

glVertex3i(stars[i+1,j].x,stars[i+1,j].y, stars[i+1,j].distance);

glColor3ub(stars[i+1,j+1].R,stars[i+1,j+1].g, stars[i+1,j+1].b);

glVertex3i(stars[i+1,j+1].x,stars[i+1,j+1].y, stars[i+1,j+1].distance);

end;

glEnd;

end;

Carmine

08-28-2015, 04:16 PM

It is not as that simple. Exactly. Hence Delauney Triangulation.

The figures you posted make it look like your data is 2D.

But the vertex coordinates are 3D.

Are you treating this point set as if it is 2D?

Are all the 'distance' values about the same?

If not, then there are other issues to deal with.

woolfik

09-03-2015, 05:22 AM

GClements - thx it works fine.

Powered by vBulletin® Version 4.2.3 Copyright © 2018 vBulletin Solutions, Inc. All rights reserved.