Skip to main content
GameDev.net gamedev.net
🔒 Locked

gluCylinder etc. in OpenGL ES

Started by ahochan May 2, 2008 at 1:45 AM 4 replies 7.3k views
Original Post
ahochan
ahochan
Hi, I'm in the process of porting an OpenGL application to OpenGL ES. It uses gluCylinder, gluDisk and gluSphere (along with some of the associated quadric functions) Can anyone suggest where to find implementations of these functions that will work in OpenGL ES? I have looked at GLU|ES (glutes.sourceforge.net), but it only contains a few glu functions. I also had a look at the sqi reference implementation of OpenGL (quad.c), but it uses GL_QUAD_STRIP extensively, and I have no idea how to get that to work in ES.
V-man
V-man
Quote:
Original post by ahochan
Hi,

I'm in the process of porting an OpenGL application to OpenGL ES.

It uses gluCylinder, gluDisk and gluSphere (along with some of the
associated quadric functions)

Can anyone suggest where to find implementations of these functions
that will work in OpenGL ES?

I have looked at GLU|ES (glutes.sourceforge.net), but it only contains
a few glu functions. I also had a look at the sqi reference implementation of OpenGL (quad.c), but it uses GL_QUAD_STRIP extensively, and I have no idea how
to get that to work in ES.


Actually, what you were looking at was GLUT|ES. GLUT and GLU are not the same thing.

From what I understand, GL|ES requires VBOs and there isn't any immediate mode or plain vertex array support.
My library has glhCreateCubef2, glhDeleteCubef2, and also functions for sphere, cylinder, partial sphere. You can generate an interleaved format. It generates it in RAM. You would need to put the vertices and indices in a VBO yourself.
It is LGPL, C++, for Windows. But you can take a look at the code if you want.
http://www.geocities.com/vmelkon/glhlibrary.html
ahochan
ahochan
Actually, the link I provided has both GLU ES and GLUT ES. The glut part seems to be fairly complete, but the GLU ES part is labelled as version 0.1 and only contains gluLookat etc.

I had a look at your library, and it seems a bit too complex for my needs. I really just need simple implementations of gluCylinder, gluDisk and gluSphere, I can take care of converting everything else myself. (mostly glBegin/End and glVertex stuff)

dwahler
dwahler
If you're comfortable with basic geometry and trigonometry, it'll probably be easier to do this yourself than track down and adapt someone else's code. E.g. you can generate a disc of radius 1 in the xy-plane like this:

for i = 0 to n:  θ = 2πi/n  Point P_i = (cos θ, sin θ, 0)  generate triangle with points (0,0,0), P_i, P_i+1


Cylinders and spheres are similar, except you have to use two loops to parameterize the whole surface.
ahochan
ahochan
My geometry and trigonometry skills are in serious need of brushing up... so rather than jumping into that now, I went ahead and modified the reference implementation for ES compatibility. I am able to draw the cylinder, but I can't get the normals to work, so the lightning is messed up.

Here is a snippet of the drawing part of the cylinder function.
(original glBegin/glEnd stuff commented out and replaced by ES compatible stuff)
  //glBegin(GL_TRIANGLE_STRIP);  int offset = 0;  int normal_offset = 0;          for (i = 0; i <= slices; i++) {    //glNormal3f(sinCache2, cosCache2, zNormal);    normal_arr[normal_offset++] = sinCache2;    normal_arr[normal_offset++] = cosCache2;    normal_arr[normal_offset++] = zNormal;                        //glVertex3f(radiusLow * sinCache, radiusLow * cosCache, zLow);    vertex_arr[offset++] = radiusLow * sinCache;    vertex_arr[offset++] = radiusLow * cosCache;    vertex_arr[offset++] = zLow;    //glVertex3f(radiusHigh * sinCache, radiusHigh * cosCache, zHigh);    vertex_arr[offset++] = radiusHigh * sinCache;    vertex_arr[offset++] = radiusHigh * cosCache;    vertex_arr[offset++] = zHigh;  }  //glEnd();  glEnableClientState(GL_VERTEX_ARRAY);  glEnableClientState(GL_NORMAL_ARRAY);  glVertexPointer(3, GL_FLOAT, 0, vertex_arr);  glNormalPointer(GL_FLOAT, 0, normal_arr);  glDrawArrays(GL_TRIANGLE_STRIP, 0, offset/3);

Can anyone help me figure out how to get the glNormal3f calls to be rendered properly? The code as it is now renders exactly the same with or without the call to glEnableClientState(GL_NORMAL_ARRAY)
ahochan
ahochan
Never mind... I figured it out. The normal array needs one entry for each vertex...

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.