本文整理汇总了C++中Model::Draw方法的典型用法代码示例。如果您正苦于以下问题:C++ Model::Draw方法的具体用法?C++ Model::Draw怎么用?C++ Model::Draw使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Model
的用法示例。
在下文中一共展示了Model::Draw方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Display
void Demo::Display(float t) {
glBindFramebuffer(GL_FRAMEBUFFER, mFramebuffer);
gWorld = Matrix4::rotationY(t * 60 * 3.14159f / 180.f);
gWorld *= Matrix4::rotationX(-90.0f * 3.14159f / 180.f);
gTime = t;
gExplode = 0.5 * t;
vLightDirs = Vector4(-0.577f, 0.577f, -0.577f, 1.0f);
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable(GL_DEPTH_TEST);
mExtrudeEffect.Enable();
gModel.Draw(*this);
glBindFramebuffer(GL_READ_FRAMEBUFFER, mFramebuffer);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
glBlitFramebuffer(0, 0, WindowWidth, WindowHeight,
0, 0, WindowWidth, WindowHeight,
GL_COLOR_BUFFER_BIT, GL_NEAREST);
}
示例2: Draw
void Draw()
{
BeginDraw();
model.Draw();
EndDraw();
}
示例3: Update
void Update()
{
MouseController();
glm::mat4 _projection;
glm::mat4 _view;
glm::mat4 _model;
_projection = glm::perspective(45.0f, 800.0f/600.0f, 0.1f, 100.0f);
glm::vec3 camDir(cosf(camPitch) * sinf(camYaw), sinf(camPitch), cosf(camPitch) * cosf(camYaw));
glm::vec3 camRight(sinf(camYaw - MATH_PI/2.0f), 0.0f, cosf(camYaw - MATH_PI/2.0f));
glm::vec3 camUp = cross(camRight, camDir);
_view = glm::lookAt(camPos, camPos + camDir, camUp);
KeyboardController(camDir, camRight, 0.0025f);
_model = glm::translate(_model, glm::vec3(0.0f, -1.75f, 0.0f));
_model = glm::scale(_model, glm::vec3(0.2f, 0.2f, 0.2f));
_model = glm::rotate(_model, 180.0f*(MATH_PI/180.0f), glm::vec3(0.0f, 1.0f, 0.0f));
glUseProgram(shader.program);
glUniformMatrix4fv(glGetUniformLocation(shader.program, "projection"), 1, GL_FALSE, glm::value_ptr(_projection));
glUniformMatrix4fv(glGetUniformLocation(shader.program, "view"), 1, GL_FALSE, glm::value_ptr(_view));
glUniformMatrix4fv(glGetUniformLocation(shader.program, "model"), 1, GL_FALSE, glm::value_ptr(_model));
glUniform3f(glGetUniformLocation(shader.program, "viewPos"), camPos.x, camPos.y, camPos.z);
// Point light 1
glUniform3f(glGetUniformLocation(shader.program, "pointLights[0].position"), 2.3f, -1.6f, -3.0f);
glUniform3f(glGetUniformLocation(shader.program, "pointLights[0].ambient"), 0.05f, 0.05f, 0.05f);
glUniform3f(glGetUniformLocation(shader.program, "pointLights[0].diffuse"), 1.0f, 1.0f, 1.0f);
glUniform3f(glGetUniformLocation(shader.program, "pointLights[0].specular"), 1.0f, 1.0f, 1.0f);
glUniform1f(glGetUniformLocation(shader.program, "pointLights[0].constant"), 1.0f);
glUniform1f(glGetUniformLocation(shader.program, "pointLights[0].linear"), 0.009);
glUniform1f(glGetUniformLocation(shader.program, "pointLights[0].quadratic"), 0.0032);
// Point light 2
glUniform3f(glGetUniformLocation(shader.program, "pointLights[1].position"), -1.7f, 0.9f, 1.0f);
glUniform3f(glGetUniformLocation(shader.program, "pointLights[1].ambient"), 0.05f, 0.05f, 0.05f);
glUniform3f(glGetUniformLocation(shader.program, "pointLights[1].diffuse"), 1.0f, 1.0f, 1.0f);
glUniform3f(glGetUniformLocation(shader.program, "pointLights[1].specular"), 1.0f, 1.0f, 1.0f);
glUniform1f(glGetUniformLocation(shader.program, "pointLights[1].constant"), 1.0f);
glUniform1f(glGetUniformLocation(shader.program, "pointLights[1].linear"), 0.009);
glUniform1f(glGetUniformLocation(shader.program, "pointLights[1].quadratic"), 0.0032);
model.Draw(shader);
}
示例4: Display
void Display()
{
CHECK();
glMatrixMode(GL_MODELVIEW);
glMultMatrixf( value_ptr(scale(vec3(3.0f))*translate<float>(0,-12.0,0)*rotate<float>(180,0,1,0)) );
{
SaveAttrib save;
glUseProgram( Program::Get("gouraud.vert+gouraud.frag")->Handle() );
glBindFramebuffer(GL_FRAMEBUFFER, mFramebuffer);
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glViewport(0, 0, SHADOW_MAP_SIZE, SHADOW_MAP_SIZE);
mModel->Draw();
glBindFramebuffer(GL_FRAMEBUFFER, 0);
}
{
SaveAttrib save;
glDisable(GL_DEPTH_TEST);
glDepthMask(GL_FALSE);
int size = Util::GetFloat(GL_MAX_VIEWPORT_DIMS);
Util::SetMatrix(GL_PROJECTION, ortho<float>(0, size, 0, size, -1, 1));
glViewport(0, 0, size, size);
Util::SetMatrix(GL_MODELVIEW, mat4());
glBindFramebuffer(GL_FRAMEBUFFER, mFramebuffer2);
glClear(GL_COLOR_BUFFER_BIT);
glUseProgram(*Program::Get("gauss_x.frag"));
glBindTexture(GL_TEXTURE_2D, *mColor);
Util::DrawRect(0,0, SHADOW_MAP_SIZE, SHADOW_MAP_SIZE);
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glUseProgram(*Program::Get("gauss_y.frag"));
glBindTexture(GL_TEXTURE_2D, *mColor2);
Util::DrawRect(0,0, SHADOW_MAP_SIZE, SHADOW_MAP_SIZE);
glUseProgram(*Program::Get("depth_view.frag"));
glBindTexture(GL_TEXTURE_2D, *mColor);
Util::DrawRect(0, 0, 256, 256);
glBindTexture(GL_TEXTURE_2D, *mColor2);
Util::DrawRect(256, 0, 256, 256);
}
}
示例5: Display
void Demo::Display(float t) {
if(mComputeEnabled)
{
mCompute.Enable();
mCompute.SetFloat(std::string("GlobalsCS.Time"), 1, &gChangesEveryFrame.Time);
glDispatchCompute(32, 32, 1);
}
glBindFramebuffer(GL_FRAMEBUFFER, mFramebuffer);
gWorld = Matrix4::rotationY(180.0f * 3.14159f / 180.f);
gWorld *= Matrix4::rotationX(-90.0f * 3.14159f / 180.f);
gTime = t;
vLightDirs = Vector4(-0.577f, 0.577f, -0.577f, 1.0f);
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable(GL_DEPTH_TEST);
mEffect.Enable();
gModel.Draw(*this);
glBindFramebuffer(GL_READ_FRAMEBUFFER, mFramebuffer);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
if(mPostFXEnabled)
{
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glDisable(GL_DEPTH_TEST);
mPostProcessEffect.Enable();
//Make the colour and depth buffers available to shaders.
glBindTexture(GL_TEXTURE_2D, mColTex);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
mPostProcessEffect.SetTexture("g_txColourBuffer", 0);
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, mDepthTex);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glActiveTexture(GL_TEXTURE0);
mPostProcessEffect.SetTexture("g_txDepthBuffer", 1);
//Draw post processing quad.
glBindVertexArray(mPostFXVAO);
glEnableVertexAttribArray(0);
glDisableVertexAttribArray(1);
glDisableVertexAttribArray(2);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mPostFXIndexBuffer);
glBindBuffer(GL_ARRAY_BUFFER, mPostFXVertexBuffer);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(PostProcessVertex), 0);
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
}
else
{
glBindFramebuffer(GL_READ_FRAMEBUFFER, mFramebuffer);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
glBlitFramebuffer(0, 0, WindowWidth, WindowHeight,
0, 0, WindowWidth, WindowHeight,
GL_COLOR_BUFFER_BIT, GL_NEAREST);
}
}
示例6: main
int main(int , char**)
{
int width = 1280, height = 760;
Display mainWindow(width, height, "DEngine");
//mainWindow.ShowCursor(false);
mainWindow.WrapMouse(false);
glm::vec3 lightPosition(-4.0f, 8.0f, -6.0f);
Light sun(lightPosition, glm::vec3(1.0f, 1.0f, 1.0f), DIRECTIONAL_LIGHT);
Camera camera(glm::vec3(0.0f, 2.0f, 1.0f));
camera.SetCameraMode(FLY);
Shader simpleProgram;
simpleProgram.LoadShaders("./SHADERS/SOURCE/NoNormal_vs.glsl",
"./SHADERS/SOURCE/NoNormal_fs.glsl");
Shader skyBoxShaders;
skyBoxShaders.LoadShaders("./SHADERS/SOURCE/skyBox_vs.glsl",
"./SHADERS/SOURCE/skyBox_fs.glsl");
Shader shadowShaders;
shadowShaders.LoadShaders("./SHADERS/SOURCE/ShadowDepth_vs.glsl",
"./SHADERS/SOURCE/ShadowDepth_fs.glsl");
EventListener eventListener(&mainWindow, &camera, &simpleProgram);
SkyBox sky;
sky.LoadCubeMap("./Models/skybox");
Model box;
box.LoadModelFromFile(".\\Models\\Box.obj");
box.TranslateModel(glm::vec3(0.0f, 2.0f, 0.0f));
box.meshes[0].AddTexture("./Models/textures/154.png", textureType::DIFFUSE_MAP);
box.meshes[0].AddTexture("./Models/textures/154_norm.png", textureType::NORMAL_MAP);
box.meshes[0].AddTexture("./Models/textures/154s.png", textureType::SPECULAR_MAP);
box.TranslateModel(glm::vec3(0.0f, -0.5f, -2.0f));
Model floor;
floor.LoadModelFromFile("./Models/Plane/plane.obj");
floor.meshes[0].AddTexture("./Models/textures/196.png", textureType::DIFFUSE_MAP);
floor.meshes[0].AddTexture("./Models/textures/196_norm.png", textureType::NORMAL_MAP);
floor.meshes[0].AddTexture("./Models/textures/196s.png", textureType::SPECULAR_MAP);
floor.TranslateModel(glm::vec3(0.0f, -2.0f, 0.0f));
Clock clock;
while (!mainWindow.isClosed)
{
eventListener.Listen();
clock.NewFrame();
//DRAWING SCENE TO SHADOWMAP
//sun.StartDrawingShadows(shadowShaders.programID);
//
//glCullFace(GL_FRONT);
////nanosuit.Draw(&mainWindow, camera, &sun, shadowShaders);
//box.Draw(&mainWindow, camera, &sun, shadowShaders);
//floor.Draw(&mainWindow, camera, &sun, shadowShaders);
//
//sun.StopDrawingShadows();
//
//glCullFace(GL_BACK);
//glViewport(0, 0, width, height);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
//NORMAL DRAWING SCENE
simpleProgram.UseProgram();
glUniformMatrix4fv(glGetUniformLocation(simpleProgram.programID, "lightSpaceMatrix"), 1, GL_FALSE, glm::value_ptr(sun.shadowMatrix));
glUniform1f(glGetUniformLocation(simpleProgram.programID, "time"), clock.time);
//glActiveTexture(GL_TEXTURE15);
//glBindTexture(GL_TEXTURE_2D, sun.shadowTexture.textureID);
//glUniform1i(glGetUniformLocation(simpleProgram.programID, "depth_map"), 15);
floor.Draw(&mainWindow, camera, &sun, simpleProgram);
box.Draw(&mainWindow, camera, &sun, simpleProgram);
//sky.Draw(&mainWindow, camera, skyBoxShaders);
camera.Update(clock.deltaTime);
mainWindow.Update();
}
return 0;
}
示例7: Run
void App::Run() {
if(SDL_Init(SDL_INIT_EVERYTHING) < 0){
logger << "SDL init failed";
throw 0;
}
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2);
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_DEBUG_FLAG);
constexpr u32 WindowWidth = 800;
constexpr u32 WindowHeight = 600;
window = SDL_CreateWindow("Cube mapping",
SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, WindowWidth, WindowHeight, SDL_WINDOW_OPENGL);
if(!window) {
logger << "Window create failed";
throw 0;
}
glctx = SDL_GL_CreateContext(window);
if(!glctx) {
logger << "OpenGL context creation failed";
throw 0;
}
u32 vao;
glGenVertexArrays(1, &vao);
glBindVertexArray(vao);
glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB);
glDebugMessageCallbackARB(DebugCallback, nullptr);
glClearColor(0.05,0.05,0.05,0);
ShaderProgram forwardProgram{};
ShaderProgram bufferProgram{};
ShaderProgram deferProgram{};
{ Shader vsh{"shaders/forward.vs"};
Shader fsh{"shaders/forward.fs"};
vsh.Compile();
fsh.Compile();
forwardProgram.Attach(vsh);
forwardProgram.Attach(fsh);
forwardProgram.Link();
forwardProgram.Use();
}
{ Shader vsh{"shaders/buffer.vs"};
Shader fsh{"shaders/buffer.fs"};
Shader defersh{"shaders/deferred.fs"};
vsh.Compile();
fsh.Compile();
bufferProgram.Attach(vsh);
bufferProgram.Attach(fsh);
bufferProgram.Link();
defersh.Compile();
deferProgram.Attach(vsh);
deferProgram.Attach(defersh);
deferProgram.Link();
}
u32 forwardFBO, lightFBO;
u32 fbTargets[4] {0};
{ u32 fbTargetTypes[4] {GL_RGBA8, GL_RGBA32F, GL_RGBA8, GL_DEPTH_COMPONENT24};
u32 fbTargetFormats[4] {GL_RGBA, GL_RGB, GL_RGB, GL_DEPTH_COMPONENT};
u32 fbTargetAttach[4] {GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2, GL_DEPTH_ATTACHMENT};
glGenFramebuffers(1, &forwardFBO);
glBindFramebuffer(GL_FRAMEBUFFER, forwardFBO);
glDrawBuffers(3, fbTargetAttach);
glGenTextures(4, fbTargets);
for(u32 i = 0; i < 4; i++) {
glBindTexture(GL_TEXTURE_2D, fbTargets[i]);
glTexImage2D(GL_TEXTURE_2D, 0, fbTargetTypes[i], WindowWidth, WindowHeight, 0, fbTargetFormats[i], GL_UNSIGNED_BYTE, nullptr);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glFramebufferTexture2D(GL_FRAMEBUFFER, fbTargetAttach[i], GL_TEXTURE_2D, fbTargets[i], 0);
}
}
u32 lightDepthBuffer;
glGenFramebuffers(1, &lightFBO);
glBindFramebuffer(GL_FRAMEBUFFER, lightFBO);
glGenTextures(1, &lightDepthBuffer);
glBindTexture(GL_TEXTURE_2D, lightDepthBuffer);
//.........这里部分代码省略.........
示例8: Draw
void World::Draw()
{
Renderer::BeginFrame();
// Set shader to use
glUseProgram(Renderer::GetShaderProgramID());
// This looks for the MVP Uniform variable in the Vertex Program
GLuint VPMatrixLocation = glGetUniformLocation(Renderer::GetShaderProgramID(), "ViewProjectionTransform");
GLuint WorldMatrixID = glGetUniformLocation(Renderer::GetShaderProgramID(), "WorldTransform");
GLuint ViewMatrixID = glGetUniformLocation(Renderer::GetShaderProgramID(), "ViewTransform");
GLuint ProjMatrixID = glGetUniformLocation(Renderer::GetShaderProgramID(), "ProjectionTransform");
SetLighting();
SetCoefficient();
// Send the view projection constants to the shader
mat4 VP = mCamera[mCurrentCamera]->GetViewProjectionMatrix();
mat4 View = mCamera[mCurrentCamera]->GetViewMatrix();
glm::mat4 World(1.0f);
mat4 Projection = mCamera[mCurrentCamera]->GetProjectionMatrix();
glUniformMatrix4fv(VPMatrixLocation, 1, GL_FALSE, &VP[0][0]);
glUniformMatrix4fv(WorldMatrixID, 1, GL_FALSE, &World[0][0]);
glUniformMatrix4fv(ViewMatrixID, 1, GL_FALSE, &View[0][0]);
glUniformMatrix4fv(ProjMatrixID, 1, GL_FALSE, &Projection[0][0]);
if (mObstacles)
{
for (Obstacles::obstacle_vector_itr it = mObstacles->getObstacles().begin(); it != mObstacles->getObstacles().end(); ++it)
{
Model* model = (*it).second;
model->Draw();
}
}
// Draw models
for (vector<Model*>::iterator it = mModel.begin(); it < mModel.end(); ++it)
{
(*it)->Draw();
}
if (DRAW_BOUNDING_VOLUME) {
for (Obstacles::obstacle_vector_itr it = mObstacles->getObstacles().begin(); it != mObstacles->getObstacles().end(); ++it)
{
Model* model = (*it).second;
Model* bvm = model->GetBoundingVolumeModel();
if (bvm)
{
bvm->Draw();
}
}
for (vector<Model*>::iterator it = mModel.begin(); it < mModel.end(); ++it)
{
Model* bvm = (*it)->GetBoundingVolumeModel();
if (bvm) {
bvm->Draw();
}
}
}
if (DRAW_ANIM_PATH) {
// Draw Path Lines
// Set Shader for path lines
unsigned int prevShader = Renderer::GetCurrentShader();
Renderer::SetShader(SHADER_PATH_LINES);
glUseProgram(Renderer::GetShaderProgramID());
// Send the view projection constants to the shader
VPMatrixLocation = glGetUniformLocation(Renderer::GetShaderProgramID(), "ViewProjectionTransform");
glUniformMatrix4fv(VPMatrixLocation, 1, GL_FALSE, &VP[0][0]);
for (vector<Animation*>::iterator it = mAnimation.begin(); it < mAnimation.end(); ++it)
{
mat4 VP = mCamera[mCurrentCamera]->GetViewProjectionMatrix();
glUniformMatrix4fv(VPMatrixLocation, 1, GL_FALSE, &VP[0][0]);
(*it)->Draw();
}
for (vector<AnimationKey*>::iterator it = mAnimationKey.begin(); it < mAnimationKey.end(); ++it)
{
mat4 VP = mCamera[mCurrentCamera]->GetViewProjectionMatrix();
glUniformMatrix4fv(VPMatrixLocation, 1, GL_FALSE, &VP[0][0]);
(*it)->Draw();
}
// Restore previous shader
Renderer::SetShader((ShaderType)prevShader);
}
Renderer::CheckForErrors();
//.........这里部分代码省略.........