Sign in to follow this  
Bostown

Drawing graph with Polygon

Recommended Posts

Bostown    100
Hello,

I've been reading this forum for a while now, but made an account for my problem.
I couldn't find a similar problem...


I've been making a graph in C# - OpenGL. Graph #1 is the one it's supposed to look like.
But only the first part looks good, after that I get some weird parts where they go back to base.


We're using the TAO Framework

[code]
Gl.glColor4ub(255,255,0,48);
Gl.glBegin(Gl.GL_POLYGON);


lastPoint = new PointD(Start.X, Start.Y + height);
for (int i = 0; i < arr.Length; i++)
{
double thisValue = arr[i];
double valueHeight = height / currentHighestValue * thisValue;

thisPoint = new PointD(Start.X + i * xGain, Start.Y + height - valueHeight);

Gl.glVertex2d(lastPoint.X, lastPoint.Y);
Gl.glVertex2d(thisPoint.X, thisPoint.Y);
lastPoint = thisPoint;
}

[/code]

I hope any of you knows how to fix this.

Regards,

Share this post


Link to post
Share on other sites
szecs    2990
Don't use polygons. You are drawing "[url="http://www.opengl.org.ru/docs/pg/0202.html"]invalid polygons[/url]".

I'd use GL_QUADS instead.

[font="Courier New"]Gl.glVertex2d(lastPoint.X, 0);
Gl.glVertex2d(thisPoint.X, 0);
Gl.glVertex2d(thisPoint.X, thisPoint.Y);
Gl.glVertex2d(lastPoint.X, lastPoint.Y);
[/font]

Share this post


Link to post
Share on other sites
Bostown    100
[quote name='szecs' timestamp='1313579631' post='4850245']
Don't use polygons. You are drawing "[url="http://www.opengl.org.ru/docs/pg/0202.html"]invalid polygons[/url]".

I'd use GL_QUADS instead.

[font="Courier New"]Gl.glVertex2d(lastPoint.X, 0);
Gl.glVertex2d(thisPoint.X, 0);
Gl.glVertex2d(thisPoint.X, thisPoint.Y);
Gl.glVertex2d(lastPoint.X, lastPoint.Y);
[/font]
[/quote]




Ok Thanx, It works now


Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this