Glowing particles opengl - opengl

My particles are not glowing. I searched on the internet that its been done with
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
This piece of code changes my particles, but it is not glowing. Can anybody see what is wrong in my code? Here are the relevant codes:
void init (void) {
glEnable (GL_LIGHTING); //enable the lighting
glEnable (GL_LIGHT0); //enable LIGHT0, our Diffuse Light
glEnable (GL_LIGHT1); //enable LIGHT1, our Ambient Light
glEnable(GL_BLEND);
// glEnable(GL_DEPTH);
// glEnable(GL_COLOR_MATERIAL);
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
}
void update()
{
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glRotatef(g_orientation, 0.0, 1.0, 0.0); // rotate in y axis
glTranslatef(-g_posX, -g_posY, -g_posZ);
glClear(GL_COLOR_BUFFER_BIT);
glClear(GL_DEPTH_BUFFER_BIT);
GLfloat DiffuseLight[] = {dlr, dlg, dlb}; //set DiffuseLight[] to the specified values
GLfloat AmbientLight[] = {alr, alg, alb}; //set AmbientLight[] to the specified values
glLightfv (GL_LIGHT0, GL_DIFFUSE, DiffuseLight); //change the light accordingly
glLightfv (GL_LIGHT1, GL_AMBIENT, AmbientLight); //change the light accordingly
GLfloat LightPosition[] = {lx, ly, lz, lw}; //set the LightPosition to the specified values
glLightfv (GL_LIGHT0, GL_POSITION, LightPosition); //change the light accordingly
glColorMaterial(GL_FRONT,GL_DIFFUSE);
drawRockets();
if(explosion == true){
drawParticles();
}
drawMolen();
glutSwapBuffers();
if(rotate==1)
angle++;
}
//commonly used material values
GLfloat no_mat[] = { 0.0, 0.0, 0.0, 1.0 };
GLfloat default_ambient[] = {0.2, 0.2, 0.2, 1.0};
GLfloat mat_ambient[] = { 0.7, 0.7, 0.7, 1.0 };
GLfloat mat_ambient_color[] = { 0.8, 0.8, 0.2, 1.0 };
GLfloat mat_diffuse[] = { 0.1, 0.5, 0.8, 1.0 };
GLfloat default_diffuse[] = {0.8, 0.8, 0.8, 1.0};
GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 };
GLfloat no_shininess[] = { 0.0 };
GLfloat low_shininess[] = { 5.0 };
GLfloat high_shininess[] = { 100.0 };
GLfloat mat_emission[] = {0.3, 0.5, 0.9, 0.0};
GLfloat mat_emission1[] = {0.0, 1.0, 0.2, 1.0};
GLfloat mat_emission2[] = {0.0, 0.0, 1.0, 0.0};
GLfloat mat_emission3[] = {1.0, 1.0, 0.0, 0.0};
Here is another example how I want my glutsolidspheres to be:
Ball of Light (Light, Material?) glutsolidsphere

Related

OpenGL black screen(GL_PERSPECTIVE, GL_MODELVIEW problem)

