OpenGL 实验二 纹理映射
一、创建工程
(同实验一)
1.1 用VS2015创建exp_2
1.2 建立OpenGL开发环境:复制头文件,静态库文件,动态库文件
1.3 配置VS,指定OpenGL头文件路径,连接OpenGL库文件
1.4 为避免在连接glaux.lib时出现无法解析的外部符号_sscanf,配置属性->链接器->输入->附加依赖项中添加依赖项legacy_stdio_definitions.lib
二、创建资源文件
在exp_2目录下创建文件夹/Data,复制图片Create.bmp
(我截图后用画图软件保存为bmp文件)
三、源文件
// exp_2.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <windows.h>
#include <GL\GL.h> //Header File For The OpenGL32 Library
#include <GL\GLU.h> //Header File For The GLu32 Library
#include <GL\GLAUX.H> //Header File For the Glaux Library
#define GLUT_DISABLE_ATEXIT_HACK
#include "GL\GLUT.H"
#pragma warning (disable:4996);
GLfloat rtri;
GLfloat rquad;
GLfloat LightAmbient[] = { 0.5f,0.5f,0.5f,1.0f }; //外界环绕
GLfloat LightDiffuse[] = { 1.0f,1.0f,1.0f,1.0f };
GLfloat LightPosition[] = { 0.0f,0.0f,2.0f,1.0f };
GLuint filter; //Which Filter to Use
GLuint texture[3]; //Storage For 3 Textures
int InitGL(int width, int height);
void DrawGLScene(void);
void myReshape(int w, int h);
void myKeyboard(int key, int x, int y);
void myMovedMouse(int x, int y);
AUX_RGBImageRec *LoadBMP(char *Filename);
int LoadGLTextures();
int main(int argc,char **argv)
{
glutInit(&argc, argv); //Initialize GLUT function callings
glutInitWindowSize(800, 600);//Set window size(width,height) in number of pixels
//Set window position, from the left and top of the screen, in numbers of pixels
glutInitWindowPosition(200, 100);
//Specify a window creation event
glutCreateWindow("3D Graph");
//Specify the drawing function that is called when the window is created or redrew
glutDisplayFunc(DrawGLScene);
glutReshapeFunc(myReshape);
glutSpecialFunc(myKeyboard);
glutMotionFunc(myMovedMouse);
InitGL(800, 600); //Invoke this function for initialization
glutMainLoop(); //Enter the event processing loop
return 0; //Indicate normal te