本文整理汇总了C++中Shader::GetProgramID方法的典型用法代码示例。如果您正苦于以下问题:C++ Shader::GetProgramID方法的具体用法?C++ Shader::GetProgramID怎么用?C++ Shader::GetProgramID使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Shader
的用法示例。
在下文中一共展示了Shader::GetProgramID方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main()
{
Game game(800, 600, "Hello World", false);
Shader shader;
shader.Load("./res/shader");
Mesh mesh;
/*const GLfloat vertices[] = {
-0.5f, 0.5f, 1.0f, 1.0f, 0.0f, 0.0f, // Top-left
0.5f, 0.5f, 1.0f, 0.0f, 1.0f, 0.0f, // Top-right
0.5f, -0.5f, 1.0f, 0.0f, 0.0f, 1.0f, // Bottom-right
-0.5f, -0.5f, 1.0f, 1.0f, 1.0f, 1.0f // Bottom-left
};*/
Vertex vertices[] = { Vertex(glm::vec3(-0.5, 0.5, 1.0), glm::vec3(0.0, 1.0, 0.0)),
Vertex(glm::vec3(0.5, 0.5, 1.0), glm::vec3(1.0, 1.0, 0.0)),
Vertex(glm::vec3(0.5, -0.5, 1.0), glm::vec3(0.0, 0.0, 1.0)),
Vertex(glm::vec3(-0.5, -0.5, 1.0), glm::vec3(0.0, 0.0, 0.0)), };
///setup element array buffer
GLuint elements[] = {
0, 1, 2,
2, 3, 0,
};
GLuint ebo;
glGenBuffers(1, &ebo);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ebo);
glBufferData(GL_ELEMENT_ARRAY_BUFFER,
sizeof(elements), elements, GL_STATIC_DRAW);
cout << "Shader programID is: " << shader.GetProgramID() << endl;
mesh.Init(&vertices[0], 4, shader.GetProgramID());
GLenum errCode;
const GLubyte* errString;
errCode = glGetError();
if (errCode != GL_NO_ERROR)
{
cout << "GL error code: " << errCode << endl;
ofstream ofs;
ofs.open("glerror.txt");
ofs << errCode << endl;
ofs.close();
}
if(glIsProgram(shader.GetProgramID()) == GL_FALSE)
{
cout << "The program with id " << shader.GetProgramID() << " does not exist." << endl;
}
else
{
cout << "Shader with program id " << shader.GetProgramID() << " has been created." << endl;
}
float counter = 0.0f;
while(!game.isClosed)
{
game.PollInput();
game.GetWindow()->r = sinf(counter);
game.GetWindow()->g = cosf(counter);
game.GetWindow()->b = cosf(counter);
game.Update();
counter += 0.01f;
if(counter >= 360.0f)
{
counter = 0.0f;
}
}
glDeleteShader(shader.GetProgramID());
game.Quit();
return 0;
}
示例2: main
int main()
{
// Init GLFW
glfwInit();
// Create a GLFWwindow object that we can use for GLFW's functions
Window window = Window(WIDTH, HEIGHT, TITLE);
window.DefineViewport();
//glfwSetInputMode(window.getWindowPtr(), GLFW_CURSOR, GLFW_CURSOR_DISABLED);
/// ^(Maybe use this later)
// Callback functions
glfwSetKeyCallback(window.getWindowPtr() , key_callback);
// Init GLEW
glewExperimental = GL_TRUE;
glewInit();
// Enable alpha channel transparency
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
// Load and compile shaders to a program
Shader ShaderProgram = Shader("../deps/shaders/shadervert.vs", "../deps/shaders/shaderfrag.fs");
// Load explosion graphics
extern_Explosion.Init(ShaderProgram.GetProgramID());
// Load texture/Game objects
Texture2D texture_background1 = Texture2D("../deps/textures/backgroundSpace_01.1.png", PNG_RGB);
SpriteMap Background = SpriteMap(texture_background1, 1.0f, 1.0f, glm::vec3(0.0f, 0.0f, 0.0f), 1.0f, BACKGROUND);
Player PlayerShip;
PlayerShip.Init(moveSpeed);
Enemy Enemies;
Enemies.Init();
// Projection matrix: ortho for 2D
glm::mat4 proj = glm::ortho(0, window.getWidth(), 0, window.getHeight());
// Game loop
while (!window.ShouldClose())
{
double startFrame = glfwGetTime(); ///< for FPS limiting
// Check if any events have been activiated and call callback function (via GLFW)
glfwPollEvents();
// Clear the colorbuffer
glClearColor(0.6f, 0.8f, 0.8f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
/* Drawing */
ShaderProgram.Use();
// Background position and drawing calculations - just identity matrix
glm::mat4 model;
GLint modelLoc = glGetUniformLocation(ShaderProgram.GetProgramID(), "model");
glUniformMatrix4fv(modelLoc, 1, GL_FALSE, glm::value_ptr(model));
Background.BackgroundScroll(scrollSpeed);
Background.Draw();
Collision::EnemyHit(&PlayerShip, &Enemies);
Collision::PlayerHit(&PlayerShip, &Enemies);
Collision::ShipsCollide(&PlayerShip, &Enemies);
PlayerShip.Move(keys);
PlayerShip.AddShots(keys);
PlayerShip.Draw(ShaderProgram.GetProgramID());
Enemies.Move();
Enemies.Shoot(PlayerShip.GetPosition());
Enemies.Draw(ShaderProgram.GetProgramID());
extern_Explosion.Draw();
// FPS Calculation/Limiting
float fps = CalculateFPS();
static int printFPS = 0;
if (printFPS == 100) {
Enemies.Add(EN_0, PlayerShip.GetPosition());
Enemies.Add(EN_1, PlayerShip.GetPosition());
std::cout << fps << std::endl;
printFPS = 0;
} else {
printFPS++;
}
LimitFPS(FPS, startFrame);
if (PlayerShip.GetLives() <= 0)
{
window.Close();
}
//.........这里部分代码省略.........
示例3: _RenderMesh
void PickingRenderer::_RenderMesh( BasicObject* tempObject )
{
Transform* cameraTransform = _renderingCamera->transform;
Camera* cameraComponent = _renderingCamera->camera;
Material* material = tempObject->meshDrawing->GetMaterial();
Mesh* mesh = tempObject->meshDrawing->GetMesh();
if ( material == NULL || mesh == NULL ) return;
Shader* shader = material->GetShader();
uint programID = shader->GetProgramID( E_ShadingType::Picking );
_gl->glUseProgram( programID );
_gl->glBindBuffer( GL_ARRAY_BUFFER, mesh->GetVertexBufferID() );
_gl->glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, mesh->GetIndexBufferID() );
_gl->glEnableVertexAttribArray(0);
_gl->glVertexAttribPointer( 0, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (const GLvoid *) (offsetof(Vertex, position)) );
int worldLoc = shader->GetUniformLocation( E_ShadingType::Picking, "ME3D_world" );
int viewLoc = shader->GetUniformLocation( E_ShadingType::Picking, "ME3D_view" );
int projectionLoc = shader->GetUniformLocation( E_ShadingType::Picking, "ME3D_projection" );
int scaleMatLoc = shader->GetUniformLocation( E_ShadingType::Picking, "ME3D_scaleMat" );
int rotationMatLoc = shader->GetUniformLocation( E_ShadingType::Picking, "ME3D_rotationMat" );
int positionMatLoc = shader->GetUniformLocation( E_ShadingType::Picking, "ME3D_positionMat" );
int camRotationMatLoc = shader->GetUniformLocation( E_ShadingType::Picking, "ME3D_camRotationMat" );
int objectIndexLoc = shader->GetUniformLocation( E_ShadingType::Picking, "ME3D_uniqueIndex" );
Matrix4 worldMatrix = tempObject->transform->GetWorldMatrix();
Matrix4 viewMatrix = cameraTransform->GetViewMatrix();
Matrix4 projectionMatrix = cameraComponent->GetProjectionMatrix();
Matrix4 scaleMatrix = tempObject->transform->GetScaleMatrix();
Matrix4 rotationMatrix = tempObject->transform->GetRotationMatrix();
Matrix4 positionMatrix = tempObject->transform->GetPositionMatrix();
Matrix4 camRotationMatrix = cameraTransform->GetRotationMatrix();
_gl->glUniformMatrix4fv ( worldLoc, 1, GL_FALSE, worldMatrix.GetValuePtr() );
_gl->glUniformMatrix4fv ( viewLoc, 1, GL_FALSE, viewMatrix.GetValuePtr() );
_gl->glUniformMatrix4fv ( projectionLoc, 1, GL_FALSE, projectionMatrix.GetValuePtr() );
_gl->glUniformMatrix4fv ( scaleMatLoc, 1, GL_FALSE, scaleMatrix.GetValuePtr() );
_gl->glUniformMatrix4fv ( rotationMatLoc, 1, GL_FALSE, rotationMatrix.GetValuePtr() );
_gl->glUniformMatrix4fv ( positionMatLoc, 1, GL_FALSE, positionMatrix.GetValuePtr() );
_gl->glUniformMatrix4fv ( camRotationMatLoc, 1, GL_FALSE, camRotationMatrix.GetValuePtr() );
_gl->glUniform1i ( objectIndexLoc, tempObject->uniqueIndex );
if ( material->IsWireframe() )
{
_gl->glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
_gl->glLineWidth( material->GetLineWidth() );
_gl->glDisable( GL_CULL_FACE );
}
else
{
_gl->glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
if ( material->GetFaceCulling() == E_FaceCulling::CULL_NONE )
{
_gl->glDisable( GL_CULL_FACE );
}
else
{
_gl->glEnable(GL_CULL_FACE);
if ( material->GetFaceCulling() == E_FaceCulling::CULL_BACK )
_gl->glCullFace( GL_BACK );
if ( material->GetFaceCulling() == E_FaceCulling::CULL_FRONT )
_gl->glCullFace( GL_FRONT );
}
}
if ( mesh->GetMeshType() == E_MeshType::POLYGON )
_gl->glDrawElements( GL_TRIANGLES, mesh->GetNumIndices(), GL_UNSIGNED_INT, 0 );
else
_gl->glDrawElements( GL_LINES, mesh->GetNumIndices(), GL_UNSIGNED_INT, 0 );
// unbind
_gl->glBindBuffer( GL_ARRAY_BUFFER, 0 );
_gl->glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, 0 );
_gl->glUseProgram( 0 );
}