Updates VS project. Replaced snprintf with std::ostringstream in Program::attachTexture. Added RenderCamera functionality for orientation and position. Much more to be added, but likely need to implement the State machine so majority of the program logic is complete.
parent
082828465c
commit
b7e867fbf2
|
@ -57,7 +57,8 @@
|
|||
</Link>
|
||||
<PostBuildEvent>
|
||||
<Command>xcopy /d /y "..\..\..\..\Dev\glew-1.11.0\bin\Release\Win32\glew32.dll" "$(OutDir)"
|
||||
xcopy /d /y "..\..\..\..\Dev\SDL2-2.0.3\lib\x86\SDL2.dll" "$(OutDir)"</Command>
|
||||
xcopy /d /y "..\..\..\..\Dev\SDL2-2.0.3\lib\x86\SDL2.dll" "$(OutDir)"
|
||||
xcopy /s /e /d /y "..\..\data" "$(OutDir)data\"</Command>
|
||||
</PostBuildEvent>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
|
@ -79,6 +80,7 @@ xcopy /d /y "..\..\..\..\Dev\SDL2-2.0.3\lib\x86\SDL2.dll" "$(OutDir)"</Command>
|
|||
<ClCompile Include="..\..\src\main.cpp" />
|
||||
<ClCompile Include="..\..\src\Mat4.cpp" />
|
||||
<ClCompile Include="..\..\src\Mesh.cpp" />
|
||||
<ClCompile Include="..\..\src\Program.cpp" />
|
||||
<ClCompile Include="..\..\src\RenderCamera.cpp" />
|
||||
<ClCompile Include="..\..\src\RenderObject.cpp" />
|
||||
<ClCompile Include="..\..\src\RenderScene.cpp" />
|
||||
|
@ -95,12 +97,15 @@ xcopy /d /y "..\..\..\..\Dev\SDL2-2.0.3\lib\x86\SDL2.dll" "$(OutDir)"</Command>
|
|||
<None Include="..\..\..\..\Dev\SDL2-2.0.3\lib\x86\SDL2.dll">
|
||||
<DeploymentContent>true</DeploymentContent>
|
||||
</None>
|
||||
<None Include="..\..\data\shaders\fb_fs.glsl" />
|
||||
<None Include="..\..\data\shaders\fb_vs.glsl" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\..\src\common.hpp" />
|
||||
<ClInclude Include="..\..\src\Log.hpp" />
|
||||
<ClInclude Include="..\..\src\Mat4.hpp" />
|
||||
<ClInclude Include="..\..\src\Mesh.hpp" />
|
||||
<ClInclude Include="..\..\src\Program.hpp" />
|
||||
<ClInclude Include="..\..\src\RenderCamera.hpp" />
|
||||
<ClInclude Include="..\..\src\RenderObject.hpp" />
|
||||
<ClInclude Include="..\..\src\RenderScene.hpp" />
|
||||
|
|
|
@ -19,6 +19,12 @@
|
|||
<Filter Include="Classes">
|
||||
<UniqueIdentifier>{e0e1a725-2ac7-4b9b-bc04-51850b74c96c}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Build Copy\data">
|
||||
<UniqueIdentifier>{09c9659c-b804-479c-a003-fd38125fb2b1}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Build Copy\data\shaders">
|
||||
<UniqueIdentifier>{67fb4fb5-992e-4ddb-9696-d1c4d51d1204}</UniqueIdentifier>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\..\src\main.cpp">
|
||||
|
@ -51,6 +57,9 @@
|
|||
<ClCompile Include="..\..\src\Mesh.cpp">
|
||||
<Filter>Classes</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\Program.cpp">
|
||||
<Filter>Classes</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="..\..\..\..\Dev\SDL2-2.0.3\lib\x86\SDL2.dll">
|
||||
|
@ -59,6 +68,12 @@
|
|||
<None Include="..\..\..\..\Dev\glew-1.11.0\bin\Release\Win32\glew32.dll">
|
||||
<Filter>Build Copy</Filter>
|
||||
</None>
|
||||
<None Include="..\..\data\shaders\fb_fs.glsl">
|
||||
<Filter>Build Copy\data\shaders</Filter>
|
||||
</None>
|
||||
<None Include="..\..\data\shaders\fb_vs.glsl">
|
||||
<Filter>Build Copy\data\shaders</Filter>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\..\src\RenderCamera.hpp">
|
||||
|
@ -91,5 +106,8 @@
|
|||
<ClInclude Include="..\..\src\Mesh.hpp">
|
||||
<Filter>Classes</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\Program.hpp">
|
||||
<Filter>Classes</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
|
@ -7,6 +7,7 @@ loading, creating, and compiling OpenGL programs.
|
|||
#include "Program.hpp"
|
||||
#include "Log.hpp"
|
||||
#include <fstream>
|
||||
#include <sstream> // ostringstream
|
||||
#include <stdexcept> // oor
|
||||
/* ======== Constructors and Destructors ======== */
|
||||
Program::Program() {
|
||||
|
@ -46,7 +47,7 @@ int Program::doCompile() {
|
|||
// Let's first create our program
|
||||
program = glCreateProgram();
|
||||
// Now we compile our shaders
|
||||
int i;
|
||||
size_t i;
|
||||
for (i = 0; i < shader_prog.size(); i++) {
|
||||
GLuint shader = shader_prog.at(i);
|
||||
glCompileShader(shader);
|
||||
|
@ -78,14 +79,7 @@ GLuint Program::getProgram() {
|
|||
//
|
||||
int Program::activate() {
|
||||
glUseProgram(program);
|
||||
// TODO: foreach texture, activate and bind
|
||||
/*glActiveTexture(r_texture++);
|
||||
glBindTexture(GL_TEXTURE_2D, r_view->getFBO());
|
||||
// FIXME: not sure how else this should be done!
|
||||
char texture_str[7];
|
||||
snprintf(texture_str, 7, "tex%d", r_texture);
|
||||
glUniform1i(glGetUniformLocation(program->getProgram(), texture_str), r_texture-1);*/
|
||||
int i;
|
||||
size_t i;
|
||||
for (i = 0; i < shader_textures.size(); i++) {
|
||||
glActiveTexture(GL_TEXTURE0 + shader_textures[i].index);
|
||||
glBindTexture(GL_TEXTURE_2D, shader_textures[i].texture);
|
||||
|
@ -95,7 +89,7 @@ int Program::activate() {
|
|||
}
|
||||
int Program::deactivate() {
|
||||
// TODO: deactivate textures
|
||||
int i;
|
||||
size_t i;
|
||||
for (i = 0; i < shader_textures.size(); i++) {
|
||||
// ?? FIXME
|
||||
}
|
||||
|
@ -111,13 +105,13 @@ int Program::doClean() {
|
|||
// Textures can be "inserted" into a Program via the following function. The texture index position corresponds to an OpenGL texture position as well as the GLSL uniform that matches "tex"+"1-99" (e.g., "tex1").
|
||||
int Program::attachTexture(GLuint index, GLuint texture) {
|
||||
if (texture == 0) return 1;
|
||||
char texture_str[7];
|
||||
snprintf(texture_str, 7, "tex%d", index);
|
||||
|
||||
std::ostringstream texture_str;
|
||||
texture_str << "tex" << index;
|
||||
|
||||
Texture tex;
|
||||
tex.index = index;
|
||||
tex.texture = texture;
|
||||
tex.location = glGetUniformLocation(program, texture_str);
|
||||
tex.location = glGetUniformLocation(program, texture_str.str().c_str());
|
||||
|
||||
// Insert it onto the textures record for later usage
|
||||
shader_textures.insert(shader_textures.begin()+index, tex);
|
||||
|
|
|
@ -4,19 +4,84 @@ RenderCamera
|
|||
This header file defines the RenderCamera class.
|
||||
================================================================ */
|
||||
#include "RenderCamera.hpp"
|
||||
#include <math.h> // fminf, M_PI
|
||||
#ifndef fminf // Just for the winderps
|
||||
#define fminf(a,b) (a) < (b) ? (a) : (b)
|
||||
#endif
|
||||
/* ======== Constructors and Destructors ======== */
|
||||
RenderCamera::RenderCamera() {
|
||||
fov_ratio = 0.75f;
|
||||
near = 0.1f;
|
||||
far = 512.0f;
|
||||
pitch = yaw = 0;
|
||||
render_mode = 0;
|
||||
flags = 0;
|
||||
width = height = 1;
|
||||
render_view = NULL;
|
||||
}
|
||||
RenderCamera::~RenderCamera() {
|
||||
}
|
||||
/* ======== Update functions ======== */
|
||||
void RenderCamera::updateProjection(int width_, int height_) {
|
||||
width = width_;
|
||||
height = height_;
|
||||
GLfloat wf, hf;
|
||||
GLfloat ratio_xy, ratio_x, ratio_y;
|
||||
GLfloat ratio_zw, ratio_z, ratio_w;
|
||||
|
||||
wf = (GLfloat)width;
|
||||
hf = (GLfloat)height;
|
||||
ratio_xy = fminf(wf, hf) * 1.0f/fov_ratio;
|
||||
ratio_x = ratio_xy / wf;
|
||||
ratio_y = ratio_xy / hf;
|
||||
ratio_zw = 1.0f / (far - near);
|
||||
ratio_z = (near + far) * ratio_zw;
|
||||
ratio_w = -2.0f * near * far * ratio_zw;
|
||||
|
||||
p_matrix[0] = Vec4(ratio_x, 0.0f, 0.0f, 0.0f);
|
||||
p_matrix[1] = Vec4(0.0f, ratio_y, 0.0f, 0.0f);
|
||||
p_matrix[2] = Vec4(0.0f, 0.0f, ratio_z, 1.0f);
|
||||
p_matrix[3] = Vec4(0.0f, 0.0f, ratio_w, 0.0f);
|
||||
}
|
||||
void RenderCamera::doRefresh() {
|
||||
if (!(flags & DIRTY)) return;
|
||||
float c_p = cos(pitch * M_PI / 180.0f);
|
||||
float s_p = sin(pitch * M_PI / 180.0f);
|
||||
float c_y = cos(yaw * M_PI / 180.0f);
|
||||
float s_y = sin(yaw * M_PI / 180.0f);
|
||||
|
||||
Vec3 x(c_y, 0, -s_y);
|
||||
Vec3 y(s_y*s_p, c_p, c_y * s_p);
|
||||
Vec3 z(s_y * c_p, -s_p, c_p * c_y);
|
||||
|
||||
mv_matrix = Mat4(
|
||||
Vec4(x.x, y.x, z.x, 0.0f),
|
||||
Vec4(x.y, y.y, z.y, 0.0f),
|
||||
Vec4(x.z, y.z, z.z, 0.0f),
|
||||
Vec4(-x.dotProduct(position), -y.dotProduct(position), -z.dotProduct(position), 1.0f)
|
||||
);
|
||||
flags &= ~DIRTY;
|
||||
}
|
||||
/* ======== Setter functions ======== */
|
||||
int RenderCamera::setRenderView(RenderView *rv) {
|
||||
if (rv == NULL) return 1;
|
||||
render_view = rv;
|
||||
return 0;
|
||||
}
|
||||
void RenderCamera::setPosition(float x, float y, float z) {
|
||||
position.x = x;
|
||||
position.y = y;
|
||||
position.z = z;
|
||||
flags |= DIRTY;
|
||||
}
|
||||
void RenderCamera::setPitch(float pitch_) {
|
||||
pitch = pitch_;
|
||||
flags |= DIRTY;
|
||||
}
|
||||
void RenderCamera::setYaw(float yaw_) {
|
||||
yaw = yaw_;
|
||||
flags |= DIRTY;
|
||||
}
|
||||
/* ======== Getter functions ======== */
|
||||
RenderView* RenderCamera::getRenderView() {
|
||||
return render_view;
|
||||
|
|
|
@ -12,15 +12,29 @@ RenderScene and outputs all data to the friend class, RenderView.
|
|||
#include "common.hpp"
|
||||
#include "RenderView.hpp"
|
||||
#include "Vec.hpp"
|
||||
#include "Mat4.hpp"
|
||||
#define DIRTY (1 << 1)
|
||||
class RenderCamera {
|
||||
public:
|
||||
RenderCamera();
|
||||
~RenderCamera();
|
||||
int setRenderView(RenderView *view);
|
||||
RenderView* getRenderView();
|
||||
void updateProjection(int width, int height);
|
||||
void doRefresh();
|
||||
void setPosition(float x, float y, float z);
|
||||
void setPitch(float pitch);
|
||||
void setYaw(float yaw);
|
||||
private:
|
||||
Vec3 x, y, z; // TODO: replace with quaternion
|
||||
Vec3 position; // The camera's coordinates in 3D space
|
||||
float pitch, yaw; //
|
||||
float fov_ratio;
|
||||
float near, far; // wherever you are
|
||||
int render_mode; // 0 = perspective, 1 = orthogonal
|
||||
RenderView *render_view; // RenderView to render the scene to
|
||||
Mat4 p_matrix; // Our camera's projection matrix
|
||||
Mat4 mv_matrix; // modelview matrix
|
||||
int width, height;
|
||||
int flags;
|
||||
};
|
||||
#endif
|
||||
|
|
|
@ -45,7 +45,7 @@ int RenderScene::renderTo(RenderView *target_view, Program *render_program) {
|
|||
// Use this provided program for rendering. Should refer to a framebuffer shader
|
||||
glUseProgram(render_program->getProgram());
|
||||
// Bind to the provided target view's fbo
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, view->fbo);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, target_view->fbo);
|
||||
// Render each of our camera's framebuffers with the appropriate changes
|
||||
for (camera_it = cameras.begin(), camera_end = cameras.end(); camera_it != camera_end; ++camera_it) {
|
||||
camera = *camera_it;
|
||||
|
|
|
@ -125,13 +125,6 @@ int main(int argc, char *argv[]) {
|
|||
glDrawArrays(GL_TRIANGLES, 0, mesh->vertices.size());
|
||||
// close 'em
|
||||
glDisableVertexAttribArray(program_vp);
|
||||
|
||||
/*glActiveTexture(r_texture++);
|
||||
glBindTexture(GL_TEXTURE_2D, r_view->getFBO());
|
||||
// FIXME: not sure how else this should be done!
|
||||
char texture_str[7];
|
||||
snprintf(texture_str, 7, "tex%d", r_texture);
|
||||
glUniform1i(glGetUniformLocation(program->getProgram(), texture_str), r_texture-1);*/
|
||||
}
|
||||
program->deactivate();
|
||||
|
||||
|
|
Loading…
Reference in New Issue