本文整理汇总了C++中GLContext::isOpen方法的典型用法代码示例。如果您正苦于以下问题:C++ GLContext::isOpen方法的具体用法?C++ GLContext::isOpen怎么用?C++ GLContext::isOpen使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GLContext
的用法示例。
在下文中一共展示了GLContext::isOpen方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char **argv)
{
GLContext ctx;
if (!ctx.create(VideoMode(720, 480, 24, 0, 4), "12 Framebuffer", true, true))
{
APP_LOG << "Failed to open context\n";
return EXIT_FAILURE;
}
APP_LOG << ctx.getDebugInfo();
Renderer gfx;
gfx.init(ctx);
try
{
if (!load())
{
gfx.dispose();
ctx.dispose();
APP_LOG << "Failed to load content\n";
return EXIT_FAILURE;
}
init(gfx, ctx);
double dt = 0.0;
while (ctx.isOpen())
{
double frame_t = ctx.getElapsedTime();
update(gfx, ctx, dt);
render(gfx, ctx, dt);
ctx.display();
ctx.pollEvents();
if (ctx.isKeyPressed(SDL_SCANCODE_ESCAPE))
ctx.close();
if (checkGLErrors())
ctx.close();
dt = ctx.getElapsedTime() - frame_t;
}
}
catch (std::exception &e)
{
APP_LOG << "An unexpected error occurred: " << e.what();
}
free();
gfx.dispose();
ctx.dispose();
return EXIT_SUCCESS;
}
示例2: run
void run()
{
if(!initialize())
shutdown("Failed to initialize");
if(!loadContent())
shutdown("Failed to load resources");
Mesh cubeMesh = Mesh::genUnitColoredCube();
MeshBuffer cubeBuffer(cubeMesh);
Model cube(cubeBuffer);
Mesh waterMesh = Mesh::genUnitColoredPlane(Color(0.57f, 0.63f, 0.98f));
MeshBuffer waterBuffer(waterMesh);
Model water(waterBuffer);
BufferObject quadVbo;
float quadVertices[] = {
-1.0f, -1.0f, 0.0f, 0.0f,
+1.0f, -1.0f, 1.0f, 0.0f,
+1.0f, +1.0f, 1.0f, 1.0f,
+1.0f, +1.0f, 1.0f, 1.0f,
-1.0f, +1.0f, 0.0f, 1.0f,
-1.0f, -1.0f, 0.0f, 0.0f
};
quadVbo.create(GL_ARRAY_BUFFER, GL_STATIC_DRAW, sizeof(quadVertices), quadVertices);
Mesh gridMesh;
for(int i = 0; i <= 8; ++i)
{
float f = (i / 8.0) * 2.0f - 1.0f;
int j = gridMesh.getPositionCount();
gridMesh.addPosition(f * 3.0f, 0.0f, -3.0f);
gridMesh.addPosition(f * 3.0f, 0.0f, +3.0f);
gridMesh.addPosition(-3.0f, 0.0f, f * 3.0f);
gridMesh.addPosition(+3.0f, 0.0f, f * 3.0f);
gridMesh.addColor(Colors::White);
gridMesh.addColor(Colors::White);
gridMesh.addColor(Colors::White);
gridMesh.addColor(Colors::White);
gridMesh.addIndex(j + 0); gridMesh.addIndex(j + 1);
gridMesh.addIndex(j + 2); gridMesh.addIndex(j + 3);
}
MeshBuffer gridBuffer(gridMesh);
Model grid(gridBuffer);
VertexArray vao;
vao.create();
vao.bind();
mat4 perspectiveMatrix = glm::perspective(45.0f, windowWidth / float(windowHeight), 0.05f, 50.0f);
// The geometry to be refracted and reflected are stored in these
// In addition to RGB values, the world-space height is stored in the alpha-channel
// of the refraction texture.
// Fresnel equations is used to blend between the two textures
RenderTexture refractionRT(windowWidth, windowHeight);
RenderTexture reflectionRT(windowWidth, windowHeight);
renderer.setClearColor(0.55f, 0.45f, 0.45f, 1.0f);
renderer.setClearDepth(1.0);
Timer timer;
timer.start();
double renderTime = 0.0;
while(context.isOpen())
{
timer.step();
double time = timer.getElapsedTime();
update(time, timer.getDelta());
double renderStart = timer.getElapsedTime();
MatrixStack viewMatrix;
viewMatrix.push();
viewMatrix.translate(0.0f, 0.0f, -3.0f);
viewMatrix.rotateX(xAxisRotation);
viewMatrix.rotateY(yAxisRotation);
renderer.setCullState(CullStates::CullNone);
renderer.setDepthTestState(DepthTestStates::LessThanOrEqual);
colorShader.begin();
colorShader.setUniform("projection", perspectiveMatrix);
cube.pushTransform();
cube.translate(0.0f, 0.0f, 0.0f);
cube.scale(0.5f);
// Render the geometry to be refracted, store result in rt
refractionRT.begin();
renderer.clearColorAndDepth();
colorShader.setUniform("view", viewMatrix.top());
cube.draw(GL_TRIANGLES);
grid.draw(GL_LINES);
refractionRT.end();
// Render the geometry to be reflected, store result in rt
reflectionRT.begin();
renderer.clearColorAndDepth();
viewMatrix.push();
//.........这里部分代码省略.........