Well, drawing lines using individual points is expensive. Why aren’t you letting OpenGL draw the lines using GL_LINES primitives?
Thats not what my project is about.
I need to make my own line drawing algorithm in OpenGL (incremental, incremental symmetrical, midpoint, two step etc…).
Also, I’ll bet you’re using immediate mode to draw your points. Let’s see your code to draw your points. You at least should use vertex arrays, either client arrays or VBOs (server arrays). That’ll speed things up a lot.
This is my code (most of it is taken from other people’s examples as I only have 3 days of expirience in openGl):
Do I need this?
protected override void InitGLContext()
{
GL.glShadeModel(GL.GL_SMOOTH);
GL.glClearColor(0.0f, 0.0f, 0.0f, 0.5f);
GL.glClearDepth(1.0);
GL.glEnable(GL.GL_DEPTH_TEST);
GL.glDepthFunc(GL.GL_LEQUAL);
GL.glHint(GL.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST);
}
This is where the things get drawn:
public override void glDraw()
{
GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
if (ObjectBeingDrawn)
{
GL.glColor3d(DrawnObjekt.Boja.Red, DrawnObjekt.Boja.Green, DrawnObjekt.Boja.Blue);
glDrawPixels(DrawnObjekt);
}
for (int Counter = 0; Counter < Objekti.Count; Counter++)
{
Objekt = Objekti[Counter];
GL.glColor3d(Objekt.Boja.Red, Objekt.Boja.Green, Objekt.Boja.Blue);
glDrawPixels(Objekt);
}
}
public void glDrawPixels(_Objekt Objekt)
{
for (int i = 0; i < Objekt.TockeObjekta.Count; i++)
{
MouseXposition = Objekt.TockeObjekta[i].X;
MouseYposition = Objekt.TockeObjekta[i].Y;
GetOGLPos();
GL.glBegin(GL.GL_POINTS);
GL.glVertex2d(OpenGlXpos, OpenGlYpos);
GL.glEnd();
}
}
Function that converts windows coordinates to vertex:
public void GetOGLPos()
{
/*
This function converts coordinates from Windows form coordinates to OpenGl vertex coordinates
*/
int[] viewport = new int[4];
double[] modelview = new double[16];
double[] projection = new double[16];
float winX, winY;
double posX, posY, posZ;
GL.glGetDoublev(GL.GL_MODELVIEW_MATRIX, modelview);
GL.glGetDoublev(GL.GL_PROJECTION_MATRIX, projection);
GL.glGetIntegerv(GL.GL_VIEWPORT, viewport);
winX = (float)MouseXposition;
winY = (float)viewport[3] - (float)MouseYposition;
GL.gluUnProject(winX, winY, 0, modelview, projection, viewport, out posX, out posY, out posZ);
OpenGlXpos = posX;
OpenGlYpos = posY;
}
This is my Object class that holds information about line:
public class _Objekt
{
public struct _Boja
{
public double Red;
public double Green;
public double Blue;
};
public List<Point> KrajnjeTocke;
public List<Point> TockeObjekta;
public _Boja Boja;
public Point Tocka;
public _Objekt()
{
KrajnjeTocke = new List<Point>();
TockeObjekta = new List<Point>();
Point Tocka = new Point();
KrajnjeTocke.Add(Tocka);
KrajnjeTocke.Add(Tocka);
}
public void SetColor(double Red, Double Green, Double Blue)
{
Boja.Red = Red;
Boja.Green = Green;
Boja.Blue = Blue;
}
}
Thanx for your help.