I'm trying to move the perspective view, so I can see that the sun, earth, and moon is moving around on a screen.
I'm keep searching and trying to fix this but there's nothing on a screen.
I really need help to fix this...
#include <gl/glew.h>
#include <gl/freeglut.h>
#include <GL/GL.h>
#include <GL/GLU.h>
#include <GL/glut.h>
#include <vector>
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtc/type_ptr.hpp>
using namespace glm;
static int Day = 0, Time = 0;
int windowWidth, windowHeight;
vec3 eye(0, 2.0, 4.0);
vec3 at(0.2, 0, 0);
vec3 up(normalize(cross(vec3(1, 0, 0), at - eye)));
void InitLight() {
// sun_light
GLfloat sun_light_amb[] = { 0.5, 0, 0, 1.0 };
GLfloat sun_light_diffuse[] = { 1, 0.5, 0.5, 1.0 };
GLfloat sun_light_specular[] = { 1, 1, 1, 1.0 };
// moon_light
GLfloat moon_light_amb[] = { 0.5, 0.5, 0, 1.0 };
GLfloat moon_light_diffuse[] = { 1, 1, 0.5, 1.0 };
GLfloat moon_light_specular[] = { 1, 1, 1, 1.0 };
glShadeModel(GL_SMOOTH); // using GL_SMOOTH
glEnable(GL_DEPTH_TEST);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_LIGHT1);
// sun - GL_LIGHT0
glLightfv(GL_LIGHT0, GL_AMBIENT, sun_light_amb);
glLightfv(GL_LIGHT0, GL_DIFFUSE, sun_light_diffuse);
glLightfv(GL_LIGHT0, GL_SPECULAR, sun_light_specular);
// moon - GL_LIGHT1
glLightfv(GL_LIGHT1, GL_AMBIENT, moon_light_amb);
glLightfv(GL_LIGHT1, GL_DIFFUSE, moon_light_diffuse);
glLightfv(GL_LIGHT1, GL_SPECULAR, moon_light_specular);
}
void MyDisplay() {
// material
// sun
GLfloat sun_mat_amb[] = { 0.2, 0 , 0, 1.0 };
GLfloat sun_mat_diffuse[] = { 1, 0.5, 0.5, 1.0 };
GLfloat sun_mat_specular[] = { 0, 0, 0, 1 };
GLfloat sun_mat_emission[] = { 0.3, 0.1, 0.1, 0.0 };
// sun
GLfloat moon_mat_amb[] = { 0.1, 0.1, 0.1, 1.0 };
GLfloat moon_mat_diff[] = { 0.5, 0.5, 0.1, 1.0 };
GLfloat moon_mat_specular[] = { 1.0, 1.0, 1.0, 1.0 };
GLfloat moon_shininess[] = { 100.0 };
GLfloat moon_mat_emission[] = { 0.3, 0.3, 0.1, 0.0 };
// earth
GLfloat earth_mat_amb[] = { 0.1, 0.1, 0.1, 1.0 };
GLfloat earth_mat_diff[] = { 0.1, 0.1, 0.8, 1.0 };
GLfloat earth_mat_specular[] = { 0.5, 0.5, 1.0, 1.0 };
GLfloat earth_shininess[] = { 80.0 };
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(20.f, (GLfloat)windowWidth / (GLfloat)windowHeight, 0.f, 20.f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(eye[0], eye[1], eye[2], at[0], at[1], at[2], up[0], up[1], up[2]);
glEnable(GL_CULL_FACE);
glFrontFace(GL_CW);
glCullFace(GL_FRONT);
glColor3f(1.0, 0.3, 0.3); // sun
glMaterialfv(GL_FRONT, GL_AMBIENT, sun_mat_amb);
glMaterialfv(GL_FRONT, GL_DIFFUSE, sun_mat_diffuse);
glMaterialfv(GL_FRONT, GL_SPECULAR, sun_mat_specular);
glMaterialfv(GL_FRONT, GL_EMISSION, sun_mat_emission);
glutSolidSphere(0.2, 20, 16);
glEnable(GL_LIGHT0); // sun - LIGHT0
glPushMatrix();
glRotatef((GLfloat)Day, 0.0, 1.0, 0.0); // earth
glTranslatef(0.7, 0.0, 0.0);
glRotatef((GLfloat)Time, 0.0, 1.0, 0.0);
glColor3f(0.5, 0.6, 0.7);
glMaterialfv(GL_FRONT, GL_AMBIENT, earth_mat_amb);
glMaterialfv(GL_FRONT, GL_DIFFUSE, earth_mat_diff);
glMaterialfv(GL_FRONT, GL_SPECULAR, earth_mat_specular);
glMaterialfv(GL_FRONT, GL_SHININESS, earth_shininess);
glutSolidSphere(0.1, 10, 8);
glPushMatrix();
glRotatef((GLfloat)Time, 0.0, 1.0, 0.0); // moon
glTranslatef(0.2, 0.0, 0.0);
glColor3f(0.9, 0.8, 0.2);
glMaterialfv(GL_FRONT, GL_AMBIENT, moon_mat_amb);
glMaterialfv(GL_FRONT, GL_DIFFUSE, moon_mat_diff);
glMaterialfv(GL_FRONT, GL_SPECULAR, moon_mat_specular);
glMaterialfv(GL_FRONT, GL_EMISSION, moon_mat_emission);
glutSolidSphere(0.04, 10, 8);
glEnable(GL_LIGHT1); // moon - LIGHT1
glPopMatrix();
glPopMatrix();
glutSwapBuffers();
}
void MyReshape(int w, int h) {
windowWidth = w;
windowHeight = h;
glViewport(0, 0, (GLsizei)w, (GLsizei)h);
}
void MyTimer(int Value) {
Day = (Day + 2) % 360;
Time = (Time + 1) % 360;
mat3 rot = rotate(mat4(1), radians(1.f), vec3(0, 0, 1)); // rotate 1 degree
eye = rot * eye;
up = rot * up;
glutPostRedisplay();
glutTimerFunc(40, MyTimer, 1);
}
int main(int argc, char** argv) {
//Create window
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(500, 500);
glutInitWindowPosition(0, 0);
glutCreateWindow("Test");
//get window size
windowWidth = glutGet(GLUT_WINDOW_WIDTH);
windowHeight = glutGet(GLUT_WINDOW_HEIGHT);
InitLight();
glutDisplayFunc(MyDisplay);
glutReshapeFunc(MyReshape);
glutTimerFunc(40, MyTimer, 1);
glutMainLoop();
return 0;
}
moving sun, earth, moon
using GL_SMOOTH
moving perspective when MyTimer callback (rotate eye and up => 1 degree)
The Perspective Projection matrix defines a Viewing Frustum. The near plane cannot be 0. The near plan must be grater than o and the far plan must be grater than the near plane.
0 < near < far
Change the near plane. e.g:
gluPerspective(20.f, (GLfloat)windowWidth / (GLfloat)windowHeight, 0.f, 20.f);
gluPerspective(20.f, (GLfloat)windowWidth / (GLfloat)windowHeight, 0.1f, 20.f);

Calculate Normals in Shader

I am new to OpenGL and Shaders.
I want to write a toon shader.
I have this OpenGL code:
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
float black[] = { 0.0, 0.0, 0.0, 1.0 };
float red[] = { 1.0, 0.0, 0.0, 1.0 };
float green[] = { 0.0, 1.0, 0.0, 1.0 };
float blue[] = { 0.0, 0.0, 1.0, 1.0 };
float white[] = { 1.0, 1.0, 1.0, 1.0 };
float lowAmbient[] = { 0.2, 0.2, 0.2, 1.0 };
float fullAmbient[] = { 1.0, 1.0, 1.0, 1.0 };
glMaterialfv(GL_FRONT, GL_AMBIENT, blue);
glMaterialfv(GL_FRONT, GL_DIFFUSE, blue);
glMaterialfv(GL_FRONT, GL_SPECULAR, white);
glMaterialf(GL_FRONT, GL_SHININESS, 128.0);
glLightfv(GL_LIGHT0, GL_AMBIENT, lowAmbient);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0.0, 0.0, -9);
glRotatef(45, 1, 0, 0);
glRotatef(45, 0, 0, 1);
glBegin(GL_QUADS);
//front
glNormal3f(0.0, 0.0, -1.0);
glVertex3f(-1.0, 1.0, 1.0);
glVertex3f(-1.0, -1.0, 1.0);
glVertex3f(1.0, -1.0, 1.0);
glVertex3f(1.0, 1.0, 1.0);
//back
glNormal3f(0.0, 0.0, 1.0);
glVertex3f(1.0, 1.0, -1.0);
glVertex3f(1.0, -1.0, -1.0);
glVertex3f(-1.0, -1.0, -1.0);
glVertex3f(-1.0, 1.0, -1.0);
//right
glNormal3f(1.0, 0.0, 0.0);
glVertex3f(1.0, 1.0, 1.0);
glVertex3f(1.0, -1.0, 1.0);
glVertex3f(1.0, -1.0, -1.0);
glVertex3f(1.0, 1.0, -1.0);
//left
glNormal3f(-1.0, 0.0, 0.0);
glVertex3f(-1.0, 1.0, -1.0);
glVertex3f(-1.0, -1.0, -1.0);
glVertex3f(-1.0, -1.0, 1.0);
glVertex3f(-1.0, 1.0, 1.0);
//top
glNormal3f(0.0, 1.0, 0.0);
glVertex3f(-1.0, 1.0, -1.0);
glVertex3f(-1.0, 1.0, 1.0);
glVertex3f(1.0, 1.0, 1.0);
glVertex3f(1.0, 1.0, -1.0);
//bottom
glNormal3f(0.0, -1.0, 0.0);
glVertex3f(-1.0, -1.0, -1.0);
glVertex3f(-1.0, -1.0, 1.0);
glVertex3f(1.0, -1.0, 1.0);
glVertex3f(1.0, -1.0, -1.0);
glEnd();
//Swap back and front buffer
glutSwapBuffers();
}
void init()
{
glClearColor(0.0, 0.0, 0.0, 1.0);
glEnable(GL_DEPTH_TEST);
glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
float ambientLight[] = { 0.2,0.2,0.2,1.0 };
float diffuseLight[] = { 0.8,0.8,0.8,1.0 };
float specularLight[] = { 1.0,1.0,1.0,1.0 };
float lightPosition[] = { 0.5,0.5,0.0,1.0 };
glLightfv(GL_LIGHT0, GL_AMBIENT, ambientLight);
glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuseLight);
glLightfv(GL_LIGHT0, GL_SPECULAR, specularLight);
glLightfv(GL_LIGHT0, GL_POSITION, lightPosition);
}
My Shader Codes:
#shader vertex
#version 330 core
void main()
{
}
#shader fragment
#version 330 core
vec3 LightPosition = gl_LightSource[0].position;//I don't know this is true or not
vec3 Normal;//I don't know how to calculate
void main()
{
vec4 color1 = gl_FrontMaterial.diffuse + gl_FrontMaterial.specular +
gl_FrontMaterial.ambient;
vec4 color2;
float intensity = dot(LightPosition, Normal);
if (intensity > 0.95) color2 = vec4(1.0, 1.0, 1.0, 1.0);
else if (intensity > 0.75) color2 = vec4(0.8, 0.8, 0.8, 1.0);
else if (intensity > 0.50) color2 = vec4(0.6, 0.6, 0.6, 1.0);
else if (intensity > 0.25) color2 = vec4(0.4, 0.4, 0.4, 1.0);
else color2 = vec4(0.2, 0.2, 0.2, 1.0);
gl_FragColor = color1 * color2;
}
To calculate light intensity and apply colors to my cube object I should know normals.
How can I calculate, or if there is a way, reach them?
(I have no problem with the shader compilation, or other OpenGL stuff. If I close my shader compilation lines I can see a green cube.)

