Question

[C++] I need to make a program to draw a dodecahedron.

[C++]

I need to make a program to draw a dodecahedron.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Below is the C code to draw dodecahedron.

CODE

#include <windows.h>
#include <GL/glut.h>
#include <stdlib.h>

static void resize(int width, int height)
{
const float ar = (float) width / (float) height;

glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum(-ar, ar, -1.0, 1.0, 2.0, 100.0);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity() ;
}

static void display(void)
{

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glColor3d(1,0,0);

//Dodecahedron
glPushMatrix();
glTranslated(-3.0, 1.5, -6);
glScaled(0.5, 0.5, 0.5);
glutSolidDodecahedron();
glPopMatrix();

glPushMatrix();
glTranslated(-3.0, -1.2, -6.0);
glScaled(0.5, 0.5, 0.5);
glutWireDodecahedron();
glPopMatrix();

//Octahedron
glPushMatrix();
glTranslated(-1.0, 1.5, -6);
glutSolidOctahedron();
glPopMatrix();

glPushMatrix();
glTranslated(-1.0, -1.2, -6.0);
glutWireOctahedron();
glPopMatrix();

//Tetrahedron
glPushMatrix();
glTranslated(1.0, 1.5, -6);
glutSolidTetrahedron();
glPopMatrix();

glPushMatrix();
glTranslated(1.0, -1.2, -6.0);
glutWireTetrahedron();
glPopMatrix();

//Icosahedrons
glPushMatrix();
glTranslated(3.0, 1.5, -6);
glutSolidIcosahedron();
glPopMatrix();

glPushMatrix();
glTranslated(3.0, -1.2, -6.0);
glutWireIcosahedron();
glPopMatrix();

glutSwapBuffers();
}

const GLfloat light_ambient[] = { 0.0f, 0.0f, 0.0f, 1.0f };
const GLfloat light_diffuse[] = { 1.0f, 1.0f, 1.0f, 1.0f };
const GLfloat light_specular[] = { 1.0f, 1.0f, 1.0f, 1.0f };
const GLfloat light_position[] = { 2.0f, 5.0f, 5.0f, 0.0f };

const GLfloat mat_ambient[] = { 0.7f, 0.7f, 0.7f, 1.0f };
const GLfloat mat_diffuse[] = { 0.8f, 0.8f, 0.8f, 1.0f };
const GLfloat mat_specular[] = { 1.0f, 1.0f, 1.0f, 1.0f };
const GLfloat high_shininess[] = { 100.0f };

/* Program entry point */

int main(int argc, char *argv[])
{
glutInit(&argc, argv);
glutInitWindowSize(640,480);
glutInitWindowPosition(10,10);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);

glutCreateWindow("Programming Techniques - 3D regular solids");

glutReshapeFunc(resize);
glutDisplayFunc(display);

glClearColor(1,1,1,1);
glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);

glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LESS);

glEnable(GL_LIGHT0);
glEnable(GL_NORMALIZE);
glEnable(GL_COLOR_MATERIAL);
glEnable(GL_LIGHTING);

glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);
glLightfv(GL_LIGHT0, GL_POSITION, light_position);

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, high_shininess);

glutMainLoop();

return EXIT_SUCCESS;
}

Add a comment
Know the answer?
Add Answer to:
[C++] I need to make a program to draw a dodecahedron.
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • C++ I need to make a program to help keep score. The program should first ask...

    C++ I need to make a program to help keep score. The program should first ask for the number of players in the game and the number of rounds to be played. Based on the number of players, the program should then ask for the names of the players and write them to a file. If no file exists, the program should create one. For each of the rounds, the program should accept the scores for each of the players....

  • I need to write a program in C that covers this: I need in c language...

    I need to write a program in C that covers this: I need in c language Design a program with a loop that lets the user enter a series of numbers the user should enter -99 to signal the end of the series. after all the numbers have been entered, the program should display the largest and smallest numbers entered.

  • Visual Basic - I need to make a program to search a text file that is...

    Visual Basic - I need to make a program to search a text file that is in the debug. Found from "IO.File.ReadAllLines".  When the word is typed into a textbox and button pressed, the program should show which line the word first appeared in the text through a message box or another feature. If it is not found, the program will open a message box. I don't have the full code, please assist

  • I am using VIM UNIX/Linux commandline program. I need the lines of code that will make...

    I am using VIM UNIX/Linux commandline program. I need the lines of code that will make the program return an exit code of zero for normal execution and an exit code of 1 for abnormal execution.

  • Java simple problem I need to make a program that will press CTR + ALT +...

    Java simple problem I need to make a program that will press CTR + ALT + F1 key automatic ly when it been called.

  • i need to make a java program to play Yahtzee. it needs to use arrays. can...

    i need to make a java program to play Yahtzee. it needs to use arrays. can you help me?

  • I need to write a class in C++. I need to make a class that uses...

    I need to write a class in C++. I need to make a class that uses measurements of a triangle and outputs its area. It needs to have the following things. variables the hold the base and height, and those should be doubles for precision. Member functions to get and set the variables from part one and that check to ensure the values entered are greater than zero. If the values are incorrect, the function must prompt the user for...

  • I need to write a C++ program where I need to read in a file and...

    I need to write a C++ program where I need to read in a file and do somethings with information inside the file. We can NOT use arrays. The picture below is what is in the file. My question is how do I read in the file and return the number of studies ( the 5 in the file ) so I can pass it through an other funciton. we need to use ofstream commands.

  • I need help with my assignment. It is a java program. Please make it as simple...

    I need help with my assignment. It is a java program. Please make it as simple as you can. Create an ArrayList with elements the objects of previous class. Using a simple loop populate the ArrayList with data from some arrays with data, or from console. Use a loop with iterator and write the information in a File using PrintWriter. Use this address for the file (c:\\result\\MyData.txt). Use the Scanner class to display the content of the file on console.

  • I need this written in the C format not C++ Name this program count.c-The program reads...

    I need this written in the C format not C++ Name this program count.c-The program reads an unknown number of words - strings that all 20 characters or less in length. It simply counts the number of words read. The end of input is signaled when the user enters control-d (end-of-file). Your program prints the number of words that the user entered. 4.

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
Active Questions
ADVERTISEMENT