diff --git "a/21551202\351\231\210\345\256\207\345\263\260/opengl\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/Data/Thumbs.db" "b/21551202\351\231\210\345\256\207\345\263\260/opengl\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/Data/Thumbs.db" new file mode 100755 index 0000000..47141a0 Binary files /dev/null and "b/21551202\351\231\210\345\256\207\345\263\260/opengl\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/Data/Thumbs.db" differ diff --git "a/21551202\351\231\210\345\256\207\345\263\260/opengl\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/Data/earth.bmp" "b/21551202\351\231\210\345\256\207\345\263\260/opengl\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/Data/earth.bmp" new file mode 100755 index 0000000..081d24b Binary files /dev/null and "b/21551202\351\231\210\345\256\207\345\263\260/opengl\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/Data/earth.bmp" differ diff --git "a/21551202\351\231\210\345\256\207\345\263\260/opengl\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/Data/moon.bmp" "b/21551202\351\231\210\345\256\207\345\263\260/opengl\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/Data/moon.bmp" new file mode 100755 index 0000000..28d4ead Binary files /dev/null and "b/21551202\351\231\210\345\256\207\345\263\260/opengl\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/Data/moon.bmp" differ diff --git "a/21551202\351\231\210\345\256\207\345\263\260/opengl\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/Data/moon2.bmp" "b/21551202\351\231\210\345\256\207\345\263\260/opengl\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/Data/moon2.bmp" new file mode 100755 index 0000000..ac9e76d Binary files /dev/null and "b/21551202\351\231\210\345\256\207\345\263\260/opengl\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/Data/moon2.bmp" differ diff --git "a/21551202\351\231\210\345\256\207\345\263\260/opengl\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/Data/muxing.bmp" "b/21551202\351\231\210\345\256\207\345\263\260/opengl\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/Data/muxing.bmp" new file mode 100755 index 0000000..97cc2e8 Binary files /dev/null and "b/21551202\351\231\210\345\256\207\345\263\260/opengl\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/Data/muxing.bmp" differ diff --git "a/21551202\351\231\210\345\256\207\345\263\260/opengl\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/Data/sun.bmp" "b/21551202\351\231\210\345\256\207\345\263\260/opengl\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/Data/sun.bmp" new file mode 100755 index 0000000..907349b Binary files /dev/null and "b/21551202\351\231\210\345\256\207\345\263\260/opengl\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/Data/sun.bmp" differ diff --git "a/21551202\351\231\210\345\256\207\345\263\260/opengl\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/Project.sdf" "b/21551202\351\231\210\345\256\207\345\263\260/opengl\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/Project.sdf" new file mode 100755 index 0000000..e5fbfe8 Binary files /dev/null and "b/21551202\351\231\210\345\256\207\345\263\260/opengl\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/Project.sdf" differ diff --git "a/21551202\351\231\210\345\256\207\345\263\260/opengl\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/Project.sln" "b/21551202\351\231\210\345\256\207\345\263\260/opengl\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/Project.sln" new file mode 100755 index 0000000..3864262 --- /dev/null +++ "b/21551202\351\231\210\345\256\207\345\263\260/opengl\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/Project.sln" @@ -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 diff --git "a/21551202\351\231\210\345\256\207\345\263\260/opengl\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/Project.v12.suo" "b/21551202\351\231\210\345\256\207\345\263\260/opengl\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/Project.v12.suo" new file mode 100755 index 0000000..d143e71 Binary files /dev/null and "b/21551202\351\231\210\345\256\207\345\263\260/opengl\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/Project.v12.suo" differ diff --git "a/21551202\351\231\210\345\256\207\345\263\260/opengl\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/Project1.v12.suo" "b/21551202\351\231\210\345\256\207\345\263\260/opengl\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/Project1.v12.suo" new file mode 100755 index 0000000..2554ddf Binary files /dev/null and "b/21551202\351\231\210\345\256\207\345\263\260/opengl\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/Project1.v12.suo" differ diff --git "a/21551202\351\231\210\345\256\207\345\263\260/opengl\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/Project1.vcxproj" "b/21551202\351\231\210\345\256\207\345\263\260/opengl\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/Project1.vcxproj" new file mode 100755 index 0000000..8f08b44 --- /dev/null +++ "b/21551202\351\231\210\345\256\207\345\263\260/opengl\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/Project1.vcxproj" @@ -0,0 +1,75 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + + + + + {7FD00F43-C87F-4DAF-99EF-30DC96CAD3C5} + Project1 + opengl第二次作业 + + + + Application + true + v120 + MultiByte + + + Application + false + v120 + true + MultiByte + + + + + + + + + + + + + + + Level3 + Disabled + true + _CRT_SECURE_NO_DEPRECATE;%(PreprocessorDefinitions) + + + true + OpenGL32.lib;GLu32.lib;GLaux.lib;%(AdditionalDependencies) + + + + + Level3 + MaxSpeed + true + true + true + + + true + true + true + + + + + + \ No newline at end of file diff --git "a/21551202\351\231\210\345\256\207\345\263\260/opengl\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/Project1.vcxproj.filters" "b/21551202\351\231\210\345\256\207\345\263\260/opengl\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/Project1.vcxproj.filters" new file mode 100755 index 0000000..711fcd5 --- /dev/null +++ "b/21551202\351\231\210\345\256\207\345\263\260/opengl\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/Project1.vcxproj.filters" @@ -0,0 +1,22 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + 源文件 + + + \ No newline at end of file diff --git "a/21551202\351\231\210\345\256\207\345\263\260/opengl\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/earth.cpp" "b/21551202\351\231\210\345\256\207\345\263\260/opengl\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/earth.cpp" new file mode 100755 index 0000000..252c833 --- /dev/null +++ "b/21551202\351\231\210\345\256\207\345\263\260/opengl\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/earth.cpp" @@ -0,0 +1,241 @@ +# include +#include +#include +#include +# include + +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; +} \ No newline at end of file diff --git "a/21551202\351\231\210\345\256\207\345\263\260/opengl\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/earth.v12.suo" "b/21551202\351\231\210\345\256\207\345\263\260/opengl\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/earth.v12.suo" new file mode 100755 index 0000000..ec98c6e Binary files /dev/null and "b/21551202\351\231\210\345\256\207\345\263\260/opengl\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/earth.v12.suo" differ