OPENGL lighting result comes out wrong

my desired outcome(in red)
Hi, I'm trying to make my code in opengl c++ to produce this(with light coming from (1,1,1)), and it doesn't work and produces this. Can anyone teach me why?
I thought it was about matrices calculation or lighting usage at first, but not so sure anymore.
light function
void init_light(void) {
glLoadIdentity();
glGetFloatv(GL_PROJECTION_MATRIX, ProjectionMat);
ProjectionMatrix = glm::make_mat4(ProjectionMat);
glGetFloatv(GL_MODELVIEW_MATRIX, ViewMat);
ViewMatrix = glm::make_mat4(ViewMat);
glm::mat4 InverseProjectionMatrix = glm::inverse(ProjectionMatrix);
glm::mat4 InverseViewMatrix = glm::inverse(ViewMatrix);
glm::mat4 M = glm::inverse(ProjectionMatrix * ViewMatrix);
glm::mat4 Matr = ProjectionMatrix * ViewMatrix;
glClearColor(1.0, 1.0, 1.0, 0.0);
//glClearDepth(0.0);
GLfloat ambient[] = { 0.2, 0.2, 0.2, 1.0 };
GLfloat diffuse[] = { 1.0, 1.0, 1.0, 1.0 };
GLfloat specular[] = { 1.0, 1.0, 1.0, 1.0 };
//GLfloat position0[] = { 1., 1., 1., 0.0 };
//GLfloat position1[] = { 1., 1., 1., 1.0 };
GLfloat pos[] = { (GLfloat)(InverseViewMatrix * glm::make_vec4(position0))[0],
(GLfloat)(InverseViewMatrix * glm::make_vec4(position0))[1],
(GLfloat)(InverseViewMatrix * glm::make_vec4(position0))[2],
(GLfloat)(InverseViewMatrix * glm::make_vec4(position0))[3] };
GLfloat spot_direction[] = { 1.0, 1.0, 1.0 };
glLightfv(GL_LIGHT0, GL_AMBIENT, ambient);
glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse);
glLightfv(GL_LIGHT0, GL_SPECULAR, specular);
glLightfv(GL_LIGHT0, GL_SPOT_DIRECTION, spot_direction);
glLightf(GL_LIGHT1, GL_SPOT_CUTOFF, 1.0);
glLightf(GL_LIGHT1, GL_SPOT_EXPONENT, 80.);
//glLightfv(GL_LIGHT0, GL_POSITION, position0);
//glLightfv(GL_LIGHT0, GL_POSITION, pos);
//glLightf(GL_LIGHT0, GL_LINEAR_ATTENUATION, 2.0);
//glLightfv(GL_LIGHT1, GL_AMBIENT, ambient);
//glLightfv(GL_LIGHT1, GL_DIFFUSE, diffuse);
//glLightfv(GL_LIGHT1, GL_POSITION, position1);
GLfloat mat_ambient[] = { 0.2, 0.2, 0.8, 0.0 };
GLfloat mat_diffuse[] = { 1.0, 1.0, 1.0, 0.0 };
GLfloat mat_specular[] = { 0.5, 0.5, 0.5, 0.0 };
//GLfloat mat_emissive[] = { 0.0, 0.0, 0.0, 0.0 };
GLfloat mat_shininess[] = { 120.0 };
glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);
//glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, mat_emissive);
glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);
glColorMaterial(GL_FRONT, GL_SHININESS);
glEnable(GL_COLOR_MATERIAL);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_LIGHT1);
glEnable(GL_NORMALIZE);
glEnable(GL_AUTO_NORMAL);
glShadeModel(GL_SMOOTH);
glEnable(GL_DEPTH_TEST);
}
rendering scene
void renderScene(void) {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
//glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
double ratio = window_size[0] * 1.0 / window_size[1];
if (rotationbool == 1) {
xRot = temp_xRot;
yRot = temp_yRot;
}
glPopMatrix();
gluPerspective(fovy, ratio, zNear + (zoom_factor)* ratio, zFar + (zoom_factor)* ratio);
glLightfv(GL_LIGHT0, GL_POSITION, position0);
glLightfv(GL_LIGHT1, GL_POSITION, position1);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glPopMatrix();
glRotatef(xRot, 1.0, .0, .0);
glRotatef(yRot, .0, 1.0, .0);
glTranslatef(xTrans, yTrans, zTrans);
glPushMatrix(); ...
}
main function
int main(int argc, char* argv[]) {
bool cad_draw = true;
if (cad_draw) {
glutInit(&argc, argv);
}
double L_base[3] = { 0.1, 0.1, 0.1 };
if (cad_draw) {
finemost_limit[0] = L_base[0];
finemost_limit[1] = L_base[1];
finemost_limit[2] = L_base[2];
window_params_init();
//glDepthRange(1.0, 0.);
glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
glEnable(GL_DEPTH_TEST);
glDepthMask(GL_FALSE);
glutInitWindowPosition(100, 100);
glutInitWindowSize(window_size[0], window_size[1]);
glutCreateWindow("Interactive boundary design");
glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE, GLUT_ACTION_CONTINUE_EXECUTION);
//init_sfc();
//init_light();
// register callbacks
glDepthFunc(GL_LEQUAL);
//glDepthFunc(GL_GEQUAL);
glDepthRange(1.0, 0.); // left handed에서 right hanaded로 변경
glutDisplayFunc(renderScene);
glutReshapeFunc(changeSize);
init_light();
///glutMouseWheelFunc(render_wheel);
glutMouseFunc(mousePress);
glutMotionFunc(mouseDrag);
glutPassiveMotionFunc(passive_mouse);
glutKeyboardFunc(simple_keyboard_binding);
// enter GLUT event processing cycle
glutMainLoop();
}
return 0;
}

