Add GLM library to deal with matrices
This commit is contained in:
parent
3c4d7ac6a9
commit
38262dee11
3 changed files with 73 additions and 4 deletions
|
@ -8,3 +8,6 @@ file (GLOB sources *.cpp)
|
||||||
|
|
||||||
add_executable (matabstrix ${sources})
|
add_executable (matabstrix ${sources})
|
||||||
set (CMAKE_EXECUTABLE_SUFFIX ".html")
|
set (CMAKE_EXECUTABLE_SUFFIX ".html")
|
||||||
|
|
||||||
|
find_package (GLM REQUIRED)
|
||||||
|
include_directories (${GLM_INCLUDE_DIRS})
|
||||||
|
|
63
cmake/Modules/FindGLM.cmake
Normal file
63
cmake/Modules/FindGLM.cmake
Normal file
|
@ -0,0 +1,63 @@
|
||||||
|
# FindGLM - attempts to locate the glm matrix/vector library.
|
||||||
|
#
|
||||||
|
# This module defines the following variables (on success):
|
||||||
|
# GLM_INCLUDE_DIRS - where to find glm/glm.hpp
|
||||||
|
# GLM_FOUND - if the library was successfully located
|
||||||
|
#
|
||||||
|
# It is trying a few standard installation locations, but can be customized
|
||||||
|
# with the following variables:
|
||||||
|
# GLM_ROOT_DIR - root directory of a glm installation
|
||||||
|
# Headers are expected to be found in either:
|
||||||
|
# <GLM_ROOT_DIR>/glm/glm.hpp OR
|
||||||
|
# <GLM_ROOT_DIR>/include/glm/glm.hpp
|
||||||
|
# This variable can either be a cmake or environment
|
||||||
|
# variable. Note however that changing the value
|
||||||
|
# of the environment varible will NOT result in
|
||||||
|
# re-running the header search and therefore NOT
|
||||||
|
# adjust the variables set by this module.
|
||||||
|
|
||||||
|
#=============================================================================
|
||||||
|
# Copyright 2012 Carsten Neumann
|
||||||
|
#
|
||||||
|
# Distributed under the OSI-approved BSD License (the "License");
|
||||||
|
# see accompanying file Copyright.txt for details.
|
||||||
|
#
|
||||||
|
# This software is distributed WITHOUT ANY WARRANTY; without even the
|
||||||
|
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
# See the License for more information.
|
||||||
|
#=============================================================================
|
||||||
|
# (To distribute this file outside of CMake, substitute the full
|
||||||
|
# License text for the above reference.)
|
||||||
|
|
||||||
|
# default search dirs
|
||||||
|
SET(_glm_HEADER_SEARCH_DIRS
|
||||||
|
"/usr/include"
|
||||||
|
"/usr/local/include")
|
||||||
|
|
||||||
|
# check environment variable
|
||||||
|
SET(_glm_ENV_ROOT_DIR "$ENV{GLM_ROOT_DIR}")
|
||||||
|
|
||||||
|
IF(NOT GLM_ROOT_DIR AND _glm_ENV_ROOT_DIR)
|
||||||
|
SET(GLM_ROOT_DIR "${_glm_ENV_ROOT_DIR}")
|
||||||
|
ENDIF(NOT GLM_ROOT_DIR AND _glm_ENV_ROOT_DIR)
|
||||||
|
|
||||||
|
# put user specified location at beginning of search
|
||||||
|
IF(GLM_ROOT_DIR)
|
||||||
|
SET(_glm_HEADER_SEARCH_DIRS "${GLM_ROOT_DIR}"
|
||||||
|
"${GLM_ROOT_DIR}/include"
|
||||||
|
${_glm_HEADER_SEARCH_DIRS})
|
||||||
|
ENDIF(GLM_ROOT_DIR)
|
||||||
|
|
||||||
|
# locate header
|
||||||
|
FIND_PATH(GLM_INCLUDE_DIR "glm/glm.hpp"
|
||||||
|
PATHS ${_glm_HEADER_SEARCH_DIRS})
|
||||||
|
|
||||||
|
INCLUDE(FindPackageHandleStandardArgs)
|
||||||
|
FIND_PACKAGE_HANDLE_STANDARD_ARGS(GLM DEFAULT_MSG
|
||||||
|
GLM_INCLUDE_DIR)
|
||||||
|
|
||||||
|
IF(GLM_FOUND)
|
||||||
|
SET(GLM_INCLUDE_DIRS "${GLM_INCLUDE_DIR}")
|
||||||
|
|
||||||
|
MESSAGE(STATUS "GLM_INCLUDE_DIR = ${GLM_INCLUDE_DIR}")
|
||||||
|
ENDIF(GLM_FOUND)
|
11
main.cpp
11
main.cpp
|
@ -1,5 +1,8 @@
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
|
||||||
|
#include <glm/glm.hpp>
|
||||||
|
#include <glm/gtc/type_ptr.hpp>
|
||||||
|
|
||||||
#include <GL/glew.h>
|
#include <GL/glew.h>
|
||||||
#include <GL/glfw.h>
|
#include <GL/glfw.h>
|
||||||
|
|
||||||
|
@ -16,12 +19,12 @@ static void iterate();
|
||||||
|
|
||||||
static GLuint view_matrix;
|
static GLuint view_matrix;
|
||||||
|
|
||||||
static GLfloat view[] = {
|
static glm::mat4 view(
|
||||||
1.0, 0.0, 0.0, 0.0,
|
1.0, 0.0, 0.0, 0.0,
|
||||||
0.0, 1.0, 0.0, 0.0,
|
0.0, 1.0, 0.0, 0.0,
|
||||||
0.0, 0.0, 1.0, 0.0,
|
0.0, 0.0, 1.0, 0.0,
|
||||||
0.0 ,0.0, 0.0, 1.0,
|
0.0, 0.0, 0.0, 1.0
|
||||||
};
|
);
|
||||||
|
|
||||||
static const char vertex_shader_source[] = \
|
static const char vertex_shader_source[] = \
|
||||||
"attribute vec4 position; \n"\
|
"attribute vec4 position; \n"\
|
||||||
|
@ -100,7 +103,7 @@ void iterate()
|
||||||
{
|
{
|
||||||
glClear(GL_COLOR_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
|
|
||||||
glUniformMatrix4fv(view_matrix, 1, GL_FALSE, view);
|
glUniformMatrix4fv(view_matrix, 1, GL_FALSE, glm::value_ptr(view));
|
||||||
|
|
||||||
glDrawArrays(GL_TRIANGLES, 0, 3);
|
glDrawArrays(GL_TRIANGLES, 0, 3);
|
||||||
|
|
||||||
|
|
Reference in a new issue