ravi.joshi53's picture

Errors while migrating from TAO framework to OpenTK

I am migrating from TAO framework to OpenTK. Below is the code for drawing cone, for which I am trying to find substitute-

Glu.GLUquadric quadric = Glu.gluNewQuadric();
try
{
    Glu.gluQuadricDrawStyle(quadric, Glu.GLU_FILL);
    Glu.gluQuadricTexture(quadric, Gl.GL_TRUE);	
    Glu.gluQuadricNormals(quadric, Gl.GL_FLAT);                
    Glu.gluCylinder(quadric, radius, 0, height, 16, 16);
}
finally
{
    Glu.gluDeleteQuadric(quadric);
}

Also while drawing cube, it shows some deprecation error. Below is the code-

Gl.glPushMatrix();
Gl.glBegin(Gl.GL_QUADS);
 
//Right 
Gl.glNormal3d(1, 0, 0);
Gl.glVertex3d(lengthMax, widthMax, 0);
Gl.glVertex3d(lengthMax, widthMax, height);
Gl.glVertex3d(lengthMax, -widthMax, height);
Gl.glVertex3d(lengthMax, -widthMax, 0);
 
//Top 
Gl.glNormal3d(0, 1, 0);
Gl.glVertex3d(lengthMax, widthMax, 0);
Gl.glVertex3d(lengthMax, widthMax, height);
Gl.glVertex3d(-lengthMax, widthMax, height);
Gl.glVertex3d(-lengthMax, widthMax, 0);
 
//Left 
Gl.glNormal3d(-1, 0, 0);
Gl.glVertex3d(-lengthMax, widthMax, 0);
Gl.glVertex3d(-lengthMax, widthMax, height);
Gl.glVertex3d(-lengthMax, -widthMax, height);
Gl.glVertex3d(-lengthMax, -widthMax, 0);
 
//Bottom 
Gl.glNormal3d(0, -1, 0);
Gl.glVertex3d(lengthMax, -widthMax, 0);
Gl.glVertex3d(lengthMax, -widthMax, height);
Gl.glVertex3d(-lengthMax, -widthMax, height);
Gl.glVertex3d(-lengthMax, -widthMax, 0);
 
//Front
Gl.glNormal3d(0, 0, 1);
Gl.glVertex3d(lengthMax, widthMax, height);
Gl.glVertex3d(lengthMax, -widthMax, height);
Gl.glVertex3d(-lengthMax, -widthMax, height);
Gl.glVertex3d(-lengthMax, widthMax, height);
 
//Back
Gl.glNormal3d(0, 0, -1);
Gl.glVertex3d(lengthMax, widthMax, 0);
Gl.glVertex3d(lengthMax, -widthMax, 0);
Gl.glVertex3d(-lengthMax, -widthMax, 0);
Gl.glVertex3d(-lengthMax, widthMax, 0);
 
Gl.glEnd(); 
Gl.glPopMatrix();

I noticed that even in the provided example to draw cube, GL.Vertex3 is used. However it seems GL.Normal3(1, 0, 0) and GL.Vertex3(lengthMax, widthMax, 0) are deprecated.

Please help.


Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
winterhell's picture

All fixed functions are deprecated for version 3.2 core.
If one version of GL.Vertex** works, all will.

ravi.joshi53's picture

winterhell,
I am using OpenTK version 1.1.1501.5712 and GL Version: 2.0.0 - Build 8.14.10.1930.

Can you please provide me code for drawing cone and cube?

winterhell's picture

For starters replace Gl.glVertex3d with GL.Vertex3, and Gl.gl with GL on the rest of the lines.
Do you get any compilation errors? What do you see?

ravi.joshi53's picture

For cube rendering, that works with some deprecation warnings. What about drawing a cone? Glu is also deprecated. how to proceed further?

winterhell's picture

I just wrote a cone code. Havent tested it but you should be able to work it out.

float height=8;
float radius=3;
int numSegments=12;
Vector3[] basePoints=new Vector3[numSegments];
for(int i=0;i<basePoints.Length;i++)
{
basePoints[i]=new Vector3(radius*(float)(Math.Sin(i*2*Math.PI/(float)basePoints.Length),0,radius*(float)(Math.Cos(i*2*Math.PI/(float)basePoints.Length));
}
GL.Begin(BeginMode.Triangles);
for(int i=0;i< basePoints.Length-1;i++)
{
GL.Vertex3(0,height,0); //side triangle
GL.Vertex3(basePoints[i]);
GL.Vertex3(basePoints[i+1]);
 
GL.Vertex3(0,0,0);//base triangle
GL.Vertex3(basePoints[i]);
GL.Vertex3(basePoints[i+1]);
}
GL.End();

I have to ask, why are you not already loading models from file? Using simple geometric primitives goes only so far, and you can create them in a modelling program much faster.

ravi.joshi53's picture
ravi.joshi53 wrote:

For cube rendering, that works with some deprecation warnings. What about drawing a cone? Glu is also deprecated. how to proceed further?

Hey, I got the reference from here. I can draw the cone. Thanks.

ravi.joshi53's picture
winterhell wrote:

I have to ask, why are you not already loading models from file? Using simple geometric primitives goes only so far, and you can create them in a modelling program much faster.

This sounds interesting... Can you please provide me the reference to do it? I have no idea about it.