create a GLProgram for object shader

This commit is contained in:
Josh Holtrop 2012-09-07 23:27:15 -04:00
parent 99a9e2b67f
commit bf8ee88cd2
3 changed files with 30 additions and 1 deletions

View File

@ -7,6 +7,7 @@
#include "Client.h" #include "Client.h"
#include <stdio.h> #include <stdio.h>
#include <iostream> #include <iostream>
#include "ccfs.h"
using namespace std; using namespace std;
@ -35,6 +36,22 @@ Client::Client(bool fullscreen, bool compatibility_context,
m_player->x = 1250; m_player->x = 1250;
m_player->y = 1000; m_player->y = 1000;
m_player->direction = M_PI_2; m_player->direction = M_PI_2;
GLProgram::AttributeBinding obj_attrib_bindings[] = {
{0, "pos"},
{1, "normal"},
{0, NULL}
};
const char *v_source = (const char *) CFS.get_file("shaders/obj_v.glsl", NULL);
const char *f_source = (const char *) CFS.get_file("shaders/obj_f.glsl", NULL);
if (v_source == NULL || f_source == NULL)
{
cerr << "Error loading shader sources" << endl;
}
else if (!m_obj_program.create(v_source, f_source,
obj_attrib_bindings))
{
cerr << "Error creating obj program" << endl;
}
} }
void Client::run() void Client::run()

View File

@ -6,6 +6,7 @@
#include "refptr.h" #include "refptr.h"
#include "Map.h" #include "Map.h"
#include "Player.h" #include "Player.h"
#include "GLProgram.h"
class Client class Client
{ {
@ -25,6 +26,7 @@ class Client
refptr<Player> m_player; refptr<Player> m_player;
int m_width; int m_width;
int m_height; int m_height;
GLProgram m_obj_program;
}; };
#endif #endif

View File

@ -35,7 +35,17 @@ bool GLShader::create(GLenum shaderType, const char *source)
} }
GLint log_length; GLint log_length;
cerr << "Error compiling shader" << endl; cerr << "Error compiling ";
switch (shaderType)
{
case GL_VERTEX_SHADER:
cerr << "vertex";
break;
case GL_FRAGMENT_SHADER:
cerr << "fragment";
break;
}
cerr << " shader" << endl;
glGetShaderiv(m_id, GL_INFO_LOG_LENGTH, &log_length); glGetShaderiv(m_id, GL_INFO_LOG_LENGTH, &log_length);
if (log_length > 0) if (log_length > 0)
{ {