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.
20 changes: 20 additions & 0 deletions nb15010张博榕/opengl_project02/opengl_project02.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2012
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "opengl_project02", "opengl_project02\opengl_project02.vcxproj", "{BB19D40C-51BB-4229-B0D6-7375C48F732F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Release|Win32 = Release|Win32
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{BB19D40C-51BB-4229-B0D6-7375C48F732F}.Debug|Win32.ActiveCfg = Debug|Win32
{BB19D40C-51BB-4229-B0D6-7375C48F732F}.Debug|Win32.Build.0 = Debug|Win32
{BB19D40C-51BB-4229-B0D6-7375C48F732F}.Release|Win32.ActiveCfg = Release|Win32
{BB19D40C-51BB-4229-B0D6-7375C48F732F}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
Binary file not shown.
30 changes: 30 additions & 0 deletions nb15010张博榕/opengl_project02/opengl_project02/ReadMe.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
========================================================================
控制台应用程序:opengl_project02 项目概述
========================================================================

应用程序向导已为您创建了此 opengl_project02 应用程序。

本文件概要介绍组成 opengl_project02 应用程序的每个文件的内容。


opengl_project02.vcxproj
这是使用应用程序向导生成的 VC++ 项目的主项目文件,其中包含生成该文件的 Visual C++ 的版本信息,以及有关使用应用程序向导选择的平台、配置和项目功能的信息。

opengl_project02.vcxproj.filters
这是使用“应用程序向导”生成的 VC++ 项目筛选器文件。它包含有关项目文件与筛选器之间的关联信息。在 IDE 中,通过这种关联,在特定节点下以分组形式显示具有相似扩展名的文件。例如,“.cpp”文件与“源文件”筛选器关联。

opengl_project02.cpp
这是主应用程序源文件。

/////////////////////////////////////////////////////////////////////////////
其他标准文件:

StdAfx.h, StdAfx.cpp
这些文件用于生成名为 opengl_project02.pch 的预编译头 (PCH) 文件和名为 StdAfx.obj 的预编译类型文件。

/////////////////////////////////////////////////////////////////////////////
其他注释:

应用程序向导使用“TODO:”注释来指示应添加或自定义的源代码部分。

/////////////////////////////////////////////////////////////////////////////
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
#include <GL/glut.h>
#include <stdlib.h>

static int year = 0, day = 0, moon = 0;

void init(void){
glClearColor(0.0, 0.0, 0.0, 0.0);
glShadeModel(GL_FLAT);
}

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

glColor3f(1.0, 1.0, 1.0);
glPushMatrix();
//����̫��
glColor3f(1.0, 0.0, 0.0);
glutSolidSphere(1.0, 20.0, 16.0);

glRotatef ((GLfloat) year, 0.0, 1.0, 0.0);
glTranslatef (2.0, 0.0, 0.0);
glRotatef ((GLfloat) day, 0.0, 1.0, 0.0);
//���Ƶ���
glColor3f(0.0, 0.0, 1.0);
glutSolidSphere(0.3, 10.0, 8.0);

glTranslatef(1.0, 0.0, 0.0);
glRotatef((GLfloat) moon, 0.0, 1.0, 0.0);
//��������
glColor3f(1.0, 1.0, 1.0);
glutSolidSphere(0.2, 10.0, 8.0);

/*glColor3f(0.7f,0.7f,0.7f);
glutSolidSphere(50.0f,50.0f,50.0f); */

glPopMatrix();
glutSwapBuffers();
}

