Added cube model for testing. Shader textures now start at index 0 rather than 1. Things work on iOS now. closeSystem deletes gl context and destroys window - needs to free textures, etc. still. Added testing finger and mouse motion control. Meshes now generate uv buffer object and normals buffer object. RenderCamera now supports rendering in orthogonal as well as perspective. Orthogonal rendering relies on 'size' float, which indicates the vertical 3D units shown on screen. This is, for RtB, equal to 1 meter. Perspective rendering uses fov_angle, which is the vertical field of view angle. This is, default, pi / 4. Screen resizing now works fine on Android - recreated buffer used non gles type. RenderView now uses nearest mag/min filters rather than linear. Added handleAppEvents which is intended to deal with state changes on mobile devices, such as app minimizing. At the moment, core.closeSystem is called when RtB enters the background.
parent
561c33f092
commit
00d0ec1c00
|
@ -24,6 +24,8 @@
|
|||
20517DB91A9C237D00DE49E9 /* checksum.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 20517DB51A9C237D00DE49E9 /* checksum.cpp */; };
|
||||
20517DBA1A9C237D00DE49E9 /* fio.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 20517DB71A9C237D00DE49E9 /* fio.cpp */; };
|
||||
20517E5A1A9D4A0300DE49E9 /* Core.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 20517E581A9D4A0300DE49E9 /* Core.cpp */; };
|
||||
205183891A9DE71F00DE49E9 /* cube.obj in Resources */ = {isa = PBXBuildFile; fileRef = 205183881A9DE71F00DE49E9 /* cube.obj */; };
|
||||
2051838A1A9DE72A00DE49E9 /* cube.obj in Copy Models */ = {isa = PBXBuildFile; fileRef = 205183881A9DE71F00DE49E9 /* cube.obj */; };
|
||||
2056AE551A8A423E00833760 /* Mat4.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2056AE4F1A8A423E00833760 /* Mat4.cpp */; };
|
||||
2056AE561A8A423E00833760 /* RenderObject.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2056AE511A8A423E00833760 /* RenderObject.cpp */; };
|
||||
2056AE571A8A423E00833760 /* Vec.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2056AE531A8A423E00833760 /* Vec.cpp */; };
|
||||
|
@ -51,6 +53,7 @@
|
|||
dstPath = data/models;
|
||||
dstSubfolderSpec = 7;
|
||||
files = (
|
||||
2051838A1A9DE72A00DE49E9 /* cube.obj in Copy Models */,
|
||||
20517CA11A9B40E800DE49E9 /* chest.obj in Copy Models */,
|
||||
);
|
||||
name = "Copy Models";
|
||||
|
@ -149,6 +152,7 @@
|
|||
20517DB81A9C237D00DE49E9 /* fio.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = fio.hpp; path = ../../src/fio.hpp; sourceTree = SOURCE_ROOT; };
|
||||
20517E581A9D4A0300DE49E9 /* Core.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Core.cpp; path = ../../src/Core.cpp; sourceTree = SOURCE_ROOT; };
|
||||
20517E591A9D4A0300DE49E9 /* Core.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = Core.hpp; path = ../../src/Core.hpp; sourceTree = SOURCE_ROOT; };
|
||||
205183881A9DE71F00DE49E9 /* cube.obj */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = cube.obj; path = ../../data/models/cube.obj; sourceTree = SOURCE_ROOT; };
|
||||
2056AE4F1A8A423E00833760 /* Mat4.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Mat4.cpp; path = ../../src/Mat4.cpp; sourceTree = SOURCE_ROOT; };
|
||||
2056AE501A8A423E00833760 /* Mat4.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = Mat4.hpp; path = ../../src/Mat4.hpp; sourceTree = SOURCE_ROOT; };
|
||||
2056AE511A8A423E00833760 /* RenderObject.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = RenderObject.cpp; path = ../../src/RenderObject.cpp; sourceTree = SOURCE_ROOT; };
|
||||
|
@ -302,6 +306,7 @@
|
|||
205723DA1A9B4053001400FA /* models */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
205183881A9DE71F00DE49E9 /* cube.obj */,
|
||||
205723DB1A9B4053001400FA /* chest.obj */,
|
||||
);
|
||||
name = models;
|
||||
|
@ -467,6 +472,7 @@
|
|||
20517D171A9B449200DE49E9 /* default_vs.100.glsl in Resources */,
|
||||
20517D181A9B449200DE49E9 /* fb_fs.100.glsl in Resources */,
|
||||
20517D191A9B449200DE49E9 /* fb_vs.100.glsl in Resources */,
|
||||
205183891A9DE71F00DE49E9 /* cube.obj in Resources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
|
|
@ -12,6 +12,8 @@
|
|||
20517D531A9BFB1B00DE49E9 /* fio.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 20517D511A9BFB1B00DE49E9 /* fio.cpp */; };
|
||||
20517D601A9C083B00DE49E9 /* checksum.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 20517D5E1A9C083B00DE49E9 /* checksum.cpp */; };
|
||||
20517DCE1A9D44DB00DE49E9 /* Core.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 20517DCC1A9D44DB00DE49E9 /* Core.cpp */; };
|
||||
205182A81A9DD62C00DE49E9 /* cube.obj in Resources */ = {isa = PBXBuildFile; fileRef = 205182A71A9DD62C00DE49E9 /* cube.obj */; };
|
||||
205182C01A9DD63E00DE49E9 /* cube.obj in Copy Models */ = {isa = PBXBuildFile; fileRef = 205182A71A9DD62C00DE49E9 /* cube.obj */; };
|
||||
2056AE3C1A8A421500833760 /* Mat4.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2056AE361A8A421500833760 /* Mat4.cpp */; };
|
||||
2056AE3D1A8A421500833760 /* RenderObject.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2056AE381A8A421500833760 /* RenderObject.cpp */; };
|
||||
2056AE3E1A8A421500833760 /* Vec.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2056AE3A1A8A421500833760 /* Vec.cpp */; };
|
||||
|
@ -43,6 +45,7 @@
|
|||
dstPath = data/models;
|
||||
dstSubfolderSpec = 7;
|
||||
files = (
|
||||
205182C01A9DD63E00DE49E9 /* cube.obj in Copy Models */,
|
||||
205723931A9B3ED3001400FA /* chest.obj in Copy Models */,
|
||||
);
|
||||
name = "Copy Models";
|
||||
|
@ -75,6 +78,7 @@
|
|||
20517D5F1A9C083B00DE49E9 /* checksum.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = checksum.hpp; path = ../../src/checksum.hpp; sourceTree = SOURCE_ROOT; };
|
||||
20517DCC1A9D44DB00DE49E9 /* Core.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Core.cpp; path = ../../src/Core.cpp; sourceTree = SOURCE_ROOT; };
|
||||
20517DCD1A9D44DB00DE49E9 /* Core.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = Core.hpp; path = ../../src/Core.hpp; sourceTree = SOURCE_ROOT; };
|
||||
205182A71A9DD62C00DE49E9 /* cube.obj */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = cube.obj; path = models/cube.obj; sourceTree = "<group>"; };
|
||||
2056AE361A8A421500833760 /* Mat4.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Mat4.cpp; path = ../../src/Mat4.cpp; sourceTree = SOURCE_ROOT; };
|
||||
2056AE371A8A421500833760 /* Mat4.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = Mat4.hpp; path = ../../src/Mat4.hpp; sourceTree = SOURCE_ROOT; };
|
||||
2056AE381A8A421500833760 /* RenderObject.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = RenderObject.cpp; path = ../../src/RenderObject.cpp; sourceTree = SOURCE_ROOT; };
|
||||
|
@ -186,6 +190,7 @@
|
|||
205723721A9B3E90001400FA /* models */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
205182A71A9DD62C00DE49E9 /* cube.obj */,
|
||||
205723771A9B3EA3001400FA /* chest.obj */,
|
||||
);
|
||||
name = models;
|
||||
|
@ -327,6 +332,7 @@
|
|||
205723781A9B3EA3001400FA /* chest.obj in Resources */,
|
||||
2057237B1A9B3EB2001400FA /* default_fs.glsl in Resources */,
|
||||
2057237C1A9B3EB2001400FA /* default_vs.glsl in Resources */,
|
||||
205182A81A9DD62C00DE49E9 /* cube.obj in Resources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
# Blender v2.69 (sub 0) OBJ File: ''
|
||||
# www.blender.org
|
||||
o Cube
|
||||
v 1.000000 -1.000000 -1.000000
|
||||
v 1.000000 -1.000000 1.000000
|
||||
v -1.000000 -1.000000 1.000000
|
||||
v -1.000000 -1.000000 -1.000000
|
||||
v 1.000000 1.000000 -0.999999
|
||||
v 0.999999 1.000000 1.000001
|
||||
v -1.000000 1.000000 1.000000
|
||||
v -1.000000 1.000000 -1.000000
|
||||
s off
|
||||
f 1 2 4
|
||||
f 5 8 6
|
||||
f 1 5 2
|
||||
f 2 6 3
|
||||
f 3 7 4
|
||||
f 5 1 8
|
||||
f 2 3 4
|
||||
f 8 7 6
|
||||
f 5 6 2
|
||||
f 6 7 3
|
||||
f 7 8 4
|
||||
f 1 4 8
|
|
@ -3,11 +3,11 @@ precision mediump float;
|
|||
// in
|
||||
varying vec2 UV;
|
||||
|
||||
uniform sampler2D tex1;
|
||||
uniform sampler2D tex0;
|
||||
|
||||
//
|
||||
void main() {
|
||||
gl_FragColor = vec4(texture2D(tex1, UV).xyz, 1.0);
|
||||
gl_FragColor = vec4(texture2D(tex0, UV).xyz, 1.0);
|
||||
//gl_FragColor = vec4(UV.xy, 1.0, 1.0);
|
||||
//gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0);
|
||||
}
|
||||
|
|
|
@ -2,11 +2,11 @@
|
|||
// in
|
||||
varying vec2 UV;
|
||||
|
||||
uniform sampler2D tex1;
|
||||
uniform sampler2D tex0;
|
||||
|
||||
//
|
||||
void main() {
|
||||
gl_FragColor = vec4(texture2D(tex1, UV).xyz, 1.0);
|
||||
gl_FragColor = vec4(texture2D(tex0, UV).xyz, 1.0);
|
||||
//gl_FragColor = vec4(UV.xy, 1.0, 1.0);
|
||||
//gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0);
|
||||
}
|
||||
|
|
60
src/Core.cpp
60
src/Core.cpp
|
@ -29,6 +29,8 @@ int Core::initSystem() {
|
|||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
|
||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
|
||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);
|
||||
// iOS readme says to set this if we're redrawing each frame
|
||||
SDL_GL_SetAttribute(SDL_GL_RETAINED_BACKING, 1);
|
||||
#endif
|
||||
// Get our maximum windowed display size and use it
|
||||
SDL_DisplayMode display_mode;
|
||||
|
@ -134,31 +136,47 @@ int Core::initSystem() {
|
|||
RenderCamera *camera = new RenderCamera();
|
||||
camera->setRenderView(new RenderView(v_width, v_height));
|
||||
camera->updateProjection(v_width, v_height);
|
||||
camera->setPitch(75.0f);
|
||||
camera->setPosition(0, 35, -10);
|
||||
camera->setPitch(80.0f);
|
||||
camera->setPosition(0, 30, 0);
|
||||
camera->doRefresh();
|
||||
|
||||
scene->addCamera(camera);
|
||||
|
||||
program->attachTexture(0, camera->getRenderView()->getFBO());
|
||||
program->attachTexture(0, camera->getRenderView()->getTex());
|
||||
|
||||
(camera->getRenderView()->setProgram(program));
|
||||
|
||||
RenderObject *objerct = new RenderObject();
|
||||
Mesh *mersh = new Mesh("data/models/chest.obj");
|
||||
mersh->buildMesh();
|
||||
objerct->setMesh(mersh);
|
||||
RenderSet *sert = new RenderSet();
|
||||
sert->setProgram(program_model);
|
||||
|
||||
RenderObject *objerct = new RenderObject();
|
||||
Mesh *mersh = new Mesh("data/models/cube.obj");
|
||||
mersh->buildMesh();
|
||||
objerct->setMesh(mersh);
|
||||
sert->addObject(objerct);
|
||||
|
||||
objerct = new RenderObject();
|
||||
mersh = new Mesh("data/models/chest.obj");
|
||||
mersh->buildMesh();
|
||||
objerct->setMesh(mersh);
|
||||
objerct->setTranslation(-5.0f, 0.0f, 5.0f);
|
||||
objerct->calcMatrix();
|
||||
sert->addObject(objerct);
|
||||
|
||||
scene->addSet(sert);
|
||||
|
||||
glClearColor(1.0f, 1.0f, 1.0f, 0.0f);
|
||||
glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
|
||||
flags |= IS_RUNNING;
|
||||
return 0;
|
||||
}
|
||||
int Core::closeSystem() {
|
||||
LOG(LOG_INFO) << FUNC_NAME << ": adios!";
|
||||
delete scene;
|
||||
// TODO: delete scene should delete rendercameras, renderviews, rendersets, and renderobjects.
|
||||
// TODO: delete meshes loaded (assets) as well
|
||||
SDL_GL_DeleteContext(v_context);
|
||||
SDL_DestroyWindow(v_window);
|
||||
SDL_Quit();
|
||||
return 0;
|
||||
}
|
||||
|
@ -173,6 +191,7 @@ void Core::doProcess() {
|
|||
if (event.window.event == SDL_WINDOWEVENT_RESIZED) {
|
||||
v_width = event.window.data1;
|
||||
v_height = event.window.data2;
|
||||
LOG(LOG_INFO) << "Resized to " << v_width << "x" << v_height;
|
||||
RenderCamera *r_camera;
|
||||
RenderView *r_view;
|
||||
std::vector<RenderCamera*>::iterator camera_it, camera_end;
|
||||
|
@ -183,6 +202,30 @@ void Core::doProcess() {
|
|||
r_view->setView(v_width, v_height);
|
||||
}
|
||||
}
|
||||
} else if (event.type == SDL_FINGERMOTION) {
|
||||
LOG(LOG_INFO) << "finger: " << event.tfinger.pressure << " " << event.tfinger.x << "x" << event.tfinger.y << " " << event.tfinger.dx << "x" << event.tfinger.dy;
|
||||
RenderCamera *camera = scene->getCamera(1);
|
||||
Vec3 camera_pos = camera->getPosition();
|
||||
float x = event.tfinger.dx * v_width/16;
|
||||
float y = event.tfinger.dy * v_height/16;
|
||||
camera->setPosition(camera_pos.x-x, camera_pos.y, camera_pos.z+y);
|
||||
camera->doRefresh();
|
||||
} else if (event.type == SDL_MOUSEMOTION) {
|
||||
if (event.motion.which == SDL_TOUCH_MOUSEID) continue;
|
||||
LOG(LOG_INFO) << "mouse motion: " << event.motion.xrel << "x" << event.motion.yrel << " ";
|
||||
RenderCamera *camera = scene->getCamera(1);
|
||||
Vec3 camera_pos = camera->getPosition();
|
||||
float x = ((float)event.motion.x-(v_width/2)) / camera->getSize();
|
||||
float y = ((float)event.motion.y-(v_height/2)) / camera->getSize();
|
||||
camera->setPosition(-x, camera_pos.y, y);
|
||||
camera->doRefresh();
|
||||
} else if (event.type == SDL_MOUSEBUTTONDOWN) {
|
||||
RenderCamera *camera = scene->getCamera(1);
|
||||
if (event.button.button == SDL_BUTTON_LEFT) {
|
||||
camera->setMode(0);
|
||||
} else {
|
||||
camera->setMode(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
doRender();
|
||||
|
@ -202,7 +245,6 @@ void Core::doRender() {
|
|||
r_camera = *camera_it;
|
||||
if ((r_view = r_camera->getRenderView()) == NULL) continue;
|
||||
if ((r_program = r_view->getProgram()) == NULL) continue;
|
||||
// FIXME: iOS doesn't like enabling the view's program - black screen if enabled.
|
||||
r_program->activate();
|
||||
GLuint program_p = r_program->getProgram();
|
||||
GLuint program_vp = glGetAttribLocation(program_p, "vp");
|
||||
|
|
|
@ -235,6 +235,8 @@ int Mesh::buildMesh() {
|
|||
}
|
||||
int Mesh::destroyMesh() {
|
||||
glDeleteBuffers(1, &vbo);
|
||||
glDeleteBuffers(1, &uvbo);
|
||||
glDeleteBuffers(1, &nbo);
|
||||
//glDeleteVertexArrays(1, &vao);
|
||||
flags &= ~MESH_BUILT;
|
||||
return 0;
|
||||
|
|
|
@ -115,6 +115,7 @@ int Program::attachTexture(GLuint index, GLuint texture) {
|
|||
tex.index = index;
|
||||
tex.texture = texture;
|
||||
tex.location = glGetUniformLocation(program, texture_str.str().c_str());
|
||||
LOG(LOG_INFO) << "attached " << texture << " as " << texture_str.str().c_str() << " to " << tex.location;
|
||||
|
||||
// Insert it onto the textures record for later usage
|
||||
shader_textures.insert(shader_textures.begin()+index, tex);
|
||||
|
|
|
@ -4,13 +4,18 @@ RenderCamera
|
|||
This header file defines the RenderCamera class.
|
||||
================================================================ */
|
||||
#include "RenderCamera.hpp"
|
||||
#include "Log.hpp"
|
||||
#include <math.h> // fminf, M_PI
|
||||
#define PI 3.1415926535897932384626433832795
|
||||
#define PI_OVER_180 0.017453292519943295769236907684886
|
||||
#define PI_OVER_360 0.0087266462599716478846184538424431
|
||||
#ifndef fminf // Just for the winderps
|
||||
#define fminf(a,b) (a) < (b) ? (a) : (b)
|
||||
#endif
|
||||
/* ======== Constructors and Destructors ======== */
|
||||
RenderCamera::RenderCamera() {
|
||||
fov_ratio = 0.75f;
|
||||
fov_angle = M_PI / 4.0f;
|
||||
size = 40.0f; // Default orthogonal size of 40 meters, vertically
|
||||
near = 0.1f;
|
||||
far = 512.0f;
|
||||
pitch = yaw = 0;
|
||||
|
@ -25,23 +30,24 @@ RenderCamera::~RenderCamera() {
|
|||
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);
|
||||
GLfloat wf = (GLfloat)width;
|
||||
GLfloat hf = (GLfloat)height;
|
||||
GLfloat aspect = wf/hf;
|
||||
if (render_mode == 0) {
|
||||
float y = 1.0f / tan((fov_angle)/2.0f);
|
||||
float x = (1/(aspect))*y;
|
||||
p_matrix[0] = Vec4(x, 0.0f, 0.0f, 0.0f);
|
||||
p_matrix[1] = Vec4(0.0f, y, 0.0f, 0.0f);
|
||||
p_matrix[2] = Vec4(0.0f, 0.0f, far/(far-near), 1.0f);
|
||||
p_matrix[3] = Vec4(0.0f, 0.0f, -((far*near)/(far-near)), 0.0f);
|
||||
} else {
|
||||
float x = size * aspect;
|
||||
float y = size;
|
||||
p_matrix[0] = Vec4(2.0f / x, 0.0f, 0.0f, 0.0f);
|
||||
p_matrix[1] = Vec4(0.0f, 2.0f / y, 0.0f, 0.0f);
|
||||
p_matrix[2] = Vec4(0.0f, 0.0f, 1.0f/(far-near), 0.0f);
|
||||
p_matrix[3] = Vec4(0.0f, 0.0f, -near/(far-near), 1.0f);
|
||||
}
|
||||
}
|
||||
void RenderCamera::doRefresh() {
|
||||
if (!(flags & DIRTY)) return;
|
||||
|
@ -63,6 +69,15 @@ void RenderCamera::doRefresh() {
|
|||
flags &= ~DIRTY;
|
||||
}
|
||||
/* ======== Setter functions ======== */
|
||||
// sets to orthogonal or perspective rendering
|
||||
void RenderCamera::setMode(int mode) {
|
||||
if (mode == 1) {
|
||||
render_mode = mode;
|
||||
} else {
|
||||
render_mode = 0;
|
||||
}
|
||||
updateProjection(width, height);
|
||||
}
|
||||
int RenderCamera::setRenderView(RenderView *rv) {
|
||||
if (rv == NULL) return 1;
|
||||
render_view = rv;
|
||||
|
@ -85,4 +100,10 @@ void RenderCamera::setYaw(float yaw_) {
|
|||
/* ======== Getter functions ======== */
|
||||
RenderView* RenderCamera::getRenderView() {
|
||||
return render_view;
|
||||
}
|
||||
}
|
||||
Vec3 RenderCamera::getPosition() {
|
||||
return position;
|
||||
}
|
||||
float RenderCamera::getSize() {
|
||||
return size;
|
||||
}
|
||||
|
|
|
@ -26,19 +26,23 @@ class RenderCamera {
|
|||
RenderView* getRenderView();
|
||||
void updateProjection(int width, int height);
|
||||
void doRefresh();
|
||||
void setMode(int mode);
|
||||
Vec3 getPosition();
|
||||
void setPosition(float x, float y, float z);
|
||||
void setPitch(float pitch);
|
||||
void setYaw(float yaw);
|
||||
float getSize();
|
||||
private:
|
||||
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
|
||||
Vec3 position; // The camera's coordinates in 3D space
|
||||
float pitch, yaw; // The camera's basic orientation
|
||||
float fov_angle; // The vertical FOV angle, used for perspective
|
||||
float size; // The vertical units on screen, used for orthogonal
|
||||
float near, far; // wherever you are
|
||||
int width, height; // width/height of the projection
|
||||
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;
|
||||
Mat4 p_matrix; // Our camera's projection matrix
|
||||
Mat4 mv_matrix; // modelview matrix
|
||||
int flags; // set flags, such as DIRTY
|
||||
};
|
||||
#endif
|
||||
|
|
|
@ -65,6 +65,7 @@ int RenderScene::doRender() {
|
|||
camera = *camera_it;
|
||||
if ((view = camera->getRenderView()) == NULL) continue; // bail if camera has no rendering target
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, view->fbo);
|
||||
glViewport(0, 0, view->w, view->h);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
// Iterate over the scene's render sets
|
||||
std::vector<RenderSet*>::iterator set_it, set_end;
|
||||
|
@ -103,12 +104,12 @@ int RenderScene::doRender() {
|
|||
// bind vp
|
||||
glBindBuffer(GL_ARRAY_BUFFER, mesh->vbo);
|
||||
glVertexAttribPointer(shader_vp, 3, GL_FLOAT, GL_FALSE, 0, NULL);
|
||||
/*// bind uvs/texture coords
|
||||
// bind uvs/texture coords
|
||||
glBindBuffer(GL_ARRAY_BUFFER, mesh->uvbo);
|
||||
glVertexAttribPointer(shader_uv, 2, GL_FLOAT, GL_FALSE, 0, 0);
|
||||
// bind normals
|
||||
glBindBuffer(GL_ARRAY_BUFFER, mesh->nbo);
|
||||
glVertexAttribPointer(shader_normal, 3, GL_FLOAT, GL_FALSE, 0, NULL);*/
|
||||
glVertexAttribPointer(shader_normal, 3, GL_FLOAT, GL_FALSE, 0, NULL);
|
||||
glDrawArrays(GL_TRIANGLES, 0, mesh->vertices.size());
|
||||
// TODO: maybe other things? Should this be managed by Program somehow?
|
||||
}
|
||||
|
@ -199,4 +200,4 @@ RenderSet* RenderScene::getSet(int id) {
|
|||
}
|
||||
std::vector<RenderSet*> *RenderScene::getSets() {
|
||||
return &sets;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,6 +24,9 @@ RenderView::~RenderView() {
|
|||
GLuint RenderView::getFBO() {
|
||||
return fbo;
|
||||
}
|
||||
GLuint RenderView::getTex() {
|
||||
return fbo_tex;
|
||||
}
|
||||
Mesh *RenderView::getMesh() {
|
||||
return mesh;
|
||||
}
|
||||
|
@ -51,8 +54,8 @@ int RenderView::createView(int width, int height) {
|
|||
// add some filters (... move this)
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
// unbind texture
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
// ================ create framebuffers
|
||||
|
@ -100,7 +103,11 @@ int RenderView::setView(int width, int height) {
|
|||
if ((flags & RENDERVIEW_ACTIVE) == 0) return 1;
|
||||
// resize depth buffer
|
||||
glBindRenderbuffer(GL_RENDERBUFFER, fbo_depth);
|
||||
#if defined(HAVE_OPENGLES)
|
||||
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, width, height);
|
||||
#else
|
||||
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, width, height);
|
||||
#endif
|
||||
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, fbo_depth);
|
||||
glBindRenderbuffer(GL_RENDERBUFFER, 0);
|
||||
// resize texture
|
||||
|
|
|
@ -18,6 +18,7 @@ class RenderView {
|
|||
RenderView(int width, int height);
|
||||
~RenderView();
|
||||
GLuint getFBO();
|
||||
GLuint getTex();
|
||||
Mesh *getMesh();
|
||||
int setProgram(Program *program);
|
||||
Program *getProgram();
|
||||
|
|
33
src/main.cpp
33
src/main.cpp
|
@ -6,6 +6,38 @@
|
|||
extern "C" void iPhoneFrame(void *) {
|
||||
core.doProcess();
|
||||
}
|
||||
/* handleAppEvents
|
||||
This function is used with SDL_SetEventFilter to intercept important events related to RtB entering the background and similar on mobile devices. If we do not handle the events in this fashion, RtB will terminate
|
||||
*/
|
||||
extern "C" int handleAppEvents(void *userdata, SDL_Event *event) {
|
||||
switch (event->type) {
|
||||
case SDL_APP_TERMINATING:
|
||||
core.closeSystem();
|
||||
// TODO: close everything
|
||||
break;
|
||||
case SDL_APP_LOWMEMORY:
|
||||
// TODO: not sure? free memory?
|
||||
break;
|
||||
case SDL_APP_WILLENTERBACKGROUND:
|
||||
// TODO: pause loops. activated when "home" is hit or a call is recv'd
|
||||
break;
|
||||
case SDL_APP_DIDENTERBACKGROUND:
|
||||
core.closeSystem();
|
||||
// TODO: occurs if WILLENTER was accepted. Have to save state?
|
||||
break;
|
||||
case SDL_APP_WILLENTERFOREGROUND:
|
||||
// TODO: occurs when app comes back, either from reactivation or if WILLENTER is denied. Restore state?
|
||||
break;
|
||||
case SDL_APP_DIDENTERFOREGROUND:
|
||||
// TODO: restart loops.
|
||||
break;
|
||||
default:
|
||||
// Add event to the standard event stack
|
||||
return 1;
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
#ifdef __APPLE__
|
||||
|
@ -16,6 +48,7 @@ int main(int argc, char *argv[]) {
|
|||
chdir(path);
|
||||
#endif
|
||||
core.initSystem();
|
||||
SDL_SetEventFilter(handleAppEvents, NULL);
|
||||
#if __IPHONEOS__
|
||||
//InitGameCenter();
|
||||
SDL_iPhoneSetAnimationCallback(core.getWindow(), 1, iPhoneFrame, 0);
|
||||
|
|
Loading…
Reference in New Issue