set transform shader matrix
This commit is contained in:
parent
b6a5821fae
commit
5adc26b089
@ -3,6 +3,6 @@
|
|||||||
env = Environment(LIBS = ['GL'])
|
env = Environment(LIBS = ['GL'])
|
||||||
env.ParseConfig('sdl-config --cflags --libs')
|
env.ParseConfig('sdl-config --cflags --libs')
|
||||||
|
|
||||||
sources = Glob('*.cc')
|
sources = [Glob('*.cc'), Glob('../glslUtil/*.c')]
|
||||||
|
|
||||||
env.Program('test', sources)
|
env.Program('test', sources)
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
#include <GL/gl.h>
|
#include <GL/gl.h>
|
||||||
#include <GL/glu.h>
|
#include <GL/glu.h>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include "../glslUtil/glslUtil.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
@ -27,11 +28,12 @@ const GLushort indices[] = {
|
|||||||
0, 1, 2, 3, 4, 5
|
0, 1, 2, 3, 4, 5
|
||||||
};
|
};
|
||||||
GLuint program, vs, fs, data_vbo, index_vbo;
|
GLuint program, vs, fs, data_vbo, index_vbo;
|
||||||
GLint ambient_loc, diffuse_loc, specular_loc, shininess_loc;
|
GLint ambient_loc, diffuse_loc, specular_loc, shininess_loc, transform_loc;
|
||||||
enum Locations {
|
enum Locations {
|
||||||
LOC_POSITION,
|
LOC_POSITION,
|
||||||
LOC_NORMAL
|
LOC_NORMAL
|
||||||
};
|
};
|
||||||
|
static guMatrix4x4 transform;
|
||||||
|
|
||||||
char * loadFile(const char *fname)
|
char * loadFile(const char *fname)
|
||||||
{
|
{
|
||||||
@ -131,15 +133,14 @@ bool init(int width, int height)
|
|||||||
glClearColor (0.0, 0.0, 0.0, 0.0);
|
glClearColor (0.0, 0.0, 0.0, 0.0);
|
||||||
glEnable(GL_DEPTH_TEST);
|
glEnable(GL_DEPTH_TEST);
|
||||||
glViewport(0, 0, WIDTH, HEIGHT);
|
glViewport(0, 0, WIDTH, HEIGHT);
|
||||||
glMatrixMode(GL_PROJECTION);
|
guMatrixLoadIdentity(&transform);
|
||||||
glLoadIdentity();
|
|
||||||
float near = 0.1;
|
float near = 0.1;
|
||||||
float scale = near * 0.577 * 2;
|
float scale = near * 0.577 * 2;
|
||||||
float aspect = (float)width / (float)height;
|
float aspect = (float)width / (float)height;
|
||||||
glFrustum(-aspect * scale, aspect * scale, -scale, scale, near, 1000.0);
|
guMatrixFrustum(&transform, -aspect * scale, aspect * scale, -scale, scale, near, 1000.0);
|
||||||
glMatrixMode(GL_MODELVIEW);
|
// guPerspective(&transform, 60, (float)width / (float)height, 0.1, 1000.0);
|
||||||
glLoadIdentity();
|
guMatrixTranslate(&transform, 0, 0, -1);
|
||||||
glTranslatef(0, 0, -1);
|
// guMatrixTranslate(&transform, 1, 0.3, 0);
|
||||||
|
|
||||||
vs = makeShader(GL_VERTEX_SHADER, "v_shader.glsl");
|
vs = makeShader(GL_VERTEX_SHADER, "v_shader.glsl");
|
||||||
fs = makeShader(GL_FRAGMENT_SHADER, "f_shader.glsl");
|
fs = makeShader(GL_FRAGMENT_SHADER, "f_shader.glsl");
|
||||||
@ -174,12 +175,14 @@ bool init(int width, int height)
|
|||||||
diffuse_loc = glGetUniformLocation(program, "diffuse");
|
diffuse_loc = glGetUniformLocation(program, "diffuse");
|
||||||
specular_loc = glGetUniformLocation(program, "specular");
|
specular_loc = glGetUniformLocation(program, "specular");
|
||||||
shininess_loc = glGetUniformLocation(program, "shininess");
|
shininess_loc = glGetUniformLocation(program, "shininess");
|
||||||
|
transform_loc = glGetUniformLocation(program, "transform");
|
||||||
|
|
||||||
glUseProgram(program);
|
glUseProgram(program);
|
||||||
glUniform4f(ambient_loc, 0.2, 0.2, 0.2, 1.0);
|
glUniform4f(ambient_loc, 0.2, 0.2, 0.2, 1.0);
|
||||||
glUniform4f(diffuse_loc, 1.0, 0.6, 0.0, 1.0);
|
glUniform4f(diffuse_loc, 1.0, 0.6, 0.0, 1.0);
|
||||||
glUniform4f(specular_loc, 1.0, 1.0, 1.0, 1.0);
|
glUniform4f(specular_loc, 1.0, 1.0, 1.0, 1.0);
|
||||||
glUniform1f(shininess_loc, 85.0);
|
glUniform1f(shininess_loc, 85.0);
|
||||||
|
glUniformMatrix4fv(transform_loc, 1, GL_TRUE, &transform[0][0]);
|
||||||
|
|
||||||
data_vbo = makeBuffer(GL_ARRAY_BUFFER, data, sizeof(data));
|
data_vbo = makeBuffer(GL_ARRAY_BUFFER, data, sizeof(data));
|
||||||
index_vbo = makeBuffer(GL_ELEMENT_ARRAY_BUFFER, indices, sizeof(indices));
|
index_vbo = makeBuffer(GL_ELEMENT_ARRAY_BUFFER, indices, sizeof(indices));
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
|
|
||||||
|
uniform mat4 transform;
|
||||||
|
|
||||||
attribute vec3 pos;
|
attribute vec3 pos;
|
||||||
attribute vec3 normal;
|
attribute vec3 normal;
|
||||||
|
|
||||||
@ -7,7 +9,7 @@ varying vec3 normal_i;
|
|||||||
|
|
||||||
void main(void)
|
void main(void)
|
||||||
{
|
{
|
||||||
gl_Position = gl_ModelViewProjectionMatrix * vec4(pos, 1);
|
gl_Position = transform * vec4(pos, 1);
|
||||||
pos_i = vec3(gl_Position.x, gl_Position.y, gl_Position.z);
|
pos_i = vec3(gl_Position.x, gl_Position.y, gl_Position.z);
|
||||||
normal_i = gl_NormalMatrix * normal;
|
normal_i = vec3(transform * vec4(normal, 0.0));
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user