void reshape(int w, int h){
glViewport(0, 0, (GLsizei) w, (GLsizei) h);

glMatrixMode(GL_PROJECTION);
glLoadIdentity();

gluPerspective(60.0, (GLfloat) w/(GLfloat) h, 1.0, 20.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(0.0, 5.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
/*GLfloat aspect =(float)w/(float)h;

if(w <= h)
{
glOrtho(-100.0f, 100.0f, -100.0f/aspect, 100.0f/aspect, -100.0f, 100.0f);
}
else
{
glOrtho(-100.0f * aspect, 100.0f * aspect, -100.0f, 100.0f, -100.0f, 100.0f);
} */
}

void keyboard(GLubyte key, GLint x, GLint y){
switch(key)
{
case 0x31: //�򿪺�ɫ��ƣ�����1��
glDisable(GL_LIGHT2);
glDisable(GL_LIGHT3);
glEnable(GL_LIGHT1);
break;

case 0x32: //����ɫ��ƣ�����2��
glDisable(GL_LIGHT1);
glDisable(GL_LIGHT3);
glEnable(GL_LIGHT2);
break;

case 0x33: //����ɫ��ƣ�����4��
glDisable(GL_LIGHT2);
glDisable(GL_LIGHT1);
glEnable(GL_LIGHT3);
break;

case 0x34: //�򿪺�ɫ����Դ������4��
glDisable(GL_LIGHT0);
glEnable(GL_LIGHT4);
break;

default: //�ر�������Ʋ�������Դ���ɰ�ɫ
glDisable(GL_LIGHT1);
glDisable(GL_LIGHT2);
glDisable(GL_LIGHT3);
glDisable(GL_LIGHT4);
glEnable(GL_LIGHT0);
break;

}
glutPostRedisplay();
}

//������Ⱦ����
void SetupRC(){
glClearColor(0.0, 0.0, 0.0, 1.0);
glEnable(GL_DEPTH_TEST);
glShadeModel(GL_SMOOTH);
}

//���ù�Դ
void SetupLights(){
GLfloat ambientLight[] = {0.2, 0.2, 0.2, 0.1}; //��ɫ����Դ������
GLfloat diffuseLight[] = {0.8, 0.8, 0.8, 1.0}; //��ɫ��Դ������
GLfloat specularLight[] = {1.0, 1.0, 1.0, 1.0}; //��ɫ����Դ�����

GLfloat redAmbiLight[] = {0.2, 0.0, 0.0, 1.0}; //��ɫ����Դ������
GLfloat redDiffLight[] = {0.8, 0.0, 0.0, 1.0}; //��ɫ��Դ������
GLfloat redSpecLight[] = {1.0, 0.0, 0.0, 1.0}; //��ɫ����Դ�����

GLfloat lightPos[] = {50.0, 120.0, 120.0, 1.0}; //��Դλ��
GLfloat spotLightPos[] = {0.0, 0.0, 200.0, 1.0}; //����
GLfloat spotDir[] = {0.0, 0.0, -1.0}; //��Ʒ���

GLfloat redLight[] = {1.0, 0.0, 0.0, 1.0}; //��ɫ��Դ
GLfloat greenLight[] = {0.0, 1.0, 0.0, 1.0}; //��ɫ��Դ
GLfloat blueLight[] = {0.0, 0.0, 1.0, 1.0}; //��ɫ��Դ

glEnable(GL_LIGHTING); //���ù���
glLightfv(GL_LIGHT0, GL_AMBIENT, ambientLight); //���û�����Դ
glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuseLight); //�����������Դ
glLightfv(GL_LIGHT0, GL_SPECULAR, specularLight); //���þ����Դ
glLightfv(GL_LIGHT0, GL_POSITION, lightPos); //���õƹ�λ��
glEnable(GL_LIGHT0); //�򿪰�ɫ����Դ

glLightfv(GL_LIGHT4, GL_AMBIENT, redAmbiLight);
glLightfv(GL_LIGHT4, GL_DIFFUSE, redDiffLight);
glLightfv(GL_LIGHT4, GL_SPECULAR, redSpecLight);
glLightfv(GL_LIGHT4, GL_POSITION, lightPos);

glLightfv(GL_LIGHT1, GL_SPECULAR, redLight); //��ɫ���
glLightfv(GL_LIGHT1, GL_POSITION, spotLightPos);
glLightfv(GL_LIGHT1, GL_SPOT_DIRECTION, spotDir);
glLightf(GL_LIGHT1, GL_SPOT_CUTOFF, 85.0);

glLightfv(GL_LIGHT2, GL_SPECULAR, greenLight); //��ɫ���
glLightfv(GL_LIGHT2, GL_POSITION, spotLightPos);
glLightfv(GL_LIGHT2, GL_SPOT_DIRECTION, spotDir);
glLightf(GL_LIGHT2, GL_SPOT_CUTOFF, 85.0);

glLightfv(GL_LIGHT3, GL_SPECULAR, blueLight); //��ɫ���
glLightfv(GL_LIGHT3, GL_POSITION, spotLightPos);
glLightfv(GL_LIGHT3, GL_SPOT_DIRECTION, spotDir);
glLightf(GL_LIGHT3, GL_SPOT_CUTOFF, 85.0);

glEnable(GL_COLOR_MATERIAL); //���ò��ʵ���ɫ����
glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE); //ָ��������ɫ����
glMaterialfv(GL_FRONT, GL_SPECULAR, specularLight); //ָ�����϶Ծ����ķ�Ӧ
glMateriali(GL_FRONT, GL_SHININESS, 100); //ָ������ϵ��
}

void main(int argc, char** argv){
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(800, 600);
glutInitWindowPosition(100, 100);
glutCreateWindow(argv[0]);

init();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutKeyboardFunc(keyboard);

SetupRC();
SetupLights();

glutMainLoop();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.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>
<PropertyGroup Label="Globals">
<ProjectGuid>{BB19D40C-51BB-4229-B0D6-7375C48F732F}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>opengl_project02</RootNamespace>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v110</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v110</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</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 Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions);NDEBUG</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>glaux.lib;glu32.lib;opengl32.lib;glut32.lib;glut.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>Use</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<Text Include="ReadMe.txt" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="opengl_project02.cpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?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;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>
<Text Include="ReadMe.txt" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="opengl_project02.cpp">
<Filter>源文件</Filter>
</ClCompile>
</ItemGroup>
</Project>
Binary file not shown.