I tried to draw a cone with the glu library,but the output of the program is a blank graphic frame,not the cone.
In the output window of vs studio 2019, there are many lines of
DXGI ERROR: CreateDXGIFactory cannot be called from DllMain. [ MISCELLANEOUS ERROR #76: ]
My classmate uses vs studio 2012,so it works correctly.
#include "stdafx.h"
#include <GL/glut.h>
#include <math.h>
GLUquadricObj* quadObj1;
GLUquadricObj* quadObj2;
GLUquadricObj* quadObj3;
GLUquadricObj* quadObj4;
GLUquadricObj* quadObj5;
static float light_ambient[] = { 0.1,0.1,0.1,1.0 };
static float light_diffuse[] = { 0.5,1.0,1.0,1.0 };
static float light_specular[] = { 0.5,1.0,1.0,1.0 };
static float light_position[] = { 90.0,90.0,150.0,0.0 };
static float front_mat_shininess[] = { 60.0 };
static float front_mat_specular[] = { 0.2,0.2,0.2,1.0 };
static float front_mat_diffuse[] = { 0.5,0.5,0.28,1.0 };
static float back_mat_shininess[] = { 60.0 };
static float back_mat_specular[] = { 0.5,0.5,0.2,1.0 };
static float back_mat_diffuse[] = { 1.0,0.9,0.2,1.0 };
static float Imodel_ambient[] = { 1.0,1.0,1.0,1.0 };
static float Imodel_twoside[] = { GL_TRUE };
static float Imodel_oneside[] = { GL_FALSE };
void myInit(void)
{
glClearColor(1.0, 1.0, 1.0, 1.0);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
glMaterialfv(GL_FRONT, GL_DIFFUSE, front_mat_diffuse);
glMaterialfv(GL_FRONT, GL_SPECULAR, front_mat_specular);
glMaterialfv(GL_FRONT, GL_SHININESS, front_mat_shininess);
glMaterialfv(GL_BACK, GL_DIFFUSE, back_mat_diffuse);
glMaterialfv(GL_BACK, GL_SPECULAR, back_mat_specular);
glMaterialfv(GL_BACK, GL_SHININESS, back_mat_shininess);
glLightModelfv(GL_LIGHT_MODEL_AMBIENT, Imodel_ambient);
glLightModelfv(GL_LIGHT_MODEL_TWO_SIDE, Imodel_twoside);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glShadeModel(GL_SMOOTH);
}
void myDisplay(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
/*create four quadric objects*/
quadObj1 = gluNewQuadric();
quadObj2 = gluNewQuadric();
quadObj3 = gluNewQuadric();
quadObj4 = gluNewQuadric();
quadObj5 = gluNewQuadric();
/*draw a cylinder*/
glPushMatrix();
gluQuadricDrawStyle(quadObj1, GLU_FILL);
gluQuadricNormals(quadObj1, GL_FLAT);
gluQuadricOrientation(quadObj1, GLU_INSIDE);
gluQuadricTexture(quadObj1, GL_TRUE);
glColor3f(1.0, 1.0, 0.0);
glRotatef(30, 1.0, 0.0, 0.0);
glRotatef(40, 0.0, 1.0, 0.0);
gluCylinder(quadObj1, 2.0, 2.0, 9.0, 20.0, 8.0);
glPopMatrix();
/*draw a cone*/
glPushMatrix();
gluQuadricDrawStyle(quadObj5, GLU_FILL);
gluQuadricNormals(quadObj5, GL_FLAT);
gluQuadricOrientation(quadObj5, GLU_INSIDE);
gluQuadricTexture(quadObj5, GL_TRUE);
//glColor3f(1.0,0.0,0.0);
glRotatef(30, 1.0, 0.0, 0.0);
glRotatef(40, 0.0, 1.0, 0.0);
gluQuadricDrawStyle(quadObj5, GLU_FILL);
glTranslatef(5.0, 5.0, 0.0);
gluCylinder(quadObj5, 3.0, 0.0, 5.0, 20.0, 8.0);
glPopMatrix();
/*draw a sphere*/
glPushMatrix();
gluQuadricDrawStyle(quadObj2, GLU_SILHOUETTE);
glTranslatef(-5.0, -1.0, 0.0);
gluSphere(quadObj2, 3.0, 20.0, 20.0);
glPopMatrix();
/*draw a disk*/
glPushMatrix();
gluQuadricDrawStyle(quadObj3, GLU_LINE);
glTranslatef(-2.0, 4.0, 0.0);
gluDisk(quadObj3, 2.0, 5.0, 15.0, 10.0);
glPopMatrix();
/*draw a part of a disk*/
glPushMatrix();
gluQuadricDrawStyle(quadObj4, GLU_POINT);
glTranslatef(-3.0, -7.0, 0.0);
gluPartialDisk(quadObj4, 2.0, 5.0, 15.0, 10.0, 10.0, 100.0);
glPopMatrix();
/*delete four Quadric objects*/
gluDeleteQuadric(quadObj1);
gluDeleteQuadric(quadObj2);
gluDeleteQuadric(quadObj3);
gluDeleteQuadric(quadObj4);
gluDeleteQuadric(quadObj5);
glFlush();
}
void myReshape(int w, int h)
{
glViewport(0, 0, (GLsizei)w, (GLsizei)h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0, (GLfloat)w / (GLfloat)h, 1.0, 50.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0.0, 0.0, -25.0);
}
int main(int argc, char** argv)
{
/*initialize*/
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(400, 400);
glutInitWindowPosition(100, 100);
/*create a window*/
glutCreateWindow(" DRAW QUADRIC OBJECTS ");
/*draw and display*/
myInit();
glutReshapeFunc(myReshape);
glutDisplayFunc(myDisplay);
glutMainLoop();
return 0;
}