anonymous No title
No License C++
2019年07月01日
Copy Clone
#include <stdio.h>
#include <stdlib.h>
#include <GL/glut.h>
#include <math.h>
#include <string.h>
#include"Frog.h"

GLfloat red_f[] = { 1.0, 0.0, 0.0, 1.0 };
GLfloat green_f[] = { 0.0, 1.0, 0.0, 1.0 };
GLfloat white_f[] = { 1.0, 1.0, 1.0, 1.0 };
GLfloat black_f[] = { .1, .1, .1, 1.0 };


GLfloat vertexes[8][3] =
{
	{ -1.0, 0.5, 0.5 },
{ -1.0, -0.5, 0.5 },
{ 1.0, -0.5, 0.5 },
{ 1.0, 0.5, 0.5 },
{ -1.0, 0.5, -0.5 },
{ -1.0, -0.5, -0.5 },
{ 1.0, -0.5, -0.5 },
{ 1.0, 0.5, -0.5 }
};


void drawCube() {

	glMaterialfv(GL_FRONT, GL_DIFFUSE, green_f);

	glNormal3f(0, 1, 0);
	glBegin(GL_QUADS);
	glVertex3fv(vertexes[0]);
	glVertex3fv(vertexes[3]);
	glVertex3fv(vertexes[7]);
	glVertex3fv(vertexes[4]);
	glEnd();

	glNormal3f(0, -1, 0);
	glBegin(GL_QUADS);
	glVertex3fv(vertexes[5]);
	glVertex3fv(vertexes[6]);
	glVertex3fv(vertexes[2]);
	glVertex3fv(vertexes[1]);
	glEnd();

	glNormal3f(0, 0, 1);
	glBegin(GL_QUADS);
	glVertex3fv(vertexes[0]);
	glVertex3fv(vertexes[1]);
	glVertex3fv(vertexes[2]);
	glVertex3fv(vertexes[3]);
	glEnd();

	glNormal3f(0, 0, -1);
	glBegin(GL_QUADS);
	glVertex3fv(vertexes[4]);
	glVertex3fv(vertexes[7]);
	glVertex3fv(vertexes[6]);
	glVertex3fv(vertexes[5]);
	glEnd();

	glNormal3f(-1, 0, 0);
	glBegin(GL_QUADS);
	glVertex3fv(vertexes[0]);
	glVertex3fv(vertexes[4]);
	glVertex3fv(vertexes[5]);
	glVertex3fv(vertexes[1]);
	glEnd();

	glNormal3f(1, 0, 0);
	glBegin(GL_QUADS);
	glVertex3fv(vertexes[3]);
	glVertex3fv(vertexes[2]);
	glVertex3fv(vertexes[6]);
	glVertex3fv(vertexes[7]);
	glEnd();
}

void drawEye() {
	glPushMatrix();
	glMaterialfv(GL_FRONT, GL_DIFFUSE, white_f);
	glutSolidSphere(0.4, 30, 30);
	glTranslatef(0, 0, -0.2);
	glMaterialfv(GL_FRONT, GL_DIFFUSE, green_f);
	glutSolidSphere(0.5, 30, 30);
	glTranslatef(0, 0, 0.45);
	glMaterialfv(GL_FRONT, GL_DIFFUSE, black_f);
	glutSolidSphere(0.2, 30, 30);
	glPopMatrix();
}

void drawMouth() {
	glPushMatrix();
	glMaterialfv(GL_FRONT, GL_DIFFUSE, red_f);
	glutSolidCube(0.5);
	glPopMatrix();
}

void drawfrog(void)
{
	/*glPushMatrix();
	glRotatef(90, 1, 0, 0);
	glTranslated(0, 0.5, 0);
	glScalef(0.5, 1, 1);*/
	drawCube();
	glTranslatef(0, -0.2, 0.3);
	drawMouth();
	glTranslatef(-0.5, 1.0, -0.1);
	drawEye();
	glTranslatef(1.0, 0, 0);
	drawEye();
	glPopMatrix();
	//glutSwapBuffers();
}
#include <stdio.h>
#include <stdlib.h>
#include <GL/glut.h>
#include <math.h>
#include <string.h>
#include"Frog.h"

GLfloat red_f[] = { 1.0, 0.0, 0.0, 1.0 };
GLfloat green_f[] = { 0.0, 1.0, 0.0, 1.0 };
GLfloat white_f[] = { 1.0, 1.0, 1.0, 1.0 };
GLfloat black_f[] = { .1, .1, .1, 1.0 };


GLfloat vertexes[8][3] =
{
	{ -1.0, 0.5, 0.5 },
{ -1.0, -0.5, 0.5 },
{ 1.0, -0.5, 0.5 },
{ 1.0, 0.5, 0.5 },
{ -1.0, 0.5, -0.5 },
{ -1.0, -0.5, -0.5 },
{ 1.0, -0.5, -0.5 },
{ 1.0, 0.5, -0.5 }
};


void drawCube() {

	glMaterialfv(GL_FRONT, GL_DIFFUSE, green_f);

	glNormal3f(0, 1, 0);
	glBegin(GL_QUADS);
	glVertex3fv(vertexes[0]);
	glVertex3fv(vertexes[3]);
	glVertex3fv(vertexes[7]);
	glVertex3fv(vertexes[4]);
	glEnd();

	glNormal3f(0, -1, 0);
	glBegin(GL_QUADS);
	glVertex3fv(vertexes[5]);
	glVertex3fv(vertexes[6]);
	glVertex3fv(vertexes[2]);
	glVertex3fv(vertexes[1]);
	glEnd();

	glNormal3f(0, 0, 1);
	glBegin(GL_QUADS);
	glVertex3fv(vertexes[0]);
	glVertex3fv(vertexes[1]);
	glVertex3fv(vertexes[2]);
	glVertex3fv(vertexes[3]);
	glEnd();

	glNormal3f(0, 0, -1);
	glBegin(GL_QUADS);
	glVertex3fv(vertexes[4]);
	glVertex3fv(vertexes[7]);
	glVertex3fv(vertexes[6]);
	glVertex3fv(vertexes[5]);
	glEnd();

	glNormal3f(-1, 0, 0);
	glBegin(GL_QUADS);
	glVertex3fv(vertexes[0]);
	glVertex3fv(vertexes[4]);
	glVertex3fv(vertexes[5]);
	glVertex3fv(vertexes[1]);
	glEnd();

	glNormal3f(1, 0, 0);
	glBegin(GL_QUADS);
	glVertex3fv(vertexes[3]);
	glVertex3fv(vertexes[2]);
	glVertex3fv(vertexes[6]);
	glVertex3fv(vertexes[7]);
	glEnd();
}

void drawEye() {
	glPushMatrix();
	glMaterialfv(GL_FRONT, GL_DIFFUSE, white_f);
	glutSolidSphere(0.4, 30, 30);
	glTranslatef(0, 0, -0.2);
	glMaterialfv(GL_FRONT, GL_DIFFUSE, green_f);
	glutSolidSphere(0.5, 30, 30);
	glTranslatef(0, 0, 0.45);
	glMaterialfv(GL_FRONT, GL_DIFFUSE, black_f);
	glutSolidSphere(0.2, 30, 30);
	glPopMatrix();
}

void drawMouth() {
	glPushMatrix();
	glMaterialfv(GL_FRONT, GL_DIFFUSE, red_f);
	glutSolidCube(0.5);
	glPopMatrix();
}

void drawfrog(void)
{
	/*glPushMatrix();
	glRotatef(90, 1, 0, 0);
	glTranslated(0, 0.5, 0);
	glScalef(0.5, 1, 1);*/
	drawCube();
	glTranslatef(0, -0.2, 0.3);
	drawMouth();
	glTranslatef(-0.5, 1.0, -0.1);
	drawEye();
	glTranslatef(1.0, 0, 0);
	drawEye();
	glPopMatrix();
	//glutSwapBuffers();
}
No one still commented. Please first comment.