OpenGL Lighitng

I am new to OpenGL, I made this to switch menu in between ambient, diffuse and specular, position light. It works but looks weird
The code (relevant part ) is:
void gfxinit(void)
{
GLfloat light_ambient[] = { 0.0, 0.0, 0.0, 1.0 };
GLfloat light_diffuse[] = { 1.0, 0.0, 1.0, 1.0 };
GLfloat light_direction[] = { -1, -2, -1, 1 };
GLfloat light_specular[] = { 1.0, 1.0, 1.0, 1.0 };
GLfloat light_position[] = { 0.0, 0.0, 1.0, 0.0 };
GLfloat global_ambient[] = { 0.2, 0.2, 0.2, 1.0 };
glClearColor(0.0, 0.0, 0.0, 1.0); //background Color
list = glGenLists(1);
glNewList(list, GL_COMPILE);
glutSolidSphere(1.0, 30, 12);
glEndList();
glEnable(GL_DEPTH_TEST);
glShadeModel(GL_SMOOTH);
glLightModelfv(GL_LIGHT_MODEL_AMBIENT, global_ambient);
glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
glLightfv(GL_LIGHT1, GL_DIFFUSE, light_diffuse);
glLightfv(GL_LIGHT2, GL_SPECULAR, light_specular);
glLightfv(GL_LIGHT3, GL_POSITION, light_position);
glLightf(GL_LIGHT4, GL_SPOT_EXPONENT, 2.0);
}
and
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glTranslatef(0.0, 0.0, tdist);
glRotatef((GLfloat)spinx, 1.0, 0.0, 0.0);
glRotatef((GLfloat)spiny, 0.0, 1.0, 0.0);
glRotatef((GLfloat)spinz, 0.0, 0.0, 1.0);
glMaterialfv(GL_FRONT, GL_AMBIENT, gray);
glMaterialfv(GL_FRONT, GL_DIFFUSE, cyan);
glMaterialfv(GL_FRONT, GL_SPECULAR, gray);
glMaterialfv(GL_FRONT, GL_POSITION, white);
glMaterialf(GL_FRONT, GL_SHININESS, 70);
glMaterialfv(GL_FRONT, GL_SPECULAR, light_param);
glEnable(GL_LIGHTING);
glEnable(GL_POLYGON_OFFSET_FILL);
if (value == 2) {//ambient
glEnable(GL_LIGHT0);
glPolygonOffset(polyfactor, polyunits);
glCallList(list);
glDisable(GL_LIGHT0);
}
else if (value == 3) {//diffuse
glEnable(GL_LIGHT1);
glPolygonOffset(polyfactor, polyunits);
glCallList(list);
glDisable(GL_LIGHT1);
}
Really thanks if someone can tell me whether there is mistake here or not! Thanks!

