How do u draw a circle or a sphere
How would i go about drawing a circle or maybe a sphere.?
The_Noob, everyone has one inside of them
The_Noob, everyone has one inside of them
try something like this:
GLUquadricObj *wireframe;GLUquadricObj *solid;void SetupQuadrics(){wireframe = gluNewQuadric();solid = gluNewQuadric();gluQuadricDrawStyle(wireframe,GLU_LINE);}void RenderQuadrics(){glPushMartix();glTranslatef(0,-2,-5);glColor3f(0,1,0);gluSphere(wireframe,1,10,16);glPopMatrix();glPushMartix();glTranslatef(0,2,-5);glColor3f(1,0,1);gluSphere(solid,1,10,16);glPopMatrix();}
Cha-ching
Basically an excerpt from Kevin Harris'' code sampler page: http://www.codesampler.com/oglsrc.htm
''Pic'' is your texture number designation and ''n'' is like the resolution to take it lightly.
Oh yea, make sure to add the following to your opengl inilization along with your standard stuff.
Makes it look more like a sphere.
Basically an excerpt from Kevin Harris'' code sampler page: http://www.codesampler.com/oglsrc.htm
''Pic'' is your texture number designation and ''n'' is like the resolution to take it lightly.
#define PI 3.14159265358979 #define TWOPI 6.28318530717958 #define PIDIV2 1.57079632679489 GLfloat gl_heading = 0.0f; GLfloat gl_pitch = 0.0f;....void Draw_Sphere(int pic, float c_x, float c_y, float c_z, double r, int n,double trans_x, double trans_y, double trans_z){ glLoadIdentity(); glTranslatef(trans_x, trans_y, trans_z); glRotatef( gl_heading, 0.0, 1.0, 0.0 ); glRotatef( gl_pitch, -1.0, 0.0, 0.0 ); gl_heading += 0.5f; glBindTexture(GL_TEXTURE_2D, texture[pic]); int i = 0; int j = 0; double theta1 = 0.0; double theta2 = 0.0; double theta3 = 0.0; float e_x = 0.0f; float e_y = 0.0f; float e_z = 0.0f; float p_x = 0.0f; float p_y = 0.0f; float p_z = 0.0f; if( r < 0 ) r = -r; if( n < 0 ) n = -n; if( n < 4 || r <= 0 ) { glBegin(GL_POINTS); glVertex3f( c_x, c_y, c_z ); glEnd(); return; } for( j = 0; j < n/2; ++j ) { theta1 = j * TWOPI / n - PIDIV2; theta2 = (j + 1) * TWOPI / n - PIDIV2; glBegin(GL_QUAD_STRIP); for( i = 0; i <= n; i++ ) { theta3 = i * TWOPI / n; e_x = cos(theta2) * cos(theta3); e_y = sin(theta2); e_z = cos(theta2) * sin(theta3); p_x = c_x + r * e_x; p_y = c_y + r * e_y; p_z = c_z + r * e_z; glNormal3f( e_x, e_y, e_z ); glTexCoord2f( i/(double)n,2*(j+1)/(double)n ); glVertex3f( p_x, p_y, p_z ); e_x = cos(theta1) * cos(theta3); e_y = sin(theta1); e_z = cos(theta1) * sin(theta3); p_x = c_x + r * e_x; p_y = c_y + r * e_y; p_z = c_z + r * e_z; glNormal3f( e_x, e_y, e_z ); glTexCoord2f( i/(double)n,2*j/(double)n ); glVertex3f( p_x, p_y, p_z ); } glEnd(); } glNormal3f(0.0,0.0,1.0);}
Oh yea, make sure to add the following to your opengl inilization along with your standard stuff.
glEnable(GL_LIGHT0); glEnable(GL_LIGHTING); glEnable(GL_COLOR_MATERIAL);
Makes it look more like a sphere.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement