Total members 11382 |It is currently Thu Nov 27, 2014 9:06 am Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R

All times are UTC [ DST ]



  Draw a solid sphere using openGL
Sun Feb 19, 2012 8:00 pm 

In this example we draw a simple and fixed colored solid sphere using OpenGL and GLU . glutSolidSphere function is used.
Code:
#include <GL\glut.h>

GLfloat xRotatedyRotatedzRotated;
GLdouble radius=1;


void display(void);
void reshape(int xint y);
 

int main (int argcchar **argv)
{
    
glutInit(&argcargv); 
    
glutInitWindowSize(350,350);
    
glutCreateWindow("Solid Sphere");
    
xRotated yRotated zRotated 30.0;
    
xRotated=43;
    
yRotated=50;
 
    
glutDisplayFunc(display);
    
glutReshapeFunc(reshape);
    
glutMainLoop();
    return 
0;
}

void display(void)
{

    
glMatrixMode(GL_MODELVIEW);
    
// clear the drawing buffer.
    
glClear(GL_COLOR_BUFFER_BIT);
    
// clear the identity matrix.
    
glLoadIdentity();
    
// traslate the draw by z = -4.0
    // Note this when you decrease z like -8.0 the drawing will looks far , or smaller.
    
glTranslatef(0.0,0.0,-5.0);
    
// Red color used to draw.
    
glColor3f(0.90.30.2); 
    
// changing in transformation matrix.
    // rotation about X axis
    
glRotatef(xRotated,1.0,0.0,0.0);
    
// rotation about Y axis
    
glRotatef(yRotated,0.0,1.0,0.0);
    
// rotation about Z axis
    
glRotatef(zRotated,0.0,0.0,1.0);
    
// scaling transfomation 
    
glScalef(1.0,1.0,1.0);
    
// built-in (glut library) function , draw you a sphere.
    
glutSolidSphere(radius,20,20);
    
// Flush buffers to screen
     
    
glFlush();        
    
// sawp buffers called because we are using double buffering 
   // glutSwapBuffers();
}

void reshape(int xint y)
{
    if (
== || == 0) return;   
    
glMatrixMode(GL_PROJECTION);  
    
glLoadIdentity(); 
    
gluPerspective(39.0,(GLdouble)x/(GLdouble)y,0.6,21.0);
    
glMatrixMode(GL_MODELVIEW);
    
glViewport(0,0,x,y);  //Use the whole window for rendering
}
 



Attachments:
Solid_Sphere.png
Solid_Sphere.png [ 3 KiB | Viewed 15863 times ]

_________________
Please recommend / share my post if you found it helpful.
Author:
Mastermind
User avatar Posts: 2694
Have thanks: 73 time
Post new topic Reply to topic  [ 1 post ] 

  Related Posts  to : Draw a solid sphere using openGL
 Adding lighting to a solid sphere     -  
 Draw 3d cube using openGL     -  
 Add solid Border to div     -  
 change border style to solid at div tag     -  
 Sphere by Lines     -  
 drawing a rotating sphere     -  
 rotate sphere in a circle with light     -  
 OpenGl simple example     -  
 openGL in java     -  
 Drawing Torus using OpenGL     -  

All times are UTC [ DST ]



Topic Tags

C++ Graphics






Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team