Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
20 changes: 20 additions & 0 deletions 21551072徐克/opengl_homework2/opengl_homework2.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

Microsoft Visual Studio Solution File, Format Version 10.00
# Visual Studio 2008
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "opengl_homework2", "opengl_homework2\opengl_homework2.vcproj", "{2C992432-235A-4A98-95F1-A4DC9F09B38C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Release|Win32 = Release|Win32
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{2C992432-235A-4A98-95F1-A4DC9F09B38C}.Debug|Win32.ActiveCfg = Debug|Win32
{2C992432-235A-4A98-95F1-A4DC9F09B38C}.Debug|Win32.Build.0 = Debug|Win32
{2C992432-235A-4A98-95F1-A4DC9F09B38C}.Release|Win32.ActiveCfg = Release|Win32
{2C992432-235A-4A98-95F1-A4DC9F09B38C}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Manifest resource last updated at 0:20:42.25 on 2016/01/09 ����
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
<security>
<requestedPrivileges>
<requestedExecutionLevel level="asInvoker" uiAccess="false"></requestedExecutionLevel>
</requestedPrivileges>
</security>
</trustInfo>
<dependency>
<dependentAssembly>
<assemblyIdentity type="win32" name="Microsoft.VC90.DebugCRT" version="9.0.21022.8" processorArchitecture="x86" publicKeyToken="1fc8b3b9a1e18e3b"></assemblyIdentity>
</dependentAssembly>
</dependency>
<dependency>
<dependentAssembly>
<assemblyIdentity type="win32" name="Microsoft.VC80.CRT" version="8.0.50727.762" processorArchitecture="x86" publicKeyToken="1fc8b3b9a1e18e3b"></assemblyIdentity>
</dependentAssembly>
</dependency>
</assembly>
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version='1.0' encoding='UTF-8' standalone='yes'?>
<assembly xmlns='urn:schemas-microsoft-com:asm.v1' manifestVersion='1.0'>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
<security>
<requestedPrivileges>
<requestedExecutionLevel level='asInvoker' uiAccess='false' />
</requestedPrivileges>
</security>
</trustInfo>
<dependency>
<dependentAssembly>
<assemblyIdentity type='win32' name='Microsoft.VC90.DebugCRT' version='9.0.21022.8' processorArchitecture='x86' publicKeyToken='1fc8b3b9a1e18e3b' />
</dependentAssembly>
</dependency>
<dependency>
<dependentAssembly>
<assemblyIdentity type='win32' name='Microsoft.VC80.CRT' version='8.0.50727.762' processorArchitecture='x86' publicKeyToken='1fc8b3b9a1e18e3b' />
</dependentAssembly>
</dependency>
</assembly>
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Empty file.
33 changes: 33 additions & 0 deletions 21551072徐克/opengl_homework2/opengl_homework2/ReadMe.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
========================================================================
CONSOLE APPLICATION : opengl_homework2 Project Overview
========================================================================

AppWizard has created this opengl_homework2 application for you.

This file contains a summary of what you will find in each of the files that
make up your opengl_homework2 application.


opengl_homework2.vcproj
This is the main project file for VC++ projects generated using an Application Wizard.
It contains information about the version of Visual C++ that generated the file, and
information about the platforms, configurations, and project features selected with the
Application Wizard.

opengl_homework2.cpp
This is the main application source file.

/////////////////////////////////////////////////////////////////////////////
Other standard files:

StdAfx.h, StdAfx.cpp
These files are used to build a precompiled header (PCH) file
named opengl_homework2.pch and a precompiled types file named StdAfx.obj.

/////////////////////////////////////////////////////////////////////////////
Other notes:

AppWizard uses "TODO:" comments to indicate parts of the source code you
should add to or customize.

/////////////////////////////////////////////////////////////////////////////
Binary file not shown.
223 changes: 223 additions & 0 deletions 21551072徐克/opengl_homework2/opengl_homework2/opengl_homework2.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,223 @@
// opengl_homework2.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
#include <glut.h>
#include <gl/GL.h>
#include <gl/GLU.h>
#include <SDL.h>

using namespace std;

static GLfloat sunRevolute = 0.0f; //̫���Դ�����
static GLfloat earthRevolute = 0.0f; //�����Դ�����
static GLfloat earthRotate = 200.0f; //����ת����
static GLfloat moonRevolute = 0.0f; //�����Դ�����
static GLfloat moonRotate = 10.0f; //����ת����

GLUquadricObj *sunQuadObj; //�������η��̶���
SDL_Surface *sunSurface = NULL;
GLuint sunTexture;

