Hello, I am trying to draw a big sphere in background, so it is supposed to look small, but for some reason its just not working. I am a newbie in OpenGL. Can someone please tell me what am I doing wrong? I am drawing the sphere in render function, and translating it by -50 Z. Thank you very much.
#include <stdio.h> // - Just for some ASCII messages
#include "gl/glut.h" // - An interface and windows
#include <math.h> // management library
#include "visuals.h" // Header file for our OpenGL functions
int angle = 0;
void Render()
{
glClear(GL_COLOR_BUFFER_BIT);
glClear(GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
///////////////////////////////////////////////////////// sphere in background
glColor4f(0.5, 0.5, 0.8,0.3);
glTranslatef(0.0, 0.0, -50);
makeSilver();
glutSolidSphere (30, 50, 50);
/////////////////////////////////////////////////////////// sphere in background
drawTorus(angle); //
drawSpheres(angle);
glutSwapBuffers();
}
void drawTorus(int a)
{
glPushMatrix();
glColor3f(0.5, 0.5, 0.8);
glTranslatef(0.0, 50, 0.0);
glRotatef(a, 0.0, 1.0, 0.0);
glutSolidTorus( 4, 16, 20, 15);
glPopMatrix();
}
void drawSpheres(int a)
{
glPushMatrix();
glColor3f(1.0, 0.5, 0.2);
makeCopper();
glRotatef(a, 0.0, 0.0, 1.0);
glPushMatrix();
glTranslatef(-18.0, 14.0, 13.0);
glutSolidSphere (10, 50, 50);
glPopMatrix();
glPushMatrix();
glTranslatef(14.0, -15.0, -16.0);
glutSolidSphere (10, 50, 50);
glPopMatrix();
glPushMatrix();
glTranslatef(-4.0, -27.0, 15.0);
glutSolidSphere (10, 50, 50);
glPopMatrix();
glPushMatrix();
glTranslatef(19, -28, 12.0);
glutSolidSphere (10, 50, 50);
glPopMatrix();
glPushMatrix();
glTranslatef(-17, 36.0,19.0);
glutSolidSphere (10, 50, 50);
glPopMatrix();
glPushMatrix();
glTranslatef(41.0, -19.0, 35.0);
glutSolidSphere (10, 50, 50);
glPopMatrix();
glPushMatrix();
glTranslatef(-35.0, -25.0, 0.0);
glutSolidSphere (10, 50, 50);
glPopMatrix();
glPushMatrix();
glTranslatef(30.0, 40.0, 0.0);
glutSolidSphere (10, 50, 50);
glPopMatrix();
glPopMatrix();
}
void makeCopper() /////////////////////////////////////// FOR COPPER TEXTURING FOR SMALL SPHERES
{
GLfloat specref[4];
specref[0] = 0.247; specref[1] = 0.225; specref[2] = 0.065; specref[3] = 1.0;
glMaterialfv(GL_FRONT,GL_AMBIENT,specref);
specref[0] = 0.346; specref[1] = 0.314; specref[2] = 0.090; specref[3] = 1.0;
glMaterialfv(GL_FRONT,GL_DIFFUSE,specref);
specref[0] = 0.797; specref[1] = 0.724; specref[2] = 0.208; specref[3] = 1.0;
glMaterialfv(GL_FRONT,GL_SPECULAR,specref);
glMaterialf(GL_FRONT,GL_SHININESS,51.2);
}
void makeSilver()//////////////////////////////// FOR SILVER TEXTURING FOR SPHERE
{
GLfloat specref[4];
specref[0] = 0.231; specref[1] = 0.231; specref[2] = 0.231; specref[3] = 1.0;
glMaterialfv(GL_FRONT,GL_AMBIENT,specref);
specref[0] = 0.275; specref[1] = 0.275; specref[2] = 0.275; specref[3] = 1.0;
glMaterialfv(GL_FRONT,GL_DIFFUSE,specref);
specref[0] = 0.774; specref[1] = 0.774; specref[2] = 0.774; specref[3] = 1.0;
glMaterialfv(GL_FRONT,GL_SPECULAR,specref);
glMaterialf(GL_FRONT,GL_SHININESS,59.5);
}
//-----------------------------------------------------------
void Resize(int w, int h)
{
if (h==0) h=1;
glViewport(0,0,w,h);
// Setup viewing volume
glMatrixMode(GL_PROJECTION);
//glLoadIdentity();
////(02b)
// L R B T N F
// glOrtho (-50.0f, 50.0f, -50.0f, 50.0f,-500.0f,500.0f);
//glFrustum(-50.0f, 50.0f, -50.0f, 50.0f,-500.0f,500.0f);
float aspect = (float)w/(float)h; /// aspect ratio
//glPushMatrix();
//glMatrixMode(GL_MODELVIEW );
gluPerspective(60.0, aspect, 1.0, 500.0);
//Resize(w,h);
}
void Idle()
{
if(angle+1 >360)
angle = 1;
else
angle +=1;
glutPostRedisplay();
}
void Setup()
{
glEnable( GL_CULL_FACE );
glShadeModel( GL_SMOOTH );
glEnable(GL_DEPTH_TEST);
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glDepthFunc( GL_LEQUAL );
glClearDepth(1.0);
glHint(GL_PERSPECTIVE_CORRECTION_HINT,GL_NICEST);
glEnable(GL_COLOR_MATERIAL);
glColorMaterial( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE );
//////////////////////////////////////////////////////////// IMPLEMENTATION OF LIGHT SOURCE////////////////////////////////////
GLfloat light_position[] = { 0.0, 0.0,50.0, 0.0 };
glLightfv( GL_LIGHT0, GL_POSITION, light_position);
GLfloat ambientLight[] = { 0.8, 0.8, 0.8, 1.0 };
GLfloat diffuseLight[] = { 0.5, 0.5, 0.5, 1.0 };
GLfloat specularLight[] = { 0.4, 0.4, 0.4, 1.0 };
glLightfv( GL_LIGHT0, GL_AMBIENT, ambientLight );
glLightfv( GL_LIGHT0, GL_DIFFUSE, diffuseLight );
glLightfv( GL_LIGHT0, GL_SPECULAR, specularLight );
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// polygon rendering mode and material properties
glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);
glEnable( GL_LIGHTING );
glEnable( GL_LIGHT0);
glEnable(GL_BLEND);
// incoming // // stored //
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
// Black background
glClearColor(0.0f,0.0f,0.0f,1.0f);
}