本文整理汇总了C++中GLRenderer类的典型用法代码示例。如果您正苦于以下问题:C++ GLRenderer类的具体用法?C++ GLRenderer怎么用?C++ GLRenderer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了GLRenderer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
void mesh_filter::StereoCameraModel::Parameters::setFilterParameters (GLRenderer& renderer) const
{
glUniform1f (glGetUniformLocation (renderer.getProgramID (), "near"), near_clipping_plane_distance_);
glUniform1f (glGetUniformLocation (renderer.getProgramID (), "far"), far_clipping_plane_distance_);
renderer.setClippingRange (near_clipping_plane_distance_, far_clipping_plane_distance_);
renderer.setBufferSize (width_, height_);
renderer.setCameraParameters (fx_, fy_, cx_, cy_);
}
示例2:
//-----------------------------------------------------------------------------
void RenderingContext::Draw(Shader& shader, GLRenderer& gl_renderer)
{
__GL_CALL(glUseProgram(shader.GetProgram()))
shader.SetUniforms(*this);
gl_renderer.Draw(shader, *this);
}
示例3: shader_fireball
void shader_fireball( GLWindow& window, GLRenderer& renderer ) {
auto camera = PerspectiveCamera::create(
40, (float)renderer.width() / renderer.height(), 1, 3000
);
camera->position().z = 4;
auto scene = Scene::create();
float time = 1;
auto material = ShaderMaterial::create(
vertexShader,
fragmentShader,
Uniforms().add("time", Uniform( THREE::f, time ))
.add("scale", Uniform( THREE::f, 1.5f ))
);
// Geometries
auto mesh = Mesh::create( SphereGeometry::create( 0.75f, 64, 32 ), material );
scene->add( mesh );
renderer.setClearColor( Color(0x050505), 0 );
/////////////////////////////////////////////////////////////////////////
window.animate( [&]( float dt ) -> bool {
time += dt;
material->uniforms[ "time" ].value = time;
mesh->rotation().x += 0.1f * dt;
mesh->rotation().y += 0.5f * dt;
renderer.render( *scene, *camera );
return true;
} );
}
示例4: SDL_CreateWindow
MStatus RadiosityRenderer::doIt(const MArgList &args)
{
this->args = args;
windowWidth = 640;
windowHeight = 480;
SDL_Window *window = SDL_CreateWindow( "Radiosity Renderer Viewport", 0, 0, 640, 480,
SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE );
SDL_GLContext glcontext = SDL_GL_CreateContext(window);
glClearColor(0,0,0,1);
glClear(GL_COLOR_BUFFER_BIT);
M3dView curView = M3dView::active3dView();
MDagPath camDagPath;
curView.getCamera( camDagPath );
IterateThroughDag();
//Pass DAG to renderer, let renderer render scene...
SDL_GL_MakeCurrent(window, glcontext);
GLRenderer renderer = GLRenderer(640,480);
renderer.RenderToScreen();
SDL_GL_SwapWindow(window);
//Write pixels to render window...
prepareRenderView();
SDL_GL_MakeCurrent(window, glcontext);
renderBufferToRenderView();
sleep(1);
SDL_GL_DeleteContext(glcontext);
SDL_DestroyWindow(window);
SDL_Quit();
return MS::kSuccess;
}
示例5: drawCallback
void GLRenderer::drawCallback(void)
{
GLRenderer* r = GLRenderer::getInstance();
r->draw();
}
示例6: main
// Main function
int main(int argc, char *argv[])
{
#if defined(DEBUG) | defined(_DEBUG)
_CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
#endif
return 0;
// random seed
randomSeed = static_cast<unsigned int>(time(NULL));
// Sets the update step
System::setClampStep(true,0.1f); // clamp the step to 100 ms
System::useAdaptiveStep(0.001f,0.01f); // use an adaptive step from 1ms to 10ms (1000fps to 100fps)
SDL_Event event;
// inits SDL
SDL_Init(SDL_INIT_VIDEO);
//SDL_WM_SetCaption("SPARK Basic Demo",NULL);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER,1); // double buffering
// vsync
//+SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL,0);
//+SDL_SetVideoMode(0,0,32, SDL_OPENGL | SDL_FULLSCREEN);
SDL_ShowCursor(0);
//+SDL_Surface screen = *SDL_GetVideoSurface();
screenWidth = 640;
screenHeight = 480;
SDL_Window* window = SDL_CreateWindow("OpenGL Window", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, screenWidth, screenHeight, SDL_WINDOW_OPENGL | SDL_WINDOW_FULLSCREEN);
renderFirstFrame();
// inits openGL
screenRatio = (float)screenWidth / (float)screenHeight;
glClearColor(0.0f,0.0f,0.0f,1.0f);
glViewport(0,0,screenWidth,screenHeight);
// Loads texture font
FTGLTextureFont font = FTGLTextureFont("res/font.ttf");
if(font.Error())
return 1;
font.FaceSize(24);
fontPtr = &font;
// Loads particle texture
GLuint textureParticle;
if (!loadTexture(textureParticle,"res/point.bmp",GL_ALPHA,/*GL_CLAMP*/GL_CLAMP_TO_EDGE,false))
return 1;
// Inits Particle Engine
Vector3D gravity(0.0f,-0.8f,0.0f);
// Renderers
GLPointRenderer* basicRenderer = GLPointRenderer::create();
GLRenderer* particleRenderer = NULL;
// We use pointSprites only if it is available and if the GL extension point parameter is available
if ((GLPointRenderer::loadGLExtPointSprite())&&(GLPointRenderer::loadGLExtPointParameter()))
{
GLPointRenderer* pointRenderer = GLPointRenderer::create();
pointRenderer->setType(POINT_SPRITE);
pointRenderer->setTexture(textureParticle);
pointRenderer->setTextureBlending(GL_MODULATE);
pointRenderer->enableWorldSize(true);
GLPointRenderer::setPixelPerUnit(45.0f * PI / 180.f,screenHeight);
pointRenderer->setSize(0.05f);
particleRenderer = pointRenderer;
}
else // we use quads
{
GLQuadRenderer* quadRenderer = GLQuadRenderer::create();
quadRenderer->setTexturingMode(TEXTURE_2D);
quadRenderer->setTexture(textureParticle);
quadRenderer->setTextureBlending(GL_MODULATE);
quadRenderer->setScale(0.05f,0.05f);
particleRenderer = quadRenderer;
}
particleRenderer->setBlending(BLENDING_ADD);
particleRenderer->enableRenderingHint(DEPTH_WRITE,false);
// Model
Model* particleModel = Model::create(FLAG_RED | FLAG_GREEN | FLAG_BLUE | FLAG_ALPHA);
particleModel->setParam(PARAM_ALPHA,0.8f); // constant alpha
particleModel->setLifeTime(8.0f,8.0f);
// Emitter
SphericEmitter* particleEmitter = SphericEmitter::create(Vector3D(0.0f,1.0f,0.0f),0.1f * PI,0.1f * PI);
particleEmitter->setZone(Point::create(Vector3D(0.0f,0.015f,0.0f)));
particleEmitter->setFlow(250);
particleEmitter->setForce(1.5f,1.5f);
// Obstacle
Plane* groundPlane = Plane::create();
Obstacle* obstacle = Obstacle::create(groundPlane,INTERSECT_ZONE,0.6f,1.0f);
// Group
//.........这里部分代码省略.........
示例7: particles_sprites
void particles_sprites( GLWindow& window, GLRenderer& renderer ) {
auto camera = PerspectiveCamera::create(
75, ( float )renderer.width() / renderer.height(), 1.f, 2000
);
camera->position().z = 1000;
auto scene = Scene::create();
scene->fog = FogExp2::create( 0x000000, .0008f );
auto geometry = Geometry::create();
auto sprite1 = ImageUtils::loadTexture( threeDataPath("textures/sprites/snowflake1.png") );
auto sprite2 = ImageUtils::loadTexture( threeDataPath("textures/sprites/snowflake2.png") );
auto sprite3 = ImageUtils::loadTexture( threeDataPath("textures/sprites/snowflake3.png") );
auto sprite4 = ImageUtils::loadTexture( threeDataPath("textures/sprites/snowflake4.png") );
auto sprite5 = ImageUtils::loadTexture( threeDataPath("textures/sprites/snowflake5.png") );
const auto particleCount = 10000;
geometry->vertices.reserve( particleCount );
std::generate_n( std::back_inserter( geometry->vertices ),
particleCount,
[] { return Vector3( Math::random(-1000.f, 1000.f),
Math::random(-1000.f, 1000.f),
Math::random(-1000.f, 1000.f) ); } );
std::vector<Material::Ptr> materials;
auto addParticleSystem = [&]( const Vector3& color, const Texture::Ptr& sprite, float size ) {
auto material = ParticleSystemMaterial::create(
Material::Parameters().add( "size", size )
.add( "map", sprite )
.add( "blending", THREE::AdditiveBlending )
.add( "depthTest", false )
.add( "transparent", true )
);
materials.push_back( material );
material->color.setHSL( color[0], color[1], color[2] );
auto particles = ParticleSystem::create( geometry, material );
particles->rotation() = Euler( Math::random() * 6,
Math::random() * 6,
Math::random() * 6 );
scene->add( particles );
};
typedef std::tuple<Vector3, Texture::Ptr, float> ColorSpriteSize;
std::array<ColorSpriteSize, 5> params = {
ColorSpriteSize( Vector3( 1.f, 0.2f, 0.5f), sprite2, 20.f ),
ColorSpriteSize( Vector3(0.95f, 0.1f, 0.5f), sprite3, 13.f ),
ColorSpriteSize( Vector3(0.90f, 0.05f, 0.5f), sprite1, 10.f ),
ColorSpriteSize( Vector3(0.85f, 0.f, 0.5f), sprite5, 8.f ),
ColorSpriteSize( Vector3(0.80f, 0.f, 0.5f), sprite4, 5.f )
};
for ( const auto& param : params ) {
addParticleSystem( std::get<0>(param), std::get<1>(param), std::get<2>(param) );
}
/////////////////////////////////////////////////////////////////////////
auto mouseX = 0.f, mouseY = 0.f;
window.addEventListener( SDL_MOUSEMOTION, [&]( const SDL_Event& event ) {
mouseX = 2.f * ( ( float )event.motion.x / renderer.width() - 0.5f );
mouseY = 2.f * ( ( float )event.motion.y / renderer.height() - 0.5f );
} );
window.addEventListener( SDL_WINDOWEVENT, [&]( const SDL_Event& event ) {
if (event.window.event != SDL_WINDOWEVENT_RESIZED) return;
camera->aspect = ( float )event.window.data1 / event.window.data2;
camera->updateProjectionMatrix();
renderer.setSize( event.window.data1, event.window.data2 );
} );
/////////////////////////////////////////////////////////////////////////
auto time = 0.f;
window.animate( [&]( float dt ) -> bool {
time += dt * .05f;
camera->position().x += ( -1000.f * mouseX - camera->position().x ) * 3 * dt;
camera->position().y += ( 1000.f * mouseY - camera->position().y ) * 3 * dt;
camera->lookAt( scene->position() );
for ( size_t i = 0; i < scene->children.size(); ++i ) {
auto& object = *scene->children[ i ];
if ( object.type() == THREE::ParticleSystem ) {
object.rotation().y = time * ( i < 4 ? i + 1 : - ( (int)i + 1 ) );
}
}
for ( size_t i = 0; i < materials.size(); ++i ) {
auto& color = std::get<0>(params[ i ]);
const auto h = Math::fmod( 360.f * ( color[0] + time ), 360.f ) / 360.f;
materials[ i ]->color.setHSL( h, color[ 1 ], color[ 2 ] );
//.........这里部分代码省略.........
示例8: geometries
void geometries( GLWindow& window, GLRenderer& renderer ) {
auto camera = PerspectiveCamera::create(
45, ( float )renderer.width() / renderer.height(), 10, 20000
);
camera->position().y = 700;
auto scene = Scene::create();
scene->add( AmbientLight::create( 0x404040 ) );
auto light = DirectionalLight::create( 0xffffff );
light->position().set( 0, 1, 0 );
scene->add( light );
auto map = ImageUtils::loadTexture( threeDataPath( "textures/UV_Grid_Sm.jpg" ) );
map->wrapS = map->wrapT = THREE::RepeatWrapping;
map->anisotropy = 16;
auto material = MeshLambertMaterial::create(
Material::Parameters()
.add( "ambient", Color( 0xbbbbbb ) )
.add( "map", map )
.add( "side", THREE::DoubleSide )
);
//
auto sphere = Mesh::create( SphereGeometry::create( 75, 20, 10 ), material );
sphere->position().set( -400, 0, 200 );
scene->add( sphere );
auto ico = Mesh::create( IcosahedronGeometry::create( 75, 1 ), material );
ico->position().set( -200, 0, 200 );
scene->add( ico );
auto octa = Mesh::create( OctahedronGeometry::create( 75, 2 ), material );
octa->position().set( 0, 0, 200 );
scene->add( octa );
auto tetra = Mesh::create( TetrahedronGeometry::create( 75, 0 ), material );
tetra->position().set( 200, 0, 200 );
scene->add( tetra );
//
auto plane = Mesh::create( PlaneGeometry::create( 100, 100, 4, 4 ), material );
plane->position().set( -400, 0, 0 );
scene->add( plane );
auto cube = Mesh::create( BoxGeometry::create( 100, 100, 100, 4, 4, 4 ), material );
cube->position().set( -200, 0, 0 );
scene->add( cube );
auto circle = Mesh::create( CircleGeometry::create( 50, 20, 0, Math::PI() * 2 ), material );
circle->position().set( 0, 0, 0 );
scene->add( circle );
auto ring = Mesh::create( RingGeometry::create( 10, 50, 20, 5, 0, Math::PI() * 2 ), material );
ring->position().set( 200, 0, 0 );
scene->add( ring );
auto cylinder = Mesh::create( CylinderGeometry::create( 25, 75, 100, 40, 5 ), material );
cylinder->position().set( 400, 0, 0 );
scene->add( cylinder );
//
std::vector<Vector3> points;
for ( auto i = 0; i < 50; i ++ ) {
points.push_back( Vector3( Math::sin( (float)i * 0.2 ) * Math::sin( (float)i * 0.1 ) * 15 + 50, 0, ( (float)i - 5 ) * 2 ) );
}
auto lathe = Mesh::create( LatheGeometry::create( points, 20 ), material );
lathe->position().set( -400, 0, -200 );
scene->add( lathe );
auto torus = Mesh::create( TorusGeometry::create( 50, 20, 20, 20 ), material );
torus->position().set( -200, 0, -200 );
scene->add( torus );
auto torusKnot = Mesh::create( TorusKnotGeometry::create( 50, 10, 50, 20 ), material );
torusKnot->position().set( 0, 0, -200 );
scene->add( torusKnot );
auto axis = AxisHelper::create( 50 );
axis->position().set( 200, 0, -200 );
scene->add( axis );
auto arrow = ArrowHelper::create( Vector3( 0, 1, 0 ), Vector3( 0, 0, 0 ) );
arrow->setLength(50);
arrow->position().set( 400, 0, -200 );
scene->add( arrow );
/////////////////////////////////////////////////////////////////////////
window.addEventListener( SDL_WINDOWEVENT, [&]( const SDL_Event& event ) {
if (event.window.event != SDL_WINDOWEVENT_RESIZED) return;
//.........这里部分代码省略.........
示例9: trails
void trails( GLWindow& window, GLRenderer& renderer ) {
renderer.sortObjects = false;
renderer.autoClearColor = false;
// Camera
auto camera = PerspectiveCamera::create(
60,
(float)renderer.width() / renderer.height(),
1, 10000
);
camera->position().set( 100000, 0, 3200 );
// Scene
auto scene = Scene::create();
// Geometries
std::array<Color, 4> colors = { Color(0x000000), Color(0xff0080), Color(0x8000ff), Color(0xffffff) };
auto geometry = Geometry::create();
for ( int i = 0; i < 2000; i ++ ) {
Vertex vertex;
vertex.x = Math::random(-2000.f, 2000.f);
vertex.y = Math::random(-2000.f, 2000.f);
vertex.z = Math::random(-2000.f, 2000.f);
geometry->vertices.push_back( vertex );
geometry->colors.push_back( colors[ (int)Math::floor( Math::random() * colors.size() ) ] );
}
// Materials
auto material = ParticleSystemMaterial::create(
Material::Parameters().add("color", Color(0xcccccc))
.add("size", 1.0f)
.add("vertexColors", THREE::VertexColors)
.add("depthTest", false)
.add("opacity", 0.5f)
.add("sizeAttenuation", false)
);
auto mesh = ParticleSystem::create( geometry, material );
scene->add( mesh );
auto mouseX = 0.f, mouseY = 0.f;
window.addEventListener(SDL_MOUSEMOTION, [&]( const SDL_Event& event ) {
mouseX = 2.f * ((float)event.motion.x / renderer.width() - 0.5f);
mouseY = 2.f * ((float)event.motion.y / renderer.height() - 0.5f);
});
// Rendering
window.animate ( [&]( float dt ) -> bool {
camera->position().x += ( 1000.f * mouseX - camera->position().x ) * 5 * dt;
camera->position().y += ( 1000.f * mouseY - camera->position().y ) * 5 * dt;
camera->lookAt( scene->position() );
renderer.render( *scene, *camera );
return true;
} );
}
示例10: main
//.........这里部分代码省略.........
else if (arg.find(HANDLER_ARG) != std::string::npos) {
handler_type = arg.substr(HANDLER_ARG.size());
}
else if (arg.find(BRANCH_ARG) != std::string::npos) {
std::string branch_arg = arg.substr(BRANCH_ARG.size());
branching = boost::lexical_cast<int>(branch_arg);
}
else if (arg.find(NQUERIES_ARG) != std::string::npos) {
std::string nqueries_arg = arg.substr(NQUERIES_ARG.size());
nqueries = boost::lexical_cast<int>(nqueries_arg);
}
else if (arg.find(STATIC_QUERIES_ARG) != std::string::npos) {
std::string static_arg = arg.substr(STATIC_QUERIES_ARG.size());
static_queries = convert_bool(static_arg);
}
}
srand(seed);
#ifndef LIBPROX_RTREE_DATA
# error "You must define LIBPROX_RTREE_DATA to either LIBPROX_RTREE_DATA_BOUNDS or LIBPROX_RTREE_DATA_MAXSIZE"
#endif
#if LIBPROX_RTREE_DATA == LIBPROX_RTREE_DATA_BOUNDS
typedef Prox::BoundingSphereData<Prox::DefaultSimulationTraits> NodeData;
#elif LIBPROX_RTREE_DATA == LIBPROX_RTREE_DATA_MAXSIZE
typedef Prox::MaxSphereData<Prox::DefaultSimulationTraits> NodeData;
#elif LIBPROX_RTREE_DATA == LIBPROX_RTREE_DATA_SIMILARMAXSIZE
typedef Prox::SimilarMaxSphereData<Prox::DefaultSimulationTraits> NodeData;
#else
# error "Invalid setting for LIBPROX_RTREE_DATA"
#endif
ManualQueryHandler* handler = NULL;
if (handler_type == "rtree") {
handler = new Prox::RTreeManualQueryHandler<Prox::DefaultSimulationTraits, NodeData>(branching);
}
Simulator* simulator = new Simulator(handler, duration, Duration::milliseconds((unsigned int)timestep), iterations, realtime);
GLRenderer* renderer = new GLRenderer(simulator, handler, display);
BoundingBox3 random_region( Vector3(-100.f, -100.f, -100.f), Vector3(100.f, 100.f, 100.f) );
int nobjects_moving = nobjects * moving_frac;
int nobjects_static = nobjects - nobjects_moving;
// There are various combinations of sources of objects we might need to get
// to the target number with the right mix. When we need random objects and
// we've loaded some from another source, we need to make sure we get the
// region to generate them over correct.
bool got_static = false;
bool got_moving = false;
// First, get objects from csv files.
if (!csvfile.empty()) {
simulator->createStaticCSVObjects(csvfile, nobjects_static);
got_static = true;
}
// note: this should be second so that
if (!csvmotionfile.empty()) {
assert(!csvfile.empty()); // FIXME we'd like to support this, need to
// figure out bounding box issues for
// generating starting positions
simulator->createMotionCSVObjects(csvmotionfile, nobjects_moving);
got_moving = true;
}
// Next, take care of leftovers with random objects. Note that we use the
// existing bounds if some other objects were already loaded.
if (!got_static && !got_moving)
simulator->createRandomObjects(random_region, nobjects, moving_frac);
else if (!got_static && got_moving)
simulator->createRandomObjects(simulator->region(), nobjects_static, 0.0);
else if (got_static && !got_moving)
simulator->createRandomObjects(simulator->region(), nobjects_moving, 1.0);
// else we don't need any random objects
// Sometimes we're not perfect, but let's aim for 99% of the target objects.
assert(simulator->allObjectsSize() >= .99f * nobjects);
simulator->initialize(/*churn_rate*/0);
if (!csvmotionfile.empty() && !static_queries)
simulator->createCSVQueries(nqueries, csvmotionfile);
else
simulator->createRandomQueries(nqueries, static_queries);
simulator->run();
renderer->run();
simulator->shutdown();
delete renderer;
delete simulator;
return 0;
}
示例11: shader
void shader( GLWindow& window, GLRenderer& renderer ) {
auto camera = PerspectiveCamera::create(
60, ( float )renderer.width() / renderer.height(), 1, 10000
);
camera->position().z = 300;
auto scene = Scene::create();
auto texture = ImageUtils::loadTexture( threeDataPath( "textures/sprites/spark1.png" ) );
Uniforms uniforms;
uniforms[ "color" ] = Uniform( THREE::c, Color( 0xffffff ) );
uniforms[ "texture" ] = Uniform( THREE::t, texture.get() );
Attributes attributes;
attributes[ "size" ] = Attribute( THREE::f );
attributes[ "customColor" ] = Attribute( THREE::c );
auto shaderMaterial = ShaderMaterial::create(
vertexShader,
fragmentShader,
uniforms,
attributes,
Material::Parameters().add( "blending", THREE::AdditiveBlending )
.add( "depthTest", false )
.add( "transparent", true )
);
// Geometries
const auto radius = 200.f;
const auto pointCount = 100000;
auto geometry = Geometry::create();
auto& vertices = geometry->vertices;
vertices.reserve( pointCount );
std::generate_n(
std::back_inserter(vertices),
pointCount,
[=]() -> Vector3 {
return Vector3( Math::random(-1.f, 1.f),
Math::random(-1.f, 1.f),
Math::random(-1.f, 1.f) ).multiplyScalar( radius );
}
);
auto sphere = ParticleSystem::create( geometry, shaderMaterial );
sphere->geometry->dynamic = true;
sphere->sortParticles = false;
std::vector<float> values_size( pointCount );
std::vector<Color> values_color( pointCount );
for ( int v = 0; v < pointCount; v++ ) {
values_size[ v ] = 10;
values_color[ v ].set( 0xffaa00 );
if ( vertices[ v ].x < 0 )
values_color[ v ].setHSL( 0.5f + 0.1f * ( (float)v / pointCount ), 0.7f, 0.5f );
else
values_color[ v ].setHSL( 0.0f + 0.1f * ( (float)v / pointCount), 0.9f, 0.5f );
}
auto& size = shaderMaterial->attributes[ "size" ];
auto& color = shaderMaterial->attributes[ "customColor" ];
size.value = values_size;
color.value = values_color;
scene->add( sphere );
/////////////////////////////////////////////////////////////////////////
window.addEventListener( SDL_WINDOWEVENT, [&]( const SDL_Event& event ) {
if (event.window.event != SDL_WINDOWEVENT_RESIZED) return;
camera->aspect = ( float )event.window.data1 / event.window.data2;
camera->updateProjectionMatrix();
renderer.setSize( event.window.data1, event.window.data2 );
} );
/////////////////////////////////////////////////////////////////////////
auto time = 0.f;
window.animate( [&]( float dt ) -> bool {
time += dt;
sphere->rotation().z = time * 0.03f;
auto& sizes = size.value.cast<std::vector<float>>();
for( size_t i = 0; i < sizes.size(); i++ ) {
sizes[ i ] = 10.f + 9.f * Math::sin( 0.1f * i + time * 3.f );
}
size.needsUpdate = true;
renderer.render( *scene, *camera );
//.........这里部分代码省略.........
示例12: particles_billboards
void particles_billboards( GLWindow& window, GLRenderer& renderer ) {
auto camera = PerspectiveCamera::create(
55, ( float )renderer.width() / renderer.height(), 2.f, 2000
);
camera->position().z = 1000;
auto scene = Scene::create();
scene->fog = FogExp2::create( 0x000000, .001f );
auto geometry = Geometry::create();
const auto particleCount = 10000;
geometry->vertices.reserve( particleCount );
std::generate_n( std::back_inserter( geometry->vertices ),
particleCount,
[] { return Vector3( Math::random(-1000.f, 1000.f),
Math::random(-1000.f, 1000.f),
Math::random(-1000.f, 1000.f) ); } );
auto sprite = ImageUtils::loadTexture(
threeDataPath("textures/sprites/disc.png")
);
auto material = ParticleSystemMaterial::create(
Material::Parameters().add( "size", 35.f )
.add( "map", sprite )
.add( "sizeAttenuation", false )
.add( "transparent", true)
);
material->color.setHSL( 1.f, 0.3f, 0.7f );
auto particles = ParticleSystem::create( geometry, material );
particles->sortParticles = true;
scene->add( particles );
/////////////////////////////////////////////////////////////////////////
auto mouseX = 0.f, mouseY = 0.f;
window.addEventListener( SDL_MOUSEMOTION, [&]( const SDL_Event& event ) {
mouseX = 2.f * ( ( float )event.motion.x / renderer.width() - 0.5f );
mouseY = 2.f * ( ( float )event.motion.y / renderer.height() - 0.5f );
} );
window.addEventListener( SDL_WINDOWEVENT, [&]( const SDL_Event& event ) {
if (event.window.event != SDL_WINDOWEVENT_RESIZED) return;
camera->aspect = ( float )event.window.data1 / event.window.data2;
camera->updateProjectionMatrix();
renderer.setSize( event.window.data1, event.window.data2 );
} );
/////////////////////////////////////////////////////////////////////////
auto time = 0.f;
window.animate( [&]( float dt ) -> bool {
time += dt * .05f;
camera->position().x += ( -1000.f * mouseX - camera->position().x ) * 3 * dt;
camera->position().y += ( 1000.f * mouseY - camera->position().y ) * 3 * dt;
camera->lookAt( scene->position() );
const auto h = Math::fmod( 360.f * ( 1.f + time ), 360.f ) / 360.f;
material->color.setHSL( h, 0.5f, 0.5f );
renderer.render( *scene, *camera );
return true;
} );
}
示例13:
void GL_LoadStaticScene()
{
for(unsigned int wo=0;wo<staticObjectCount;wo++) {
GL_AddModelToLists(&staticObjectPool[wo], true);
}
renderer.staticsRebuild();
}
示例14: sizeof
void GL_AddLight(residx_t shader, sceneobj_t *obj, bool bStatic)
{
worldLight_t *l = &worldlights[lightCount++];
memset(l, 0, sizeof(worldLight_t));
M_CopyVec3(obj->color, l->color);
//M_CopyVec3(obj->pos, l.origin);
l->falloff = obj->scale;
renderer.addLight(l, obj, shader, bStatic);
}
示例15: GLRenderTarget
void GL_InitScene()
{
Cvar_Register(&gfx_doubleSided);
Cvar_Register(&gfx_separate_specular_color);
Cvar_Register(&gfx_ambient_and_diffuse);
Cvar_Register(&gfx_render);
Cvar_Register(&gfx_maxlightsperpass);
Cvar_Register(&gfx_multipassLighting);
Cvar_Register(&gfx_nicerFog);
Cvar_Register(&gfx_octreeDepth);
Cvar_Register(&gfx_sortAll);
Cvar_Register(&gfx_depthNormalPass);
Cvar_Register(&gfx_debugoctree);
Cvar_Register(&gfx_useBuckets);
Cvar_Register(&gfx_niceEffects);
Cvar_Register(&gfx_debugCamera);
GL_InitTerrain();
GL_InitModel();
GL_InitWater();
GL_InitClouds();
GL_InitWeather();
if (gl_ext_texenv_combine.integer) //we'll be using 2x modulation
{
Cvar_Set("vid_overbrightNormalize", "0.5");
}
GL_InitShadow();
GL_InitPostProcessing();
screen_target = new GLRenderTarget();
glScreen = screen_target;
if(gfx_postProcEnabled.integer)
zPass = new DepthPass();
glGetIntegerv(GL_MAX_LIGHTS, &glMaxLights);
renderer.reset();
}