OpenGL Light doesn't show up in my program

I want to make a simple OpenGL Program with a sun shining. Here is my code so far:
void init() {
glClearColor (0.0f, 0.0f, 0.0f, 0.0f);
glClear (GL_COLOR_BUFFER_BIT);
glLoadIdentity();
glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0);
// Lighting set up
glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
// Set lighting intensity and color
GLfloat qaAmbientLight[] = {0.2, 0.2, 0.2, 1.0};
GLfloat qaDiffuseLight[] = {0.8, 0.8, 0.8, 1.0};
GLfloat qaSpecularLight[] = {1.0, 1.0, 1.0, 1.0};
glLightfv(GL_LIGHT0, GL_AMBIENT, qaAmbientLight);
glLightfv(GL_LIGHT0, GL_DIFFUSE, qaDiffuseLight);
glLightfv(GL_LIGHT0, GL_SPECULAR, qaSpecularLight);
// Set the light position
GLfloat qaLightPosition[] = {0, 0.758, 0.0, 1.0};
glLightfv(GL_LIGHT0, GL_POSITION, qaLightPosition);
}
void drawSun() {
glClear(GL_COLOR_BUFFER_BIT);
// Set material properties
GLfloat Yellow[] = {1.0, 0.647, 0.0, 1.0};
GLfloat White[] = {1.0, 1.0, 1.0, 1.0};
glMaterialfv(GL_FRONT, GL_AMBIENT, Yellow);
glMaterialfv(GL_FRONT, GL_DIFFUSE, Yellow);
glMaterialfv(GL_FRONT, GL_SPECULAR, White);
glMaterialf(GL_FRONT, GL_SHININESS, 60.0);
float x, y;
float radius = 0.095f;
float x_mid = 0;
float y_mid = 0.758;
glBegin(GL_POLYGON);
x = x_mid + (float)radius * cos(359 * PI / 180.0f);
y = y_mid + (float)radius * sin(359 * PI / 180.0f);
for (int j = 0; j < 360; j++)
{
glVertex2f(x, y);
x = x_mid + (float)radius * cos(j * PI / 180.0f);
y = y_mid + (float)radius * sin(j * PI / 180.0f);
glVertex2f(x, y);
}
glEnd();
}
But the sun doesn't shine, it looks like this :
I want to know if I make some mistakes in my code, any helps will be appreciated.
Shouldn't you call glColorMaterial to enable GL_SPECULAR that is off by default?
Also you are completely skipping all the error checking.