diff --git "a/nb15110\350\260\255\351\224\246\345\277\227/README.md" "b/nb15110\350\260\255\351\224\246\345\277\227/README.md" index 10f8d1e..f154fcf 100644 --- "a/nb15110\350\260\255\351\224\246\345\277\227/README.md" +++ "b/nb15110\350\260\255\351\224\246\345\277\227/README.md" @@ -1,11 +1,20 @@ ##作业说明: - 环境 windows ; VS2015 - 底层框架使用win32 API封装,支持OpenGL 4.3 +- 框架详情 : https://github.com/apanoo/ApanooEngine - GLWindow/ 提供窗口 - System/ 提供系统工具:系统时间等 - Tool/ 封装各类工具:ShaderLoader TextureLoader等 -######作业1:地月系绘制 +######作业1:地月系1 - 地球绕太阳转,月球绕地球转 - 启用灯光 -- 截图保存路径 : \Bin\Debug\screenshot\ \ No newline at end of file +- 截图保存路径 : \Bin\Debug\screenshot\ + +######作业2:地月系2 +- 在作业1基础上添加太阳中心光源 +- 绘制太阳光晕 +- 启用雾 +- 绘制旋转星空 +- 效果图: +![pic-2](ogl-framework/pic/pic2.gif) \ No newline at end of file diff --git "a/nb15110\350\260\255\351\224\246\345\277\227/ogl-framework/.vs/ogl-framewprk/v14/.suo" "b/nb15110\350\260\255\351\224\246\345\277\227/ogl-framework/.vs/ogl-framewprk/v14/.suo" index c9c8812..da0ea6d 100644 Binary files "a/nb15110\350\260\255\351\224\246\345\277\227/ogl-framework/.vs/ogl-framewprk/v14/.suo" and "b/nb15110\350\260\255\351\224\246\345\277\227/ogl-framework/.vs/ogl-framewprk/v14/.suo" differ diff --git "a/nb15110\350\260\255\351\224\246\345\277\227/ogl-framework/Bin/Debug/Data/1.bmp" "b/nb15110\350\260\255\351\224\246\345\277\227/ogl-framework/Bin/Debug/Data/1.bmp" new file mode 100644 index 0000000..3dc012e Binary files /dev/null and "b/nb15110\350\260\255\351\224\246\345\277\227/ogl-framework/Bin/Debug/Data/1.bmp" differ diff --git "a/nb15110\350\260\255\351\224\246\345\277\227/ogl-framework/Bin/Debug/Data/2.bmp" "b/nb15110\350\260\255\351\224\246\345\277\227/ogl-framework/Bin/Debug/Data/2.bmp" new file mode 100644 index 0000000..5e250a9 Binary files /dev/null and "b/nb15110\350\260\255\351\224\246\345\277\227/ogl-framework/Bin/Debug/Data/2.bmp" differ diff --git "a/nb15110\350\260\255\351\224\246\345\277\227/ogl-framework/Bin/Debug/Data/3.bmp" "b/nb15110\350\260\255\351\224\246\345\277\227/ogl-framework/Bin/Debug/Data/3.bmp" new file mode 100644 index 0000000..7817c04 Binary files /dev/null and "b/nb15110\350\260\255\351\224\246\345\277\227/ogl-framework/Bin/Debug/Data/3.bmp" differ diff --git "a/nb15110\350\260\255\351\224\246\345\277\227/ogl-framework/Bin/Debug/Data/4.bmp" "b/nb15110\350\260\255\351\224\246\345\277\227/ogl-framework/Bin/Debug/Data/4.bmp" new file mode 100644 index 0000000..3e24eec Binary files /dev/null and "b/nb15110\350\260\255\351\224\246\345\277\227/ogl-framework/Bin/Debug/Data/4.bmp" differ diff --git "a/nb15110\350\260\255\351\224\246\345\277\227/ogl-framework/Bin/Debug/homework2_d.exe" "b/nb15110\350\260\255\351\224\246\345\277\227/ogl-framework/Bin/Debug/homework2_d.exe" new file mode 100644 index 0000000..4325a2e Binary files /dev/null and "b/nb15110\350\260\255\351\224\246\345\277\227/ogl-framework/Bin/Debug/homework2_d.exe" differ diff --git "a/nb15110\350\260\255\351\224\246\345\277\227/ogl-framework/Bin/Debug/homework2_d.ilk" "b/nb15110\350\260\255\351\224\246\345\277\227/ogl-framework/Bin/Debug/homework2_d.ilk" new file mode 100644 index 0000000..2bfb699 Binary files /dev/null and "b/nb15110\350\260\255\351\224\246\345\277\227/ogl-framework/Bin/Debug/homework2_d.ilk" differ diff --git "a/nb15110\350\260\255\351\224\246\345\277\227/ogl-framework/Bin/Debug/homework2_d.pdb" "b/nb15110\350\260\255\351\224\246\345\277\227/ogl-framework/Bin/Debug/homework2_d.pdb" new file mode 100644 index 0000000..1b98ee5 Binary files /dev/null and "b/nb15110\350\260\255\351\224\246\345\277\227/ogl-framework/Bin/Debug/homework2_d.pdb" differ diff --git "a/nb15110\350\260\255\351\224\246\345\277\227/ogl-framework/Bin/Debug/screenshot/grab_screen 2016 01 14 10 52 16.bmp" "b/nb15110\350\260\255\351\224\246\345\277\227/ogl-framework/Bin/Debug/screenshot/grab_screen 2016 01 14 10 52 16.bmp" new file mode 100644 index 0000000..99d01d8 Binary files /dev/null and "b/nb15110\350\260\255\351\224\246\345\277\227/ogl-framework/Bin/Debug/screenshot/grab_screen 2016 01 14 10 52 16.bmp" differ diff --git "a/nb15110\350\260\255\351\224\246\345\277\227/ogl-framework/Bin/Debug/screenshot/grab_screen 2016 01 14 10 52 20.bmp" "b/nb15110\350\260\255\351\224\246\345\277\227/ogl-framework/Bin/Debug/screenshot/grab_screen 2016 01 14 10 52 20.bmp" new file mode 100644 index 0000000..049d17d Binary files /dev/null and "b/nb15110\350\260\255\351\224\246\345\277\227/ogl-framework/Bin/Debug/screenshot/grab_screen 2016 01 14 10 52 20.bmp" differ diff --git "a/nb15110\350\260\255\351\224\246\345\277\227/ogl-framework/Bin/Debug/screenshot/grab_screen 2016 01 14 10 52 40.bmp" "b/nb15110\350\260\255\351\224\246\345\277\227/ogl-framework/Bin/Debug/screenshot/grab_screen 2016 01 14 10 52 40.bmp" new file mode 100644 index 0000000..7e7dbb4 Binary files /dev/null and "b/nb15110\350\260\255\351\224\246\345\277\227/ogl-framework/Bin/Debug/screenshot/grab_screen 2016 01 14 10 52 40.bmp" differ diff --git "a/nb15110\350\260\255\351\224\246\345\277\227/ogl-framework/Bin/Release/screenshot/grab_screen 2016 01 14 10 52 16.bmp" "b/nb15110\350\260\255\351\224\246\345\277\227/ogl-framework/Bin/Release/screenshot/grab_screen 2016 01 14 10 52 16.bmp" new file mode 100644 index 0000000..99d01d8 Binary files /dev/null and "b/nb15110\350\260\255\351\224\246\345\277\227/ogl-framework/Bin/Release/screenshot/grab_screen 2016 01 14 10 52 16.bmp" differ diff --git "a/nb15110\350\260\255\351\224\246\345\277\227/ogl-framework/Bin/Release/screenshot/grab_screen 2016 01 14 10 52 20.bmp" "b/nb15110\350\260\255\351\224\246\345\277\227/ogl-framework/Bin/Release/screenshot/grab_screen 2016 01 14 10 52 20.bmp" new file mode 100644 index 0000000..049d17d Binary files /dev/null and "b/nb15110\350\260\255\351\224\246\345\277\227/ogl-framework/Bin/Release/screenshot/grab_screen 2016 01 14 10 52 20.bmp" differ diff --git "a/nb15110\350\260\255\351\224\246\345\277\227/ogl-framework/Bin/Release/screenshot/grab_screen 2016 01 14 10 52 40.bmp" "b/nb15110\350\260\255\351\224\246\345\277\227/ogl-framework/Bin/Release/screenshot/grab_screen 2016 01 14 10 52 40.bmp" new file mode 100644 index 0000000..7e7dbb4 Binary files /dev/null and "b/nb15110\350\260\255\351\224\246\345\277\227/ogl-framework/Bin/Release/screenshot/grab_screen 2016 01 14 10 52 40.bmp" differ diff --git "a/nb15110\350\260\255\351\224\246\345\277\227/ogl-framework/Src/GLWindow/GLWindow.cpp" "b/nb15110\350\260\255\351\224\246\345\277\227/ogl-framework/Src/GLWindow/GLWindow.cpp" index 8da9fa9..d0a2489 100644 --- "a/nb15110\350\260\255\351\224\246\345\277\227/ogl-framework/Src/GLWindow/GLWindow.cpp" +++ "b/nb15110\350\260\255\351\224\246\345\277\227/ogl-framework/Src/GLWindow/GLWindow.cpp" @@ -35,8 +35,8 @@ BOOL GLWindow::CreateGlWnd(const char* title, int x, int y, int width, int heigh // ȫ - Ԥ // ʽ - windowStyle = WS_POPUP; - windowExStyle |= WS_EX_TOPMOST; + //windowStyle = WS_POPUP; + //windowExStyle |= WS_EX_TOPMOST; ::AdjustWindowRectEx(&windowRect, windowStyle, 0, windowExStyle); // @@ -128,9 +128,10 @@ BOOL GLWindow::CreateGlWnd(const char* title, int x, int y, int width, int heigh { // ֧opengl4.X ԭΪopengl 2.1 m_hRc = tempContext; } - RECT rect; // ͻС - ::GetClientRect(m_hWnd, &rect); - ResizeGLScene(rect.right - rect.left, rect.bottom - rect.top); // GLĻ (ע⣬ֻʹÿͻ) + //RECT rect; // ͻС + //::GetClientRect(m_hWnd, &rect); + //ResizeGLScene(rect.right - rect.left, rect.bottom - rect.top); // GLĻ (ע⣬ֻʹÿͻ) + ResizeGLScene(width, height); if (!initGL()) // ʼopengl { @@ -269,5 +270,3 @@ HRESULT GLWindow::OnPaint(WPARAM wParam, LPARAM lParam) ::ValidateRect(m_hWnd, NULL); // ʹЧ return TRUE; } - - diff --git "a/nb15110\350\260\255\351\224\246\345\277\227/ogl-framework/Src/Tools/FileTool/FileUtils.h" "b/nb15110\350\260\255\351\224\246\345\277\227/ogl-framework/Src/Tools/FileTool/FileUtils.h" new file mode 100644 index 0000000..f434212 --- /dev/null +++ "b/nb15110\350\260\255\351\224\246\345\277\227/ogl-framework/Src/Tools/FileTool/FileUtils.h" @@ -0,0 +1,31 @@ +#ifndef __FILEUTILS_H__ +#define __FILEUTILS_H__ + +#include +#include + +// ȡıļ +class FileUtils +{ +public: + static std::string ReadFile(const char* filepath) + { + FILE * file = fopen(filepath, "rt"); + fseek(file, 0, SEEK_END); + unsigned long length = ftell(file); // ļ + + char* data = new char[length + 1]; // ڴ + + memset(data, 0, length + 1); // + fseek(file, 0, SEEK_SET); // صļͷ + fread(data, 1, length, file); // ȡļ + + fclose(file); + std::string result(data); + + delete[] data; + return result; + } +}; + +#endif // ifn diff --git "a/nb15110\350\260\255\351\224\246\345\277\227/ogl-framework/Src/Tools/ShaderLoader/shader.cpp" "b/nb15110\350\260\255\351\224\246\345\277\227/ogl-framework/Src/Tools/ShaderLoader/shader.cpp" new file mode 100644 index 0000000..67a904b --- /dev/null +++ "b/nb15110\350\260\255\351\224\246\345\277\227/ogl-framework/Src/Tools/ShaderLoader/shader.cpp" @@ -0,0 +1,131 @@ +#include +#include + +#define GLEW_STATIC +#include "GL/glew.h" + +#include "shader.h" +#include + +////////////////////////////////////////////////////////////////////////// + +Shader::~Shader() +{ + glDeleteProgram(m_ShaderID); +} + +Shader::Shader(const char* vertPath, const char* fragPath) +: m_VertPath(vertPath), m_FragPath(fragPath) +{ + m_ShaderID = 0; +} + +void Shader::enable() +{ + if (0 == m_ShaderID) + { + init(); // ĽǨƵ췽ִ + } + glUseProgram(m_ShaderID); +} + +void Shader::diable() const +{ + glUseProgram(0); +} + +///////////////////////////////set uniform/////////////////////////////////////////// +void Shader::setUniform1f(const GLchar* name, float value) +{ + glUniform1f(getUniformLocation(name), value); +} + +void Shader::setUniform1i(const GLchar* name, int value) +{ + glUniform1i(getUniformLocation(name), value); +} + +void Shader::setUniform2f(const GLchar* name, const vec2& vector) +{ + glUniform2f(getUniformLocation(name), vector.x, vector.y); +} + +void Shader::setUniform3f(const GLchar* name, const vec3& vector) +{ + glUniform3f(getUniformLocation(name), vector.x, vector.y, vector.z); +} + +void Shader::setUniform4f(const GLchar* name, const vec4& vector) +{ + glUniform4f(getUniformLocation(name), vector.x, vector.y, vector.z, vector.w); +} + +void Shader::setUniformMat4(const GLchar* name, const mat4 &matrix) +{ + glUniformMatrix4fv(getUniformLocation(name), 1, GL_FALSE, matrix.elements); +} + +GLuint Shader::getUniformLocation(const GLchar* name) +{ + return glGetUniformLocation(m_ShaderID, name); +} + +//////////////////////////////////init//////////////////////////////////////// +void Shader::init() +{ + GLuint program = glCreateProgram(); + + GLuint vertex = glCreateShader(GL_VERTEX_SHADER); + GLuint fragment = glCreateShader(GL_FRAGMENT_SHADER); + + std::string vertSourceString = FileUtils::ReadFile(m_VertPath); + std::string fragSourceString = FileUtils::ReadFile(m_FragPath); + + const char* vertSource = vertSourceString.c_str(); + const char* fragSource = fragSourceString.c_str(); + + glShaderSource(vertex, 1, &vertSource, NULL); + glCompileShader(vertex); // + GLint result; + glGetShaderiv(vertex, GL_COMPILE_STATUS, &result); + if (result == GL_FALSE) // Ϣ + { + GLint length; + glGetShaderiv(vertex, GL_INFO_LOG_LENGTH, &length); + std::vector error(length); + glGetShaderInfoLog(vertex, length, &length, &error[0]); + // log("error compile vertex shader"); + // log(&error[0]); + glDeleteShader(vertex); + return; + } + + glShaderSource(fragment, 1, &fragSource, NULL); + glCompileShader(fragment); // + glGetShaderiv(fragment, GL_COMPILE_STATUS, &result); + if (result == GL_FALSE) // Ϣ + { + GLint length; + glGetShaderiv(fragment, GL_INFO_LOG_LENGTH, &length); + std::vector error(length); + glGetShaderInfoLog(fragment, length, &length, &error[0]); + // log("error compile fragment shader"); + // log(&error[0]); + glDeleteShader(fragment); + return; + } + + // attach + glAttachShader(program, vertex); + glAttachShader(program, fragment); + + // link + glLinkProgram(program); + glValidateProgram(program); + + // delete + glDeleteShader(vertex); + glDeleteShader(fragment); + + m_ShaderID = program; +} diff --git "a/nb15110\350\260\255\351\224\246\345\277\227/ogl-framework/Src/Tools/ShaderLoader/shader.h" "b/nb15110\350\260\255\351\224\246\345\277\227/ogl-framework/Src/Tools/ShaderLoader/shader.h" new file mode 100644 index 0000000..4e7fb38 --- /dev/null +++ "b/nb15110\350\260\255\351\224\246\345\277\227/ogl-framework/Src/Tools/ShaderLoader/shader.h" @@ -0,0 +1,36 @@ +#ifndef __SHADER_H__ +#define __SHADER_H__ + +#include "../FileTool/FileUtils.h" +#include "../maths/maths.h" + +class Shader +{ +public: + ~Shader(); + + Shader(const char* vertPath, const char* fragPath); + + void init(); // shader + void enable(); // shader + void diable() const; // shader + + ///////////////////////////////////drt uniform/////////////////////////////////////// + + void setUniform1f(const GLchar* name, float value); + void setUniform1i(const GLchar* name, int value); + void setUniform2f(const GLchar* name, const vec2& vector); + void setUniform3f(const GLchar* name, const vec3& vector); + void setUniform4f(const GLchar* name, const vec4& vector); + void setUniformMat4(const GLchar* name, const mat4 &matrix); + +private: + GLuint getUniformLocation(const GLchar* name); + +private: + GLuint m_ShaderID; + const char* m_VertPath; + const char* m_FragPath; +}; + +#endif \ No newline at end of file diff --git "a/nb15110\350\260\255\351\224\246\345\277\227/ogl-framework/Src/Tools/maths/MathUtils.h" "b/nb15110\350\260\255\351\224\246\345\277\227/ogl-framework/Src/Tools/maths/MathUtils.h" new file mode 100644 index 0000000..615f692 --- /dev/null +++ "b/nb15110\350\260\255\351\224\246\345\277\227/ogl-framework/Src/Tools/maths/MathUtils.h" @@ -0,0 +1,10 @@ +#pragma once + +#define _USE_MATH_DEFINES +#include + +// Ƕת +inline float toRadians(float degrees) +{ + return (float)(degrees * (M_PI / 180.0f)); +} \ No newline at end of file diff --git "a/nb15110\350\260\255\351\224\246\345\277\227/ogl-framework/Src/Tools/maths/mat4.cpp" "b/nb15110\350\260\255\351\224\246\345\277\227/ogl-framework/Src/Tools/maths/mat4.cpp" new file mode 100644 index 0000000..5704aae --- /dev/null +++ "b/nb15110\350\260\255\351\224\246\345\277\227/ogl-framework/Src/Tools/maths/mat4.cpp" @@ -0,0 +1,149 @@ +#include "mat4.h" + +mat4::mat4() +{ + for (int i = 0; i < 4 * 4; ++i) + { + elements[i] = 0.0f; + } +} + +mat4::mat4(float diagonal) +{ + for (int i = 0; i < 4 * 4; ++i) + { + elements[i] = 0.0f; + } + + elements[0 + 0 * 4] = diagonal; + elements[1 + 1 * 4] = diagonal; + elements[2 + 2 * 4] = diagonal; + elements[3 + 3 * 4] = diagonal; +} + +mat4& mat4::multiply(const mat4& other) +{ + float data[16]; + for (int y = 0; y < 4; ++y) + { + for (int x = 0; x < 4; ++x) + { + float sum = 0.0f; + for (int e = 0; e < 4; ++e) + { + sum += elements[x + e * 4] * other.elements[e + y * 4]; + } + data[x + y * 4] = sum; + } + } + memcpy(elements, data, 4 * 4 * sizeof(float)); + + return *this; +} + +mat4 mat4::identity() +{ + return mat4(1.0f); +} + +// ѵ1ͼ +mat4 mat4::orthographic(float left, float right, float bottom, float top, float near, float far) +{ + mat4 result(1.0f); + + result.elements[0 + 0 * 4] = 2.0f / (right - left); + result.elements[1 + 1 * 4] = 2.0f / (top - bottom); + result.elements[2 + 2 * 4] = 2.0f / (near - far); + + result.elements[0 + 3 * 4] = (left + right) / (left - right); + result.elements[1 + 3 * 4] = (bottom + top) / (bottom - top); + result.elements[2 + 3 * 4] = (far + near) / (far - near); + + return result; +} + +// ѵ2͸ͼ +mat4 mat4::perspective(float fov, float aspectRatio, float near, float far) +{ + mat4 result(1.0f); + + float q = 1.0f / tan(toRadians(0.5f * fov)); + float a = q / aspectRatio; + + float b = (near + far) / (near - far); + float c = (2.0f * near * far) / (near - far); + + result.elements[0 + 0 * 4] = a; + result.elements[1 + 1 * 4] = q; + result.elements[2 + 2 * 4] = b; + result.elements[3 + 2 * 4] = -1.0f; + result.elements[2 + 3 * 4] = c; + + return result; +} + +// 嵱ǰλýƽ +mat4 mat4::translation(const vec3& translation) +{ + mat4 result(1.0f); + + result.elements[0 + 3 * 4] = translation.x; + result.elements[1 + 3 * 4] = translation.y; + result.elements[2 + 3 * 4] = translation.z; + + return result; +} + +// ѵ3 ; Ŀǰڵǰϵԭתת +mat4 mat4::rotation(float angle, const vec3& axis) +{ + mat4 result(1.0f); + + float r = toRadians(angle); + float c = cos(r); + float s = sin(r); + + float omc = 1.0f - c; + + float x = axis.x; + float y = axis.y; + float z = axis.z; + + result.elements[0 + 0 * 4] = x * omc + c; + result.elements[1 + 0 * 4] = y * x * omc + z * s; + result.elements[2 + 0 * 4] = x * z * omc - y * s; + + result.elements[0 + 1 * 4] = x * y * omc - z * s; + result.elements[1 + 1 * 4] = y * omc + c; + result.elements[2 + 1 * 4] = y * z * omc + x * s; + + result.elements[0 + 2 * 4] = x * z * omc + y * s; + result.elements[1 + 2 * 4] = y * z * omc - x * s; + result.elements[2 + 2 * 4] = z * omc + c; + + return result; +} + +// Ŀǰڵǰϵԭķ +mat4 mat4::scale(const vec3& scale) +{ + mat4 result(1.0f); + + result.elements[0 + 0 * 4] = scale.x; + result.elements[1 + 1 * 4] = scale.y; + result.elements[2 + 2 * 4] = scale.z; + + return result; +} + +mat4 mat4::operator*=(const mat4& other) +{ + return multiply(other); + +} + +mat4 operator*(mat4 left, const mat4& right) +{ + return left.multiply(right); +} + diff --git "a/nb15110\350\260\255\351\224\246\345\277\227/ogl-framework/Src/Tools/maths/mat4.h" "b/nb15110\350\260\255\351\224\246\345\277\227/ogl-framework/Src/Tools/maths/mat4.h" new file mode 100644 index 0000000..099250f --- /dev/null +++ "b/nb15110\350\260\255\351\224\246\345\277\227/ogl-framework/Src/Tools/maths/mat4.h" @@ -0,0 +1,57 @@ +/* +* author : ̷־ +* email : apanoo@126.com +* time : 2015 12 09 +*/ +#ifndef __MAT4_H__ +#define __MAT4_H__ + +#include "vec3.h" +#include "vec4.h" +#include "mathUtils.h" + +struct mat4 +{ + union // 4 * 16 ֽ == 4 * 4 * 4 ֽelementsÿĸԪ൱ھһ + { + float elements[4 * 4]; + vec4 columns[4]; + }; + + mat4(); + mat4(float diagonal); + + // getColum + vec4 getCloum(int index) + { + index *= 4; + return vec4(elements[index + 1], elements[index + 2], elements[index + 3], elements[index + 4]); + } + + // + mat4& multiply(const mat4& other); + + // λ + static mat4 identity(); + + // + static mat4 orthographic(float left, float right, float bottom, float top, float near, float far); + + // ͸Ӿ + static mat4 perspective(float fov, float aspectRatio, float near, float far); + + // ƽƾ + static mat4 translation(const vec3& translation); + + // ת + static mat4 rotation(float angle, const vec3& axis); + + // + static mat4 scale(const vec3& scale); + + // + friend mat4 operator*(mat4 left, const mat4& right); + mat4 operator*=(const mat4& other); +}; + +#endif // !__MAT4_H__ diff --git "a/nb15110\350\260\255\351\224\246\345\277\227/ogl-framework/Src/Tools/maths/maths.h" "b/nb15110\350\260\255\351\224\246\345\277\227/ogl-framework/Src/Tools/maths/maths.h" new file mode 100644 index 0000000..8f9ebdb --- /dev/null +++ "b/nb15110\350\260\255\351\224\246\345\277\227/ogl-framework/Src/Tools/maths/maths.h" @@ -0,0 +1,21 @@ +/* +* author : ̷־ +* email : apanoo@126.com +* time : 2015 12 09 +*/ + +/* + * ʹѧͷļ + */ + +#pragma once + +#ifndef __MATH_H__ +#define __MATH_H__ + +#include "vec2.h" +#include "vec3.h" +#include "vec4.h" +#include "mat4.h" + +#endif // !__MATH_H__ \ No newline at end of file diff --git "a/nb15110\350\260\255\351\224\246\345\277\227/ogl-framework/Src/Tools/maths/vec2.cpp" "b/nb15110\350\260\255\351\224\246\345\277\227/ogl-framework/Src/Tools/maths/vec2.cpp" new file mode 100644 index 0000000..c90cc33 --- /dev/null +++ "b/nb15110\350\260\255\351\224\246\345\277\227/ogl-framework/Src/Tools/maths/vec2.cpp" @@ -0,0 +1,101 @@ +#include "vec2.h" + +vec2::vec2() +{ + x = 0.0f; + y = 0.0f; +} + +vec2::vec2(const float& x, const float& y) +{ + this->x = x; + this->y = y; +} + +vec2& vec2::add(const vec2& other) +{ + x += other.x; + y += other.y; + + return *this; +} + +vec2& vec2::subtract(const vec2& other) +{ + x -= other.x; + y -= other.y; + + return *this; +} +vec2& vec2::mutiply(const vec2& other) +{ + x *= other.x; + y *= other.y; + + return *this; +} +vec2& vec2::divide(const vec2& other) +{ + x /= other.x; + y /= other.y; + + return *this; +} + +// +vec2 operator+(vec2 left, const vec2& right) +{ + return left.add(right); +} + +vec2 operator-(vec2 left, const vec2& right) +{ + return left.subtract(right); +} + +vec2 operator*(vec2 left, const vec2& right) +{ + return left.mutiply(right); +} + +vec2 operator/(vec2 left, const vec2& right) +{ + return left.divide(right); +} + +bool vec2::operator==(const vec2& other) +{ + return x == other.x && y == other.y; +} + +bool vec2::operator!=(const vec2& other) +{ + return !(*this == other); +} + +vec2& vec2::operator+=(const vec2& other) +{ + return add(other); +} + +vec2& vec2::operator-=(const vec2& other) +{ + return subtract(other); +} + +vec2& vec2::operator*=(const vec2& other) +{ + return mutiply(other); +} + +vec2& vec2::operator/=(const vec2& other) +{ + return divide(other); +} + + +std::ostream& operator<<(std::ostream& stream, const vec2& vector) +{ + stream << "vec2:(" << vector.x << "," << vector.y << ")"; + return stream; +} \ No newline at end of file diff --git "a/nb15110\350\260\255\351\224\246\345\277\227/ogl-framework/Src/Tools/maths/vec2.h" "b/nb15110\350\260\255\351\224\246\345\277\227/ogl-framework/Src/Tools/maths/vec2.h" new file mode 100644 index 0000000..6d8c61e --- /dev/null +++ "b/nb15110\350\260\255\351\224\246\345\277\227/ogl-framework/Src/Tools/maths/vec2.h" @@ -0,0 +1,40 @@ +/* +* author : ̷־ +* email : apanoo@126.com +* time : 2015 12 09 +*/ + +#ifndef __VEC2_H__ +#define __VEC2_H__ + +#include + +struct vec2 +{ + float x, y; + vec2(); + vec2(const float &x, const float &y); + + vec2& add(const vec2& other); + vec2& subtract(const vec2& other); + vec2& mutiply(const vec2& other); + vec2& divide(const vec2& other); + + // + friend vec2 operator+(vec2 left, const vec2& right); + friend vec2 operator-(vec2 left, const vec2& right); + friend vec2 operator*(vec2 left, const vec2& right); + friend vec2 operator/(vec2 left, const vec2& right); + + bool operator==(const vec2& other); + bool operator!=(const vec2& other); + + vec2& operator+=(const vec2& other); + vec2& operator-=(const vec2& other); + vec2& operator*=(const vec2& other); + vec2& operator/=(const vec2& other); + + friend std::ostream& operator<<(std::ostream& stream, const vec2& vector); +}; + +#endif // !__VEC2_H__ \ No newline at end of file diff --git "a/nb15110\350\260\255\351\224\246\345\277\227/ogl-framework/Src/Tools/maths/vec3.cpp" "b/nb15110\350\260\255\351\224\246\345\277\227/ogl-framework/Src/Tools/maths/vec3.cpp" new file mode 100644 index 0000000..bc8904a --- /dev/null +++ "b/nb15110\350\260\255\351\224\246\345\277\227/ogl-framework/Src/Tools/maths/vec3.cpp" @@ -0,0 +1,106 @@ +#include "vec3.h" + +vec3::vec3() +{ + x = 0.0f; + y = 0.0f; +} + +vec3::vec3(const float& x, const float& y, const float &z) +{ + this->x = x; + this->y = y; + this->z = z; +} + +vec3& vec3::add(const vec3& other) +{ + x += other.x; + y += other.y; + z += other.z; + + return *this; +} + +vec3& vec3::subtract(const vec3& other) +{ + x -= other.x; + y -= other.y; + z -= other.z; + + return *this; +} +vec3& vec3::mutiply(const vec3& other) +{ + x *= other.x; + y *= other.y; + z *= other.z; + + return *this; +} +vec3& vec3::divide(const vec3& other) +{ + x /= other.x; + y /= other.y; + z /= other.z; + + return *this; +} + +// +vec3 operator+(vec3 left, const vec3& right) +{ + return left.add(right); +} + +vec3 operator-(vec3 left, const vec3& right) +{ + return left.subtract(right); +} + +vec3 operator*(vec3 left, const vec3& right) +{ + return left.mutiply(right); +} + +vec3 operator/(vec3 left, const vec3& right) +{ + return left.divide(right); +} + +bool vec3::operator==(const vec3& other) +{ + return x == other.x && y == other.y && z == other.z; +} + +bool vec3::operator!=(const vec3& other) +{ + return !(*this == other); +} + +vec3& vec3::operator+=(const vec3& other) +{ + return add(other); +} + +vec3& vec3::operator-=(const vec3& other) +{ + return subtract(other); +} + +vec3& vec3::operator*=(const vec3& other) +{ + return mutiply(other); +} + +vec3& vec3::operator/=(const vec3& other) +{ + return divide(other); +} + + +std::ostream& operator<<(std::ostream& stream, const vec3& vector) +{ + stream << "vec3:(" << vector.x << "," << vector.y << "," << vector.z << ")"; + return stream; +} \ No newline at end of file diff --git "a/nb15110\350\260\255\351\224\246\345\277\227/ogl-framework/Src/Tools/maths/vec3.h" "b/nb15110\350\260\255\351\224\246\345\277\227/ogl-framework/Src/Tools/maths/vec3.h" new file mode 100644 index 0000000..8cd39a6 --- /dev/null +++ "b/nb15110\350\260\255\351\224\246\345\277\227/ogl-framework/Src/Tools/maths/vec3.h" @@ -0,0 +1,40 @@ +/* +* author : ̷־ +* email : apanoo@126.com +* time : 2015 12 09 +*/ + +#ifndef __VEC3_H__ +#define __VEC3_H__ + +#include + +struct vec3 +{ + float x, y, z; + vec3(); + vec3(const float &x, const float &y, const float &z); + + vec3& add(const vec3& other); + vec3& subtract(const vec3& other); + vec3& mutiply(const vec3& other); + vec3& divide(const vec3& other); + + // + friend vec3 operator+(vec3 left, const vec3& right); + friend vec3 operator-(vec3 left, const vec3& right); + friend vec3 operator*(vec3 left, const vec3& right); + friend vec3 operator/(vec3 left, const vec3& right); + + bool operator==(const vec3& other); + bool operator!=(const vec3& other); + + vec3& operator+=(const vec3& other); + vec3& operator-=(const vec3& other); + vec3& operator*=(const vec3& other); + vec3& operator/=(const vec3& other); + + friend std::ostream& operator<<(std::ostream& stream, const vec3& vector); +}; + +#endif // !__VEC3_H__ \ No newline at end of file diff --git "a/nb15110\350\260\255\351\224\246\345\277\227/ogl-framework/Src/Tools/maths/vec4.cpp" "b/nb15110\350\260\255\351\224\246\345\277\227/ogl-framework/Src/Tools/maths/vec4.cpp" new file mode 100644 index 0000000..41f637f --- /dev/null +++ "b/nb15110\350\260\255\351\224\246\345\277\227/ogl-framework/Src/Tools/maths/vec4.cpp" @@ -0,0 +1,105 @@ +#include "vec4.h" + +vec4::vec4(const float& x, const float& y, const float &z, const float &w) +{ + this->x = x; + this->y = y; + this->z = z; + this->w = w; +} + +vec4& vec4::add(const vec4& other) +{ + x += other.x; + y += other.y; + z += other.z; + w += other.w; + + return *this; +} + +vec4& vec4::subtract(const vec4& other) +{ + x -= other.x; + y -= other.y; + z -= other.z; + w -= other.w; + + return *this; +} +vec4& vec4::mutiply(const vec4& other) +{ + x *= other.x; + y *= other.y; + z *= other.z; + w *= other.w; + + return *this; +} +vec4& vec4::divide(const vec4& other) +{ + x /= other.x; + y /= other.y; + z /= other.z; + w /= other.w; + + return *this; +} + +// +vec4 operator+(vec4 left, const vec4& right) +{ + return left.add(right); +} + +vec4 operator-(vec4 left, const vec4& right) +{ + return left.subtract(right); +} + +vec4 operator*(vec4 left, const vec4& right) +{ + return left.mutiply(right); +} + +vec4 operator/(vec4 left, const vec4& right) +{ + return left.divide(right); +} + +bool vec4::operator==(const vec4& other) +{ + return x == other.x && y == other.y && z == other.z && w == other.w; +} + +bool vec4::operator!=(const vec4& other) +{ + return !(*this == other); +} + +vec4& vec4::operator+=(const vec4& other) +{ + return add(other); +} + +vec4& vec4::operator-=(const vec4& other) +{ + return subtract(other); +} + +vec4& vec4::operator*=(const vec4& other) +{ + return mutiply(other); +} + +vec4& vec4::operator/=(const vec4& other) +{ + return divide(other); +} + + +std::ostream& operator<<(std::ostream& stream, const vec4& vector) +{ + stream << "vec4:(" << vector.x << "," << vector.y << "," << vector.z << "," << vector.w << ")"; + return stream; +} \ No newline at end of file diff --git "a/nb15110\350\260\255\351\224\246\345\277\227/ogl-framework/Src/Tools/maths/vec4.h" "b/nb15110\350\260\255\351\224\246\345\277\227/ogl-framework/Src/Tools/maths/vec4.h" new file mode 100644 index 0000000..6c27c14 --- /dev/null +++ "b/nb15110\350\260\255\351\224\246\345\277\227/ogl-framework/Src/Tools/maths/vec4.h" @@ -0,0 +1,41 @@ +/* +* author : ̷־ +* email : apanoo@126.com +* time : 2015 12 09 +*/ + +#ifndef __VEC4_H__ +#define __VEC4_H__ + +#include + +struct vec4 +{ + float x, y, z, w; + + vec4() = default; // mat4У + vec4(const float &x, const float &y, const float &z, const float &w); + + vec4& add(const vec4& other); + vec4& subtract(const vec4& other); + vec4& mutiply(const vec4& other); + vec4& divide(const vec4& other); + + // + friend vec4 operator+(vec4 left, const vec4& right); + friend vec4 operator-(vec4 left, const vec4& right); + friend vec4 operator*(vec4 left, const vec4& right); + friend vec4 operator/(vec4 left, const vec4& right); + + bool operator==(const vec4& other); + bool operator!=(const vec4& other); + + vec4& operator+=(const vec4& other); + vec4& operator-=(const vec4& other); + vec4& operator*=(const vec4& other); + vec4& operator/=(const vec4& other); + + friend std::ostream& operator<<(std::ostream& stream, const vec4& vector); +}; + +#endif // !__VEC4_H__ \ No newline at end of file diff --git "a/nb15110\350\260\255\351\224\246\345\277\227/ogl-framework/Src/homework1/homework1.vcxproj" "b/nb15110\350\260\255\351\224\246\345\277\227/ogl-framework/Src/homework1/homework1.vcxproj" index f7537b4..b0dafc4 100644 --- "a/nb15110\350\260\255\351\224\246\345\277\227/ogl-framework/Src/homework1/homework1.vcxproj" +++ "b/nb15110\350\260\255\351\224\246\345\277\227/ogl-framework/Src/homework1/homework1.vcxproj" @@ -96,6 +96,10 @@ + + + + @@ -109,6 +113,13 @@ + + + + + + + diff --git "a/nb15110\350\260\255\351\224\246\345\277\227/ogl-framework/Src/homework1/homework1.vcxproj.filters" "b/nb15110\350\260\255\351\224\246\345\277\227/ogl-framework/Src/homework1/homework1.vcxproj.filters" index 62a44cd..7779c2f 100644 --- "a/nb15110\350\260\255\351\224\246\345\277\227/ogl-framework/Src/homework1/homework1.vcxproj.filters" +++ "b/nb15110\350\260\255\351\224\246\345\277\227/ogl-framework/Src/homework1/homework1.vcxproj.filters" @@ -25,6 +25,18 @@ System + + Tools\Maths + + + Tools\Maths + + + Tools\Maths + + + Tools\Maths + @@ -54,6 +66,27 @@ System + + Tools\Maths + + + Tools\Maths + + + Tools\Maths + + + Tools\Maths + + + Tools\Maths + + + Tools\Maths + + + Tools\FileTools + @@ -74,5 +107,11 @@ {3dcff4c8-12ce-459f-a875-1211ae8948dd} + + {b3a1da4c-8fa4-4393-8194-c3513a59df10} + + + {ab9fa1ef-2346-4465-af6f-47a85a49a95f} + \ No newline at end of file diff --git "a/nb15110\350\260\255\351\224\246\345\277\227/ogl-framework/Src/homework2/AppDelegate.cpp" "b/nb15110\350\260\255\351\224\246\345\277\227/ogl-framework/Src/homework2/AppDelegate.cpp" new file mode 100644 index 0000000..06e0d07 --- /dev/null +++ "b/nb15110\350\260\255\351\224\246\345\277\227/ogl-framework/Src/homework2/AppDelegate.cpp" @@ -0,0 +1,39 @@ +#include "AppDelegate.h" +#include "MainScene.h" + +AppDelegate::AppDelegate() +{ + +} + +AppDelegate::~AppDelegate() +{ + +} + +BOOL AppDelegate::InitInstance() +{ + MainScene *pMainWnd = new MainScene(); + if (NULL == pMainWnd) + { + return 0; // ڴʧ + } + m_pMainWnd = (LPVOID)pMainWnd; // + + pMainWnd->CreateGlWnd("ogl-framework", 200, 100, 800, 600); + pMainWnd->ShowWindow(SW_SHOW); + pMainWnd->UpdateWindow(); + + return TRUE; +} + +BOOL AppDelegate::ExitInstance() +{ + if (m_pMainWnd) + { + delete m_pMainWnd; // ˳ǰ + m_pMainWnd = NULL; + } + return true; +} + diff --git "a/nb15110\350\260\255\351\224\246\345\277\227/ogl-framework/Src/homework2/AppDelegate.h" "b/nb15110\350\260\255\351\224\246\345\277\227/ogl-framework/Src/homework2/AppDelegate.h" new file mode 100644 index 0000000..539b75b --- /dev/null +++ "b/nb15110\350\260\255\351\224\246\345\277\227/ogl-framework/Src/homework2/AppDelegate.h" @@ -0,0 +1,17 @@ +#pragma once +#include "../GLWindow/QWndApp.h" + +class AppDelegate : public QWndApp +{ +public: + AppDelegate(); + ~AppDelegate(); + +public: + + // ʼ + virtual BOOL InitInstance(); + + // ˳ + virtual BOOL ExitInstance(); +}; \ No newline at end of file diff --git "a/nb15110\350\260\255\351\224\246\345\277\227/ogl-framework/Src/homework2/Main.cpp" "b/nb15110\350\260\255\351\224\246\345\277\227/ogl-framework/Src/homework2/Main.cpp" new file mode 100644 index 0000000..439ae6f --- /dev/null +++ "b/nb15110\350\260\255\351\224\246\345\277\227/ogl-framework/Src/homework2/Main.cpp" @@ -0,0 +1,30 @@ +/************************************************************************/ +/* time : 2015-12-02 */ +/* author : ̷־ */ +/* email : apanoo@126.com */ +/************************************************************************/ + +#define WIN32_LEAN_AND_MEAN +#include "Main.h" +#include "AppDelegate.h" + +// link to libraries +// #pragma comment(lib, "opengl32.lib") +// #pragma comment(lib, "glu32.lib") +// #pragma comment(lib, "winmm.lib") + +// WinMain ں + +AppDelegate theApp; // ȫֱ + +int WINAPI WinMain( HINSTANCE hInstance, // Instance + HINSTANCE hPrevInstance, // Previous Instance + LPSTR lpCmdLine, // Command line params + int nShowCmd) // Window show state +{ + theApp.InitInstance(); + theApp.run(); + theApp.ExitInstance(); + + return true; +} diff --git "a/nb15110\350\260\255\351\224\246\345\277\227/ogl-framework/Src/homework2/Main.h" "b/nb15110\350\260\255\351\224\246\345\277\227/ogl-framework/Src/homework2/Main.h" new file mode 100644 index 0000000..9036915 --- /dev/null +++ "b/nb15110\350\260\255\351\224\246\345\277\227/ogl-framework/Src/homework2/Main.h" @@ -0,0 +1,12 @@ +#pragma once +#ifndef MAIN_H +#define MAIN_H +#include "../GLWindow/stdafx.h" + +//WinMain +int WINAPI WinMain( HINSTANCE hInstance, //Instance + HINSTANCE hPrevInstance, //Previous Instance + LPSTR lpCmdLine, //Command line params + int nShowCmd); //Window show state + +#endif //MAIN_H \ No newline at end of file diff --git "a/nb15110\350\260\255\351\224\246\345\277\227/ogl-framework/Src/homework2/MainScene.cpp" "b/nb15110\350\260\255\351\224\246\345\277\227/ogl-framework/Src/homework2/MainScene.cpp" new file mode 100644 index 0000000..8c4ab85 --- /dev/null +++ "b/nb15110\350\260\255\351\224\246\345\277\227/ogl-framework/Src/homework2/MainScene.cpp" @@ -0,0 +1,211 @@ +#include "MainScene.h" +#include "../Tools/TextureLoader/TextureLoader.h" // texture +#include "../Tools/ScreenShot/ScreenShot.h" // Ļͼ +#include +#include "../System/System.h" // ϵͳ + +// ڴ˴û: +GLfloat ep_Angle; // תĽǶ +GLfloat es_Angle; // תĽǶ +GLfloat mp_Angle; // תĽǶ +GLfloat ms_Angle; // תĽǶ +GLuint texture[4]; // 飬 +GLUquadricObj *quadric; // +GLfloat angle_Z; // ǿתǶ + +GLfloat LightAmbient[] = { 1.0f, 1.0f, 1.0f, 0.0f }; // 廷ɫ +GLfloat LightDiffuse[] = { 1.0f, 1.0f, 1.0f, 0.0f }; // ɫ +GLfloat LightPosition[] = { 0.0f, 0.0f, 0.0f, 1.0f }; // Դλ + +GLfloat fogColor[4] = { 0.5f, 0.0f, 0.5f, 1.0f }; // ɫΪɫ + +MainScene::MainScene() +{ + m_texLoader = NULL; + m_screenShot = NULL; +} + +MainScene::~MainScene() +{ + if ( NULL != m_texLoader) { + m_texLoader = NULL; + } + if (NULL != m_screenShot) { + m_screenShot = NULL; + } +} + +BOOL MainScene::initGL(GLvoid) +{ + /////////////////////////////ʼ//////////////////////////////////////// + texture[0] = m_texLoader->LoadBitMapTexture("Data/1.bmp"); + texture[1] = m_texLoader->LoadBitMapTexture("Data/2.bmp"); + texture[2] = m_texLoader->LoadBitMapTexture("Data/3.bmp"); + texture[3] = m_texLoader->LoadBitMapTexture("Data/4.bmp"); + + // ڴ˴ʼƳ + glClearColor(0.0f, 0.0f, 0.0f, 0.5f); // Ϊɫ + glClearDepth(1.0f); // Ȼ + glDepthFunc(GL_LEQUAL); // ѡȲԷʽ + glEnable(GL_DEPTH_TEST); // Ȳ + glShadeModel(GL_SMOOTH); // ƽʽ + glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // ϸ͸Ӽ + + glEnable(GL_TEXTURE_2D); // 2Dӳ + + glLightfv(GL_LIGHT1, GL_AMBIENT, LightAmbient); // û + glLightfv(GL_LIGHT1, GL_DIFFUSE, LightDiffuse); // + + quadric = gluNewQuadric(); // һָ + gluQuadricTexture(quadric, GLU_TRUE); // + gluQuadricDrawStyle(quadric, GLU_FILL); // + glEnable(GL_LIGHTING); // 򿪹 + glEnable(GL_LIGHT1); // 򿪹Դ1 + // ĸֲ + glFogi(GL_FOG_MODE, GL_LINEAR); // + glFogfv(GL_FOG_COLOR, fogColor); // ɫ + glFogf(GL_FOG_DENSITY, 0.6f); // Ũ + glHint(GL_FOG_HINT, GL_DONT_CARE); // Ⱦʽ + glFogf(GL_FOG_START, 1.0f); // Ŀʼ + glFogf(GL_FOG_END, 30.0f); // ֹ + glEnable(GL_FOG); // + + ////////////////////////////////////////////////////////////////////////// + return TRUE; +} + +// ʾģʽ +void MainScene::ViewMode() +{ + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + + // ͸ģʽ + // ˴widthheightҪǿתΪfloat ΪGLWindowн䶨ΪGLsizeiǿתopenglӿ + gluPerspective(45.0f, (float)this->GetWidth() / (float)this->GetHeight(), 0.01f, 100.0f); + + // λ + //gluLookAt(0, 0, 1, 0, 0, 0, 0, 1, 0); + + // ѡģʽ۲ + glMatrixMode(GL_MODELVIEW); + + glLoadIdentity(); +} + +BOOL MainScene::DrawGL(GLvoid) +{ + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // ɫȻ + glLoadIdentity(); // õǰ + /////////////////////////////////////////////////////////////////////// + + glTranslatef(0.0f, 0.0f, -5.0f); // ϵĻ8.0f + glRotatef(10, 1.0f, 0.0f, 0.0f); // ϵxת10 + glEnable(GL_LIGHT0); // 򿪹Դ0 + /**********************************Ʊǿ*********************************************/ + + glPushMatrix(); // ǰģ;ջ + glTranslatef(-10.0f, 3.0f, 0.0f); + glRotatef(angle_Z, 0.0f, 0.0f, 1.0f); + glEnable(GL_TEXTURE_2D); + glBindTexture(GL_TEXTURE_2D, texture[1]); // ǿ + glBegin(GL_QUADS); + glNormal3f(0.0f, 0.0f, 1.0f); + glTexCoord2f(0.0f, 0.0f); glVertex3f(-20.0f, -20.0f, -5.0f); + glTexCoord2f(6.0f, 0.0f); glVertex3f(20.0f, -20.0f, -5.0f); + glTexCoord2f(6.0f, 6.0f); glVertex3f(20.0f, 20.0f, -5.0f); + glTexCoord2f(0.0f, 6.0f); glVertex3f(-20.0f, 20.0f, -5.0f); + glEnd(); + glPopMatrix(); // ǰģ;ջ + + /**********************************̫*************************************************/ + glBindTexture(GL_TEXTURE_2D, texture[2]); // + glEnable(GL_BLEND); // + glDisable(GL_DEPTH_TEST); // رȲ + //̫ + glDisable(GL_LIGHTING); // رչ + glBlendFunc(GL_SRC_ALPHA, GL_ONE); // Դalphaֵͨİ͸Ϻ + glColor4f(1.0f, 1.0f, 1.0f, 0.4f); // RGBAֵ + glBegin(GL_QUADS); + glNormal3f(0.0f, 0.0f, 1.0f); + glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 0.0f); + glTexCoord2f(1.0f, 0.0f); glVertex3f(1.0f, -1.0f, 0.0f); + glTexCoord2f(1.0f, 1.0f); glVertex3f(1.0f, 1.0f, 0.0f); + glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, 0.0f); + glEnd(); + glDisable(GL_BLEND); // رջ + glEnable(GL_DEPTH_TEST); + + glDisable(GL_TEXTURE_2D); // ر + + glEnable(GL_LIGHTING); // + glLightfv(GL_LIGHT1, GL_POSITION, LightPosition); // ùԴ1ĵǰλ + + gluSphere(quadric, 0.3f, 32, 32); // ̫ + + /**********************************Ƶ*************************************************/ + + glDisable(GL_LIGHT0); + glRotatef(ep_Angle, 0.0f, 1.0f, 0.0f); // ϵYתep_AngleǶ Ƶת + glRotatef(-90.0f, 1.0f, 0.0f, 0.0f); // ϵXת-90 + + glEnable(GL_TEXTURE_2D); // + + glTranslatef(2.0f, 0.0f, 0.0f); // ϵ2.0f + glBindTexture(GL_TEXTURE_2D, texture[0]); // + + glPushMatrix(); // ǰģͼջ + glRotatef(es_Angle, 0.0f, 0.0f, 1.0f); // ϵZתes_AngleǶ Ƶת + gluSphere(quadric, 0.2f, 32, 32); // + glPopMatrix(); // ǰģͼջ + + /***********************************************************************************/ + + glRotatef(mp_Angle, 0.0f, 0.0f, 1.0f); // ϵZתmp_AngleǶ ת + glBindTexture(GL_TEXTURE_2D, texture[3]); // + glTranslatef(0.5f, 0.0f, 0.0f); // 0.5f + glRotatef(ms_Angle, 0.0f, 0.0f, 1.0f); // ϵZתms_AngleǶ ת + gluSphere(quadric, 0.05, 32, 32); // + + // + ep_Angle += 2.0f; + mp_Angle += 5.0f; + es_Angle += 5.0f; + ms_Angle += 5.0f; + + angle_Z += 0.1f; + + ////////////////////////////////////////////////////////////////////////// + glFlush(); // ˢGL + return TRUE; +} + +BOOL MainScene::UpdateGL(GLvoid) +{ + /* + * ϵͳӳ˵ + * F1->F12 : VK_F1 -> VK_F12 + * num 0 -> 9 : VK_NUMPAD0 -> VK_NUMPAD9 + * char A -> Z : 0x41 -> ... + */ + + if (keyDown(VK_F1)) // F1 Ϊbmp + { + m_screenShot->GrabScreen(this); + } + + return TRUE; +} + +GLvoid MainScene::DestroyGL(GLvoid) +{ + +} + +HRESULT MainScene::OnMouseMove(WPARAM wParam, LPARAM lParam) +{ + double x = LOWORD(lParam); // x + double y = HIWORD(lParam); // y + + return true; +} diff --git "a/nb15110\350\260\255\351\224\246\345\277\227/ogl-framework/Src/homework2/MainScene.h" "b/nb15110\350\260\255\351\224\246\345\277\227/ogl-framework/Src/homework2/MainScene.h" new file mode 100644 index 0000000..3a12b3e --- /dev/null +++ "b/nb15110\350\260\255\351\224\246\345\277\227/ogl-framework/Src/homework2/MainScene.h" @@ -0,0 +1,33 @@ +#pragma once +#include "../GLWindow/GLWindow.h" // ʹGLWindow win32װĴӦ + +class TextureLoader; +class ScreenShot; + +class MainScene : public GLWindow +{ +public: + MainScene(); + ~MainScene(); + + // ʼ + BOOL initGL(GLvoid) override; + + // ʾģʽ ģʽʱ + void ViewMode() override; + + // Ƴ + BOOL DrawGL(GLvoid) override; + + // ´Ϣ + BOOL UpdateGL(GLvoid) override; + + // openglǰĴ + GLvoid DestroyGL(GLvoid) override; + + HRESULT OnMouseMove(WPARAM wParam, LPARAM lParam) override; + +private: + TextureLoader *m_texLoader; // ع + ScreenShot *m_screenShot; // Ļͼ +}; \ No newline at end of file diff --git "a/nb15110\350\260\255\351\224\246\345\277\227/ogl-framework/Src/homework2/homework2.vcxproj" "b/nb15110\350\260\255\351\224\246\345\277\227/ogl-framework/Src/homework2/homework2.vcxproj" new file mode 100644 index 0000000..e3b7648 --- /dev/null +++ "b/nb15110\350\260\255\351\224\246\345\277\227/ogl-framework/Src/homework2/homework2.vcxproj" @@ -0,0 +1,135 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + + {DE1FCBB6-BB55-4255-9145-033CD946122C} + Win32Proj + opengl + homework2 + 8.1 + + + + Application + true + v140 + MultiByte + + + Application + false + v140 + true + MultiByte + + + + + + + + + + + + + true + ../../Bin/Debug/ + ../../Objs/Debug/ + $(ProjectName)_d + ../../SDKs/freeglut/include;../../SDKs/glew/include;../../SDKs/glm;../../SDKs/GLTools/include;$(IncludePath) + ../../SDKs/freeglut/lib;../../SDKs/glew/lib;../../SDKs/GLTools/lib;$(LibraryPath) + + + false + ../../Bin/Release/ + ../../Objs/Release/ + ../../SDKs/freeglut/include;../../SDKs/glew/include;../../SDKs/glm;../../SDKs/GLTools/include;$(IncludePath) + ../../SDKs/freeglut/lib;../../SDKs/glew/lib;../../SDKs/GLTools/lib;$(LibraryPath) + + + + NotUsing + Level3 + Disabled + WIN32;_DEBUG;_WINDOWS;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + true + MultiThreadedDebug + + + Windows + true + ../../Bin/Debug/$(ProjectName)_d.exe + + + + + Level3 + NotUsing + MaxSpeed + true + true + WIN32;NDEBUG;_WINDOWS;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + true + MultiThreaded + + + Windows + true + true + true + ../../Bin/Release/$(ProjectName).exe + /SAFESEH:NO %(AdditionalOptions) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git "a/nb15110\350\260\255\351\224\246\345\277\227/ogl-framework/Src/homework2/homework2.vcxproj.filters" "b/nb15110\350\260\255\351\224\246\345\277\227/ogl-framework/Src/homework2/homework2.vcxproj.filters" new file mode 100644 index 0000000..ca6ec02 --- /dev/null +++ "b/nb15110\350\260\255\351\224\246\345\277\227/ogl-framework/Src/homework2/homework2.vcxproj.filters" @@ -0,0 +1,123 @@ + + + + + + GLWindow + + + GLWindow + + + GLWindow + + + + + Tools\TextureLoader + + + Tools\ShaderLoader + + + Tools\ScreenShot + + + System + + + Tools\Maths + + + Tools\Maths + + + Tools\Maths + + + Tools\Maths + + + Tools\ShaderLoader + + + + + + GLWindow + + + GLWindow + + + GLWindow + + + GLWindow + + + + + Tools\TextureLoader + + + Tools\ShaderLoader + + + Tools\ScreenShot + + + System + + + Tools\FileTool + + + Tools\Maths + + + Tools\Maths + + + Tools\Maths + + + Tools\Maths + + + Tools\Maths + + + Tools\Maths + + + Tools\ShaderLoader + + + + + {2833157b-f410-43f6-9b8e-f5855d63d967} + + + {0c92387b-6d4a-4f27-8783-8b1a5b1b2efa} + + + {198450a3-f01f-4843-af64-d0e4bbbc3bb6} + + + {8d91dda6-90f9-410e-8f8c-3c89f6b7ee1e} + + + {05119733-8ef0-475a-9e88-08526182f77d} + + + {3dcff4c8-12ce-459f-a875-1211ae8948dd} + + + {7cabefd5-fb3f-40f7-a2b8-6d84c2e624a2} + + + {a7d0cd4b-4dfb-4d95-b424-21ee1216e0cc} + + + \ No newline at end of file diff --git "a/nb15110\350\260\255\351\224\246\345\277\227/ogl-framework/Src/homework2/homework2.vcxproj.user" "b/nb15110\350\260\255\351\224\246\345\277\227/ogl-framework/Src/homework2/homework2.vcxproj.user" new file mode 100644 index 0000000..9684b66 --- /dev/null +++ "b/nb15110\350\260\255\351\224\246\345\277\227/ogl-framework/Src/homework2/homework2.vcxproj.user" @@ -0,0 +1,11 @@ + + + + ../../Bin/Debug/ + WindowsLocalDebugger + + + ../../Bin/Release/ + WindowsLocalDebugger + + \ No newline at end of file diff --git "a/nb15110\350\260\255\351\224\246\345\277\227/ogl-framework/ogl-framewprk.sln" "b/nb15110\350\260\255\351\224\246\345\277\227/ogl-framework/ogl-framewprk.sln" index e122ad0..4cee53b 100644 --- "a/nb15110\350\260\255\351\224\246\345\277\227/ogl-framework/ogl-framewprk.sln" +++ "b/nb15110\350\260\255\351\224\246\345\277\227/ogl-framework/ogl-framewprk.sln" @@ -1,7 +1,11 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 2012 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "opengl", "Src\homework1\homework1.vcxproj", "{36CF9C0B-14F5-47BC-AFD4-2C9A010128F1}" +# Visual Studio 14 +VisualStudioVersion = 14.0.23107.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "homework1", "Src\homework1\homework1.vcxproj", "{36CF9C0B-14F5-47BC-AFD4-2C9A010128F1}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "homework2", "Src\homework2\homework2.vcxproj", "{DE1FCBB6-BB55-4255-9145-033CD946122C}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -13,6 +17,10 @@ Global {36CF9C0B-14F5-47BC-AFD4-2C9A010128F1}.Debug|Win32.Build.0 = Debug|Win32 {36CF9C0B-14F5-47BC-AFD4-2C9A010128F1}.Release|Win32.ActiveCfg = Release|Win32 {36CF9C0B-14F5-47BC-AFD4-2C9A010128F1}.Release|Win32.Build.0 = Release|Win32 + {DE1FCBB6-BB55-4255-9145-033CD946122C}.Debug|Win32.ActiveCfg = Debug|Win32 + {DE1FCBB6-BB55-4255-9145-033CD946122C}.Debug|Win32.Build.0 = Debug|Win32 + {DE1FCBB6-BB55-4255-9145-033CD946122C}.Release|Win32.ActiveCfg = Release|Win32 + {DE1FCBB6-BB55-4255-9145-033CD946122C}.Release|Win32.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git "a/nb15110\350\260\255\351\224\246\345\277\227/ogl-framework/pic/pic2.gif" "b/nb15110\350\260\255\351\224\246\345\277\227/ogl-framework/pic/pic2.gif" new file mode 100644 index 0000000..6b94392 Binary files /dev/null and "b/nb15110\350\260\255\351\224\246\345\277\227/ogl-framework/pic/pic2.gif" differ