Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

第二次作业 #135

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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.
Binary file not shown.
Binary file not shown.
Binary file not shown.
22 changes: 22 additions & 0 deletions 21551202陈宇峰/opengl第二次作业/Project.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013
VisualStudioVersion = 12.0.21005.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "opengl第二次作业", "Project1.vcxproj", "{7FD00F43-C87F-4DAF-99EF-30DC96CAD3C5}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Release|Win32 = Release|Win32
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{7FD00F43-C87F-4DAF-99EF-30DC96CAD3C5}.Debug|Win32.ActiveCfg = Debug|Win32
{7FD00F43-C87F-4DAF-99EF-30DC96CAD3C5}.Debug|Win32.Build.0 = Debug|Win32
{7FD00F43-C87F-4DAF-99EF-30DC96CAD3C5}.Release|Win32.ActiveCfg = Release|Win32
{7FD00F43-C87F-4DAF-99EF-30DC96CAD3C5}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
Binary file not shown.
Binary file not shown.
75 changes: 75 additions & 0 deletions 21551202陈宇峰/opengl第二次作业/Project1.vcxproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
</ItemGroup>
<ItemGroup>
<ClCompile Include="earth.cpp" />
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{7FD00F43-C87F-4DAF-99EF-30DC96CAD3C5}</ProjectGuid>
<RootNamespace>Project1</RootNamespace>
<ProjectName>opengl第二次作业</ProjectName>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v120</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v120</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup />
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_CRT_SECURE_NO_DEPRECATE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>OpenGL32.lib;GLu32.lib;GLaux.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
</ClCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
22 changes: 22 additions & 0 deletions 21551202陈宇峰/opengl第二次作业/Project1.vcxproj.filters
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="源文件">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="头文件">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions>
</Filter>
<Filter Include="资源文件">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="earth.cpp">
<Filter>源文件</Filter>
</ClCompile>
</ItemGroup>
</Project>
241 changes: 241 additions & 0 deletions 21551202陈宇峰/opengl第二次作业/earth.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,241 @@
# include <stdlib.h>
#include <stdio.h>
#include <tchar.h>
#include <gl/glaux.h>
# include <gl/glut.h>

static double year = 0, day = 0, startYear = 0;
static double moonday = 0, moonmonth = 0;

GLuint texture[3];
GLUquadricObj *q;
GLUquadricObj *p;
GLUquadricObj *t;
GLUquadricObj *r;
AUX_RGBImageRec *TextureImage[3];

//������ͼ�ļ�
AUX_RGBImageRec *LoadBMP(char *Filename)
{
FILE *File = NULL;
if (!Filename)
{
return NULL;
}
File = fopen(Filename, "r");
if (File)
{
fclose(File);
return auxDIBImageLoad(Filename);
}
return NULL;
}

void init(void)
{
GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 };
GLfloat mat_shininess[] = { 50.0 };
GLfloat light_position[] = { 0.0, 0.0, 0.0, 1.0f };
GLfloat white_light[] = { 1.0, 1.0, 1.0, 1.0 };
GLfloat lmodel_ambient[] = { 0.1, 0.1, 0.1, 1.0 };

glClearColor(0.0, 0.0, 0.0, 0.0);
glShadeModel(GL_SMOOTH);
glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
glLightfv(GL_LIGHT0, GL_DIFFUSE, white_light);
glLightfv(GL_LIGHT0, GL_SPECULAR, white_light);
glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient);
glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE);

q = gluNewQuadric();

gluQuadricNormals(q, GL_SMOOTH);
gluQuadricTexture(q, GL_TRUE);

p = gluNewQuadric();
gluQuadricNormals(p, GL_SMOOTH);
gluQuadricTexture(p, GL_TRUE);

t = gluNewQuadric();
gluQuadricNormals(t, GL_SMOOTH);
gluQuadricTexture(t, GL_TRUE);

r = gluNewQuadric();
gluQuadricNormals(r, GL_SMOOTH);
gluQuadricTexture(r, GL_TRUE);

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

