Sign in to follow this  
izua

OpenGL Rendering from a method

Recommended Posts

I'm making a poly class, which will hold polygons, and do some computing with them. It also has a Render() method, which will do a Vertex3f() with each of the points the class is holding. it basically goes like this
void Poly::Render()
{
     //a very small optimisation
     if (cnum==3) {glBegin(GL_TRIANGLES);}
     if (cnum==4) {glBegin(GL_QUADS);}
     if (cnum>4) {glBegin(GL_POLYGON);}                 
     for (int i=0;i<=cnum;i++) {
         glVertex3f(corners[i].x,corners[i].y,corners[i].z);
     }   
     glEnd();       
}


is it "right" to do this in a class' method? it works, and i'm defining and rendering a poly from my opengl main rendering function, but is it "right" to do it this way? or does it involve working with some kind of handles to opengl windows, etc? i'm not an opengl guru, i am in my first weeks, and every app i make is inside NeHe's framework. thank you. later edit: cnum is a variable which will hold how many corners the poly will have.

Share this post


Link to post
Share on other sites
you shouldnt call glBegin / glEnd for every poly. this should be done once for a whole batch of polygons. you might run into some performance issues with your current method. this will probably only be an issue if you are going to be rendering something with a large number of polys like a mesh. if you are just trying to render one simple poly, and not a large group the glBegin/glEnd issue wont be too bad.

as for your question about calling this outside of your main function, it will work fine as long as you created your OpenGL context right and all that jazz.

Share this post


Link to post
Share on other sites
well, at a latter point i will do have a higher level class, which will handle adding polys, grouping them (perhaps even octrees).
uh, i see here. so it's better to use glBegin-glEnd and render all polys there. thanks.

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