PDA

View Full Version : Trouble rendering in Delphi



dcr269
02-25-2016, 01:12 PM
Hello,
I am adding a small 3D viewer to a Delphi application. I have opengl initialized and appears to be working correctly.
I am trying to set up the viewer to add features as the are measured. ie: points lines circle cones etc

Here is the issue I can not get lines( the first geometry I tried) to draw:


This is the draw routine
procedure TForm2.Draw;

begin
// glClearColor(1, 1, 1, 0.0);
glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT);
DrawGradientBackGround;
DrawXYZOrientation;
// glLoadIdentity;
DrawGLLine();
SwapBuffers(wglGetCurrentDC);
end;

this is the line draw routine( right now the values are meaningless)
procedure TForm2.DrawGLLine;
Begin
glPushMatrix();
// glMatrixMode( GL_MODELVIEW );

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glBegin(GL_LINES);
glColor3f(1.0, 1.0, 0.0);
glvertex3f(0.0,0.0,0.0);
glvertex3f(3.0,3.0,3.0);
glEnd;
glMatrixMode(GL_PROJECTION);
glPopMatrix ();
// Application.MessageBox('Hello from DrawGLLine',0,0);
end;

And this draws the XYZ indicator
procedure TForm2.DrawXYZOrientation;
const
CYLINDER_DIAMETER = 0.1;
CYLINDER_LENGTH = 1.0;
ARROW_DIAMETER = 0.2;
ARROW_LENGTH = 0.5;
SPHERE_RADIUS = 0.3;
begin
glPushMatrix();
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
glTranslatef(0.0, 0.0, -12.0);
// glTranslated(-0.21, -0.14, -0.5);
glRotated(AX, 1.0, 0.0, 0.0);
glRotated(AY, 0.0, 1.0, 0.0);
// glRotated(m_RotZ, 0.0, 0.0, 1.0);

// z-axis
// make it blue
glColor3d(0.0, 0.0, 1.0);
// draw a cylinder
gluCylinder(quadratic, CYLINDER_DIAMETER, CYLINDER_DIAMETER, CYLINDER_LENGTH, 20, 10);
// move to the end of the cylinder
glTranslated(0.0, 0.0, CYLINDER_LENGTH);
// draw a cone at the end of the cylinder
gluCylinder(quadratic, ARROW_DIAMETER, 0.0, ARROW_LENGTH, 20, 1);
// return to center
glTranslated(0.0, 0.0, -CYLINDER_LENGTH);

// y-axis
// rotate around to the Y axis
glRotated(-90.0, 1.0, 0.0, 0.0);
// make it green
glColor3d(0.0, 1.0, 0.0);
// draw a cylinder
gluCylinder(quadratic, CYLINDER_DIAMETER, CYLINDER_DIAMETER, CYLINDER_LENGTH, 20, 10);
// move to the end of the cylinder
glTranslated(0.0, 0.0, CYLINDER_LENGTH);
// draw a cone at the end of the cylinder
gluCylinder(quadratic, ARROW_DIAMETER, 0.0, ARROW_LENGTH, 20, 1);
// return to center
glTranslated(0.0, 0.0, -CYLINDER_LENGTH);

// x-axis
// rotate around to the x axis
glRotated(90, 0.0, 0.5, 0.0);
// make it red
glColor3d(1.0, 0.0, 0.0);
// draw a cylinder
gluCylinder(quadratic, CYLINDER_DIAMETER, CYLINDER_DIAMETER, CYLINDER_LENGTH, 20, 10);
// move to the end of the cylinder
glTranslated(0.0, 0.0, CYLINDER_LENGTH);
// draw a cone at the end of the cylinder
gluCylinder(quadratic, ARROW_DIAMETER, 0.0, ARROW_LENGTH, 20, 1);
// return to center
glTranslated(0.0, 0.0, -CYLINDER_LENGTH);

// select gray
glColor3d(0.5, 0.5, 0.5);
// draw a sphere
gluSphere(quadratic, SPHERE_RADIUS, 20, 10);

// glBegin(GL_LINES);
// glColor3f(1.0, 1.0, 0.0);
// glvertex3f(0.0,0.0,0.0);
// glvertex3f(3.0,3.0,3.0);
// glEnd;

glPopMatrix ();
end;

Basically without the draw line routine the viewer comes up and I can rotate with the mouse, however If I include the line the XYZ indicator is only visible before you move the window and the mouse does nothing.

Im sure its something Im overlooking but Im stumpted

Thanks
-Derrek