/*******************��ʼ����ͼ**************************************/

memset(TextureImage, 0, sizeof(void *)* 1);

//����������ͼ
if (TextureImage[0] = LoadBMP("DATA/earth.bmp"))
{
glGenTextures(1, &texture[0]);

glBindTexture(GL_TEXTURE_2D, texture[0]);
glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

if (TextureImage[0])
{
if (TextureImage[0]->data)
{
free(TextureImage[0]->data);
}

free(TextureImage[0]);
}
}

//����̫����ͼ
if (TextureImage[1] = LoadBMP("DATA/sun.bmp"))
{
glGenTextures(1, &texture[1]);
glBindTexture(GL_TEXTURE_2D, texture[1]);
glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[1]->sizeX, TextureImage[1]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[1]->data);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

if (TextureImage[1])
{
if (TextureImage[1]->data)
{
free(TextureImage[1]->data);
}

free(TextureImage[1]);
}
}

//����������ͼ
if (TextureImage[2] = LoadBMP("DATA/moon.bmp"))
{
glGenTextures(1, &texture[2]);
glBindTexture(GL_TEXTURE_2D, texture[2]);
glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[2]->sizeX, TextureImage[2]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[2]->data);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

if (TextureImage[2])
{
if (TextureImage[2]->data)
{
free(TextureImage[2]->data);
}

free(TextureImage[2]);
}
}

glEnable(GL_TEXTURE_2D);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_DEPTH_TEST);
}

void display(void)
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

glBindTexture(GL_TEXTURE_2D, texture[1]);
/*�滭̫��*/
glPushMatrix();
glColor3f(0.4, 0.4, 0.2);
glRotatef((GLfloat)year, 0.0, 1.0, 0.0);
//̫����ת
gluSphere(p,2.01,20,16);
glPopMatrix();

glBindTexture(GL_TEXTURE_2D, texture[0]);
/*���Ƶ���*/
glPushMatrix();
//����ת
glRotatef((GLfloat)year, 0.0, 1.0, 0.0);
glTranslatef(6.0, 0.0, 0.0);
//������ת
glRotatef((GLfloat)day, 0.0, 1.0, 0.0);
gluSphere(q,1.0,10,8);

/*���ƹ��*/
glPushMatrix();
glColor3f(0.0, 0.0, 0.0);
glRotatef(90.0f, 1.0, 0.0, 0.0);
glPopMatrix();

glPopMatrix();

glPushMatrix();
glColor3f(0.0, 0.0, 0.0);
glRotatef(90.0f, 1.0, 0.0, 0.0);
glutSolidTorus(0.005, 6.0, 10, 64);
glPopMatrix();


glRasterPos2f(0.0, 0.0);
glutBitmapCharacter(GLUT_BITMAP_9_BY_15, 'A');
glFlush();
}

void reshape(int w, int h)
{
glViewport(0, 0, (GLsizei)w, (GLsizei)h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(40.0, (GLfloat)w / (GLfloat)h, 1.0, 40.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(0.0, 8.0, 15.0, 0.0, 0.0, 0.0, 0.0, 1.0, -1.0);
}

void idle()
{
moonday = moonday + 0.1;
if (moonday >= 360)
{
moonday -= 360;
}
moonmonth = moonmonth + 0.04;
if (moonmonth >= 360)
{
moonmonth -= 360;
}
day = day + 0.05;
if (day >= 360)
{
day -= 360;
}
year = year + 0.1;
if (day >= 360)
{
year -= 360;
}
startYear = startYear + 0.1;
if (startYear >= 360)
{
startYear -= 360;
}

glutPostRedisplay();
}

int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB|GLUT_DEPTH);
glutInitWindowSize(1000, 600);
glutInitWindowPosition(100, 100);
glutCreateWindow(argv[0]);
init();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutIdleFunc(idle);
glutMainLoop();
return 0;
}
Binary file not shown.