本文整理汇总了C++中VertexShader::load方法的典型用法代码示例。如果您正苦于以下问题:C++ VertexShader::load方法的具体用法?C++ VertexShader::load怎么用?C++ VertexShader::load使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类VertexShader
的用法示例。
在下文中一共展示了VertexShader::load方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char** argv)
{
SDL_Window* window;
SDL_GLContext ctx;
GLuint vao;
if(!initSDL(&window, &ctx) || !initGLEW())
{
return false;
}
// Create camera
Camera camera(glm::radians(60.0f),
static_cast<float>(width)/static_cast<float>(height),
0.000001f,
1000.0f);
camera.getTransform()->setPosition(0.0f,0.0f,5.0f);
VertexShader vs;
FragmentShader fs;
ShaderProgram shaderProg;
WavefrontMeshFactory factory;
Mesh* mesh = factory.load("../../wreck/assets/uvcube.obj");
if(!vs.load("../../wreck/assets/lambert.vs")) std::cout << "Vertex Shader error." << std::endl;
if(!fs.load("../../wreck/assets/lambert.fs")) std::cout << "Fragment shader error." << std::endl;
Texture texture;
texture.load("../../wreck/assets/uvpattern.dds");
Light light(glm::vec3(5.0f, 5.0f, 5.0f), glm::vec3(1.0f, 1.0f, 1.0f));
light.setIntensity(1.0f);
std::cout << "Linking..." << std::endl;
shaderProg.setVertexShader(&vs);
shaderProg.setFragmentShader(&fs);
shaderProg.link();
//glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
glEnable(GL_DEPTH_TEST);
glClearColor(0.0f, 0.0f, 0.0f, 1.0f); // Black
Uint32 ticks = SDL_GetTicks();
bool running = true;
while(running)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
SDL_Event event;
while(SDL_PollEvent(&event))
{
Uint32 elapsed = SDL_GetTicks()-ticks;
ticks = SDL_GetTicks();
switch (event.type)
{
case SDL_KEYDOWN:
keyboardCameraControl(event, camera, elapsed);
break;
case SDL_KEYUP:
// if escape is pressed, quit
if (event.key.keysym.sym == SDLK_ESCAPE)
running = false; // set status to 1 to exit main loop
break;
case SDL_MOUSEMOTION:
mouseCameraControl(event, window, camera, elapsed);
break;
case SDL_QUIT:
running = false;
break;
}
}
glm::vec3 lightPos = light.getTransform()->getPosition();
glm::vec3 lightColor = light.getColor() * light.getIntensity();
glm::vec4 diffuse = glm::vec4(1.0f, 1.0f, 1.0f, 1.0f);
glm::mat4 m = glm::mat4(1.0f);
glm::mat4 v = camera.getViewMatrix();
glm::mat4 p = camera.getProjectionMatrix();
glm::mat4 mvp = p*v*m;
// Begin drawing
shaderProg.begin();
mesh->use();
texture.use();
shaderProg.setUniformValue(0, mvp);
shaderProg.setUniformValue(1, m);
shaderProg.setUniformValue(2, v);
shaderProg.setUniformValue(3, lightPos);
shaderProg.setUniformValue(4, lightColor);
//shaderProg.setUniformValue(1, diffuse);
glDrawElements(GL_TRIANGLES, mesh->indices.size(), GL_UNSIGNED_INT, 0);
shaderProg.end();
SDL_GL_SwapWindow(window);
}
SDL_GL_DeleteContext(ctx);
//.........这里部分代码省略.........