GLUquadricObj *earthQuadObj;
SDL_Surface *earthSurface;
GLuint earthTexture;

GLUquadricObj *moonQuadObj;
SDL_Surface *moonSurface;
GLuint moonTexture;

void ShutdownRC()
{
glDeleteTextures(1, &sunTexture);
glDeleteTextures(1, &earthTexture);
glDeleteTextures(1, &moonTexture);
glDisable(GL_TEXTURE_2D);
glDisable(GL_LIGHT0);
glDisable(GL_LIGHTING);
glDisable(GL_DEPTH_TEST);
}

void myDisplay(void){
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(75,1,1,0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(0,0,-25,0,0,0,0,1,0);

//����̫����Դ
GLfloat sun_light_position[] = {0.0f, 0.0f, 0.0f, 1.0f};
GLfloat sun_light_ambient[] = {1.0f, 1.0f, 1.0f, 1.0f};
GLfloat sun_light_diffuse[] = {1.0f, 1.0f, 1.0f, 1.0f};
GLfloat sun_light_specular[] = {1.0f, 1.0f, 1.0f, 1.0f};
glLightfv(GL_LIGHT0, GL_POSITION, sun_light_position);
glLightfv(GL_LIGHT0, GL_AMBIENT, sun_light_ambient);
glLightfv(GL_LIGHT0, GL_DIFFUSE, sun_light_diffuse);
glLightfv(GL_LIGHT0, GL_SPECULAR, sun_light_specular);
glEnable(GL_LIGHT0);
glEnable(GL_LIGHTING);
glEnable(GL_DEPTH_TEST);

// ����̫���IJ���
GLfloat sun_mat_ambient[] = {0.0f, 0.0f, 0.0f, 1.0f};
GLfloat sun_mat_diffuse[] = {0.0f, 0.0f, 0.0f, 1.0f};
GLfloat sun_mat_specular[] = {0.0f, 0.0f, 0.0f, 1.0f};
GLfloat sun_mat_emission[] = {0.3f, 0.0f, 0.0f, 1.0f};
GLfloat sun_mat_shininess = 0.0f;
glMaterialfv(GL_FRONT, GL_AMBIENT, sun_mat_ambient);
glMaterialfv(GL_FRONT, GL_DIFFUSE, sun_mat_diffuse);
glMaterialfv(GL_FRONT, GL_SPECULAR, sun_mat_specular);
glMaterialfv(GL_FRONT, GL_EMISSION, sun_mat_emission);
glMaterialf (GL_FRONT, GL_SHININESS, sun_mat_shininess);

//����̫��
glPushMatrix();
glBindTexture(GL_TEXTURE_2D, sunTexture);
glRotatef(sunRevolute/30.0*360.0, 0.0f, 0.0f, -1.0f); //̫����ת������30��
gluSphere(sunQuadObj, 4.0, 20, 20);
glPopMatrix();

//����������
GLfloat earth_mat_ambient[] = {0.0f, 0.0f, 0.5f, 1.0f};
GLfloat earth_mat_diffuse[] = {0.0f, 0.0f, 0.5f, 1.0f};
GLfloat earth_mat_specular[] = {0.0f, 0.0f, 1.0f, 1.0f};
GLfloat earth_mat_emission[] = {0.0f, 0.0f, 0.0f, 1.0f};
GLfloat earth_mat_shininess = 30.0f;
glMaterialfv(GL_FRONT, GL_AMBIENT, earth_mat_ambient);
glMaterialfv(GL_FRONT, GL_DIFFUSE, earth_mat_diffuse);
glMaterialfv(GL_FRONT, GL_SPECULAR, earth_mat_specular);
glMaterialfv(GL_FRONT, GL_EMISSION, earth_mat_emission);
glMaterialf (GL_FRONT, GL_SHININESS, earth_mat_shininess);

glPushMatrix();
glBindTexture(GL_TEXTURE_2D, earthTexture);
glRotatef(earthRotate/360.0*360.0,0.0f,0.0f,-1.0f); //����ת������360��
glTranslatef(14.0f,0.0f,0.0f);
glRotatef(earthRevolute/1.0f*360.0, 0.0f, 0.0f, -1.0f); //������ת������1��
gluSphere(earthQuadObj, 2.0, 15, 15);

//�����������
GLfloat moon_mat_ambient[] = {0.5f, 0.5f, 0.0f, 1.0f};
GLfloat moon_mat_diffuse[] = {0.5f, 0.5f, 0.0f, 1.0f};
GLfloat moon_mat_specular[] = {1.0f, 1.0f, 0.0f, 1.0f};
GLfloat moon_mat_emission[] = {0.0f, 0.0f, 0.0f, 1.0f};
GLfloat moon_mat_shininess = 50.0f;
glMaterialfv(GL_FRONT, GL_AMBIENT, moon_mat_ambient);
glMaterialfv(GL_FRONT, GL_DIFFUSE, moon_mat_diffuse);
glMaterialfv(GL_FRONT, GL_SPECULAR, moon_mat_specular);
glMaterialfv(GL_FRONT, GL_EMISSION, moon_mat_emission);
glMaterialf (GL_FRONT, GL_SHININESS, moon_mat_shininess);

glPushMatrix();
glBindTexture(GL_TEXTURE_2D, moonTexture);
glRotatef(moonRotate/27.0*360.0-earthRotate/360.0*360.0+earthRevolute/1.0f*360.0, 0.0f, 0.0f, 1.0f); //����ת������27��
glTranslatef(5.0f,0.0f,0.0f);
glRotatef(moonRevolute/27.0f*360.0, 0.0f, 0.0f, 1.0f); //�����Դ�������27��
gluSphere(moonQuadObj, 1.0, 10, 10);
glPopMatrix();
glPopMatrix();
glFlush();
glutSwapBuffers();
}

void myReshape(int w, int h)
{
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
if (w <= h)
glOrtho(-2.0, 2.0, -2.0 * (GLfloat) h / (GLfloat) w,
2.0 * (GLfloat) h / (GLfloat) w, -10.0, 10.0);
else
glOrtho(-2.0 * (GLfloat) w / (GLfloat) h,
2.0 * (GLfloat) w / (GLfloat) h, -2.0, 2.0, -10.0, 10.0);
glMatrixMode(GL_MODELVIEW);
}

void rotateObj(GLfloat *rot, GLfloat angle)
{
*rot+=0.01f;
if (*rot>=angle)
{
*rot -= angle;
}
}

void renderScene(void)
{
rotateObj(&sunRevolute, 30.0f);
rotateObj(&earthRevolute, 1.0f);
rotateObj(&earthRotate, 360.0f);
rotateObj(&moonRevolute, 27.0f);
rotateObj(&moonRotate, 27.0f);
myDisplay();
}

void init()
{
sunQuadObj = gluNewQuadric();
gluQuadricNormals(sunQuadObj, GLU_SMOOTH);
gluQuadricTexture(sunQuadObj, GL_TRUE);

moonQuadObj = gluNewQuadric();
gluQuadricNormals(moonQuadObj, GLU_SMOOTH);
gluQuadricTexture(moonQuadObj, GLU_TRUE);

earthQuadObj = gluNewQuadric();
gluQuadricNormals(earthQuadObj, GLU_SMOOTH);
gluQuadricTexture(earthQuadObj, GLU_TRUE);

glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);

sunSurface = SDL_LoadBMP("Sun.bmp");
glGenTextures(1,&sunTexture);
glBindTexture(GL_TEXTURE_2D, sunTexture);
glTexImage2D(GL_TEXTURE_2D, 0, 3, sunSurface->w, sunSurface->h, 0, GL_BGR_EXT, GL_UNSIGNED_BYTE, sunSurface->pixels);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

earthSurface = SDL_LoadBMP("Earth.bmp");
printf("------------%p\n",earthSurface);
glGenTextures(1,&earthTexture);
glBindTexture(GL_TEXTURE_2D, earthTexture);
glTexImage2D(GL_TEXTURE_2D, 0, 3, earthSurface->w, earthSurface->h, 0, GL_BGR_EXT, GL_UNSIGNED_BYTE, earthSurface->pixels);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

moonSurface = SDL_LoadBMP("Moon.bmp");
glGenTextures(1,&moonTexture);
glBindTexture(GL_TEXTURE_2D, moonTexture);
glTexImage2D(GL_TEXTURE_2D, 0, 3, moonSurface->w, moonSurface->h, 0, GL_BGR_EXT, GL_UNSIGNED_BYTE, moonSurface->pixels);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

glEnable(GL_TEXTURE_2D);
}

int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowPosition(500,100);
glutInitWindowSize(500, 500);
glutCreateWindow("homework2");
init();
glutReshapeFunc(myReshape);
glutDisplayFunc(myDisplay);
glutIdleFunc(renderScene);
glutMainLoop();
ShutdownRC();
return 0;
}
Loading