本文整理汇总了C++中ShaderProgram::attachShader方法的典型用法代码示例。如果您正苦于以下问题:C++ ShaderProgram::attachShader方法的具体用法?C++ ShaderProgram::attachShader怎么用?C++ ShaderProgram::attachShader使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ShaderProgram
的用法示例。
在下文中一共展示了ShaderProgram::attachShader方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(void){
WindowGL window("render2texture", 640, 480);
DriverGPU * driver = DriverGPU::get();
Texture tulipsTex("./Tulips.jpg");
Shader vShader(eShaderType::eVertexShader, "../../src/shaders/flat.vertex");
Shader sobelShader(eShaderType::eFragmentShader, "../../src/shaders/sobel.fragment");
ShaderProgram program;
program.attachShader(vShader);
program.attachShader(sobelShader);
program.link();
#if defined(_WIN32)
window.peekMessage();
double t0 = STime::get()->getTime();
drawImage(tulipsTex, program);
double t1 = STime::get()->getTime();
#endif
std::cout << "Edge detection spent " << t1 - t0 << std::endl;
window.swapBuffers();
// delete window; Class has no destructor, undefined behaviour
delete driver;
system("PAUSE");
return 0;
}
示例2: appendProgram
void SceneLoader::appendProgram(const QDomElement & programNode) {
string name, shaderUrl;
vector<string> flags;
ShaderProgram * program = new ShaderProgram();
if (programNode.hasAttribute("name"))
name = programNode.attribute("name").toStdString();
QDomElement programInfo = programNode.firstChildElement();
while (!programInfo.isNull()) {
if (programInfo.tagName() == "Shader") {
shaderUrl = programInfo.attribute("url").toStdString();
if (programInfo.hasAttribute("type")) {
QString shaderType = programInfo.attribute("type");
if (shaderType == "VERTEX_SHADER")
program->attachShader(shaderUrl, GL_VERTEX_SHADER, false);
else if (shaderType == "GEOMETRY_SHADER")
program->attachShader(shaderUrl, GL_GEOMETRY_SHADER, false);
else if (shaderType == "FRAGMENT_SHADER")
program->attachShader(shaderUrl, GL_FRAGMENT_SHADER, false);
else if (shaderType == "CONTROL_SHADER")
program->attachShader(shaderUrl, GL_TESS_CONTROL_SHADER, false);
else if (shaderType == "EVALUATION_SHADER")
program->attachShader(shaderUrl, GL_TESS_EVALUATION_SHADER, false);
} else {
if (programInfo.hasAttribute("flags")) {
flags
= splitValues<string> (programInfo.attribute(
"flags"));
program->attachVertFrag(shaderUrl, flags);
} else {
program->attachVertFrag(shaderUrl, false);
}
}
} else if (programInfo.tagName() == "Template") {
shaderUrl = programInfo.attribute("url").toStdString();
program->attachVertFrag(shaderUrl, true);
} else if (programInfo.tagName() == "Uniform") {
program->uniforms.push_back(Uniform<float> (programInfo.attribute(
"name").toStdString(), splitValues<float> (
programInfo.attribute("value"))));
} else if (programInfo.tagName() == "Uniformi") {
program->uniformsi.push_back(Uniform<int> (programInfo.attribute(
"name").toStdString(), splitValues<int> (
programInfo.attribute("value"))));
}
programInfo = programInfo.nextSiblingElement();
}
QList<string> attributes;
attributes.push_back("uv");
attributes.push_back("normal");
attributes.push_back("tangent");
program->init(attributes);
program->name = name;
SceneData::Instance().shaderPrograms.insert(name, program);
}
示例3: main
int main(void){
WindowGL window("Texture loader", 640, 480);
DriverGPU * driver = DriverGPU::get();
Shader vShader(eShaderType::eVertexShader, "../../src/shaders/flat.vertex");
Shader fShader(eShaderType::eFragmentShader, "../../src/shaders/flat.fragment");
ShaderProgram program;
program.attachShader(vShader);
program.attachShader(fShader);
program.link();
bool condition = true;
do{
#if defined(_WIN32)
window.peekMessage();
drawImage(program);
#endif
window.swapBuffers();
} while (condition);
window.hide();
#ifdef _WIN32
system("PAUSE");
#endif
// delete window; Class has no destructor, undefined behaviour
delete driver;
return 0;
}
示例4: openGLThread
void openGLThread(bool _draw, GLfloat _red) {
//WindowGL * window = WindowGL::createWindow(640, 480);
Context context;
DriverGPU *driver = DriverGPU::get();
Shader vShader(eShaderType::eVertexShader, "../../src/shaders/vTriangleShader.vertex");
Shader fShader(eShaderType::eFragmentShader, "../../src/shaders/fTriangleShader.fragment");
ShaderProgram sProgram;
sProgram.attachShader(vShader);
sProgram.attachShader(fShader);
sProgram.bindAttribute(0, "vPosition");
sProgram.link();
while(running) {
//window->peekMessage();
//window->swapBuffers();
//if (_draw)
// drawOnBuffer(640, 480, sProgram, _red);
}
delete driver;
}
示例5: makeShaderProgram
ShaderManager::ShaderProgram* ShaderManager::makeShaderProgram(const char* programName, const char* vertexShaderFile, const char* fragmentShaderFile){
//Create the shaders with filename as name
Shader* vsShader = makeShader(vertexShaderFile, Vertex, vertexShaderFile);
Shader* fsShader = makeShader(fragmentShaderFile, Fragment, fragmentShaderFile);
if( vsShader == 0 || fsShader == 0 ) return 0;
ShaderProgram* newProgram = new ShaderProgram();
shaderPrograms.insert(ShaderProgramContainer::value_type(programName, newProgram));
newProgram->attachShader(vsShader);
newProgram->attachShader(fsShader);
return newProgram;
}
示例6: main
//.........这里部分代码省略.........
}else if(argMatch(argv[i], "VolumeForces")){
output[outputLength++] = VOLUME_FORCES;
}else if(argMatch(argv[i], "NetForces")){
output[outputLength++] = NET_FORCES;
}else if(argMatch(argv[i], "Points")){
output[outputLength++] = POINTS;
}
} while(lastChar(argv[i]) == ',');
}
}
Mesh* mesh;
switch(meshType){
case TETRAHEDRON:
mesh = new TetrahedronMesh(ceil(sqrt(idealTriangleCount/4.0)));
break;
case ICOSAHEDRON:
if(idealTriangleCount <= 100){
meshFile = "models/icosa1.obj";
}else if(idealTriangleCount <= 1000){
meshFile = "models/icosa2.obj";
}else if(idealTriangleCount <= 10000){
meshFile = "models/icosa3.obj";
}else if(idealTriangleCount <= 100000){
meshFile = "models/icosa4.obj";
}else{
meshFile = "models/icosa5.obj";
}
mesh = new ExternalMesh(meshFile);
break;
default:
mesh = new ExternalMesh(meshFile);
break;
}
// visualization only applies to GPU calculation, so:
if(visualization){
SceneManager manager(&device);
CameraNode camera(&device, width, height);
camera.getTransform().setTranslation(20.0f, 20.0f, 20.0f);
manager.addNode(&camera);
ModelNode mn;
//mn.getTransform().setScale(0.025f, 0.025f, 0.025f);
mn.getTransform().setScale(scale, scale, scale);
mn.getTransform().setTranslation(0.0f, 0.0f, 0.0f);
mn.setMesh(mesh);
manager.addNode(&mn);
ShaderProgram geometryProgram;
Shader geometryVertexShader("shaders/geometry_pass.vert", VERTEX);
Shader geometryFragShader("shaders/geometry_pass.frag", FRAGMENT);
geometryProgram.attachShader(&geometryVertexShader);
geometryProgram.attachShader(&geometryFragShader);
geometryProgram.link();
manager.setGeometryProgram(&geometryProgram);
GPUEvolver evolver(mesh, 10);
while (device.run()) {
evolver.update();
evolver.synchronizeToMesh();
manager.drawAll();
device.endScene();
}
} else {
if (gpu) {
GPUEvolver evolver(mesh, 10);
evolver.setOutputFormat(output, outputLength);
std::clock_t start;
start = std::clock();
for(int i=0; i < iterations; i++){
evolver.update();
evolver.outputData();
}
if (timing){
std::cout << "Time: " << (std::clock() - start) / (double)(CLOCKS_PER_SEC / 1000) << " ms" << std::endl;
}
} else {
CPUEvolver evolver(mesh, 10);
evolver.setOutputFormat(output, outputLength);
std::clock_t start;
start = std::clock();
for(int i=0; i < iterations; i++){
evolver.update();
evolver.outputData();
}
if (timing){
std::cout << "Time: " << (std::clock() - start) / (double)(CLOCKS_PER_SEC / 1000) << " ms" << std::endl;
}
}
}
return 0;
}
示例7: appendProgram
void SceneLoader::appendProgram(const QDomElement & programNode) {
string name, shaderUrl;
vector<string> flags;
QList<string> attributes = QList<string>() << "uv" << "normal" << "tangent" << "bitangent";
if (programNode.hasAttribute("name"))
name = programNode.attribute("name").toStdString();
ShaderProgram * program = new ShaderProgram(name);
QDomElement programInfo = programNode.firstChildElement();
while (!programInfo.isNull()) {
if (programInfo.tagName() == "Shader") {
shaderUrl = programInfo.attribute("url").toStdString();
if (programInfo.hasAttribute("flags")) {
flags = splitValues<string> (programInfo.attribute("flags"));
TemplateEngine::Instance().addFlags(flags);
}
if (programInfo.hasAttribute("type")) {
QString shaderType = programInfo.attribute("type");
if (shaderType == "VERTEX_SHADER")
program->attachShader(shaderUrl, GL_VERTEX_SHADER);
else if (shaderType == "GEOMETRY_SHADER")
program->attachShader(shaderUrl, GL_GEOMETRY_SHADER);
else if (shaderType == "FRAGMENT_SHADER")
program->attachShader(shaderUrl, GL_FRAGMENT_SHADER);
else if (shaderType == "CONTROL_SHADER")
program->attachShader(shaderUrl, GL_TESS_CONTROL_SHADER);
else if (shaderType == "EVALUATION_SHADER")
program->attachShader(shaderUrl, GL_TESS_EVALUATION_SHADER);
} else {
program->attachVertFrag(shaderUrl);
}
} else if (programInfo.tagName() == "Uniform") {
program->uniforms.push_back(Uniform<float> (programInfo.attribute(
"name").toStdString(), splitValues<float> (
programInfo.attribute("value"))));
} else if (programInfo.tagName() == "Uniformi") {
program->uniformsi.push_back(Uniform<int> (programInfo.attribute(
"name").toStdString(), splitValues<int> (
programInfo.attribute("value"))));
} else if (programInfo.tagName() == "Layer") {
if (programInfo.hasAttribute("texture")) {
Texture * texture = Scene::Instance().textures.value(
programInfo.attribute("texture").toStdString());
if (Scene::Instance().textures.count(programInfo.attribute("texture").toStdString()) == 0)
LogError << "Texture "
<< programInfo.attribute("texture").toStdString()
<< " not found.";
// TODO(bmonkey): uniform name reset
LogDebug << programInfo.attribute("sampler").toStdString();
texture->name = programInfo.attribute("sampler").toStdString();
program->addTexture(texture);
}
}
programInfo = programInfo.nextSiblingElement();
}
program->init(attributes);
program->samplerUniforms();
Scene::Instance().shaders.insert(name, program);
}
示例8: main
int main(int argc, char** argv)
{
--argc;
++argv;
const int WIDTH = 800;
const int HEIGHT = 600;
/*
* Create window
*/
sf::RenderWindow window(sf::VideoMode(WIDTH, HEIGHT), "Window", sf::Style::Default, sf::ContextSettings(32));
/*
* Initialize GLEW
*/
GLenum status = glewInit();
if(status != GLEW_OK)
{
std::cerr << "[F] GLEW NOT INITIALIZED: ";
std::cerr << glewGetErrorString(status) << std::endl;
window.close();
return -1;
}
/*
* Create GUI
*/
tgui::Gui gui(window);
tgui::Gui gui2(window);
gui.setGlobalFont("fonts/DejaVuSans.ttf");
loadWidgets(gui, gui2, window);
char* args[argc + 1];
/*
* load geometry
*/
Model cube;
getArgs(argc, argv, ".obj", args);
if (!args[0])
{
std::cerr << "[F] MUST SUPPLY 1+ OBJ FILES IN COMMAND LINE ARGS <filename.obj>" << std::endl;
exit(-1);
} //if
loadGeometry(cube, args[0]);
getArgs(argc, argv, ".scale", args);
if (args[0])
{
cube.scale = glm::vec3(strtof(args[0], NULL));
} //if
else
{
cube.scale = glm::vec3(1.0f);
} //else
/*
* load shader
*/
Shader vertexShader(GL_VERTEX_SHADER);
getArgs(argc, argv, ".vs", args);
vertexShader.loadFromFile(args[0]? args[0] : ".vs");
vertexShader.compile();
Shader fragmentShader(GL_FRAGMENT_SHADER);
getArgs(argc, argv, ".fs", args);
fragmentShader.loadFromFile(args[0]? args[0] : ".fs");
fragmentShader.compile();
/*
* create program
*/
ShaderProgram program;
program.attachShader(vertexShader);
program.attachShader(fragmentShader);
program.linkProgram();
program.attachShader(vertexShader);
program.attachShader(fragmentShader);
program.linkProgram();
glEnable(GL_DEPTH_TEST);
glDepthMask(GL_TRUE);
glClearDepth(1.f);
Camera camera;
sf::Event event;
tgui::Callback callback;
Planet p(&cube);
/*
* main loop
//.........这里部分代码省略.........
示例9: engine_portal_init
void engine_portal_init(void)
{
glClearColor(0.1f, 0.2f, 0.3f, 1.0f);
const GLfloat vertices[6][2] =
{
{ -0.50, -0.50 },
{ 0.50, -0.50 },
{ 0.50, 0.50 },
{ -0.50, 0.50 }
};
const GLfloat colors[] = {
1.0, 0.0, 0.0, 1.0,
0.0, 1.0, 0.0, 1.0,
0.0, 0.0, 1.0, 1.0,
1.0, 1.0, 0.0, 1.0,
};
const GLushort vertex_indies[] = {
0, 1, 2, 0, 2, 3
};
glGenBuffers(1, &indiesBufferObject);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indiesBufferObject);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(vertex_indies), vertex_indies, GL_STATIC_DRAW);
glGenVertexArrays(1, &vertexArrayObject);
glBindVertexArray(vertexArrayObject);
glGenBuffers(1, &vertexBufferObject);
glBindBuffer(GL_ARRAY_BUFFER, vertexBufferObject);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices) + sizeof(colors), nullptr, GL_STATIC_DRAW);
glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(vertices), vertices);
glBufferSubData(GL_ARRAY_BUFFER, sizeof(vertices), sizeof(colors), colors);
ShaderElement * shaderVert = ShaderElement::createWithShaderCode(GL_VERTEX_SHADER, File::readAllText("../Shader/triangles.vert"));
if (!shaderVert->compile()) {
cout << shaderVert->getError() << endl;
cout << "Vertex Shader Compile Error" << endl;
}
ShaderElement * shaderFrag = ShaderElement::createWithShaderCode(GL_FRAGMENT_SHADER, File::readAllText("../Shader/triangles.frag"));
if (!shaderFrag->compile()) {
cout << "Fragment Shader Compile Error" << endl;
}
ShaderProgram * shaderProgram = ShaderProgram::create();
shaderProgram->attachShader(*shaderVert);
shaderProgram->attachShader(*shaderFrag);
if (!shaderProgram->linkProgram()) {
cout << "ShaderProgram Linking Error" << endl;
}
GLint uboSize;
GLuint uboIndex = glGetUniformBlockIndex(shaderProgram->programId(), "Uniforms");
GLvoid * uboData;
GLuint ubo;
if (uboIndex == GL_INVALID_INDEX) {
cout << "Uniforms Is Not Uniform Block Name" << endl;
}
glGetActiveUniformBlockiv(shaderProgram->programId(), uboIndex, GL_UNIFORM_BLOCK_DATA_SIZE, &uboSize);
uboData = (GLvoid *)malloc(uboSize);
if (uboData == nullptr) {
cout << "uboData Malloc Error" << endl;
}
enum { vTranslation, vRotation, vScale, numUniforms };
const char* uniformsNames[numUniforms] = {
"vTranslation",
"vRotation",
"vScale"
};
GLuint indices[numUniforms];
GLint sizes[numUniforms];
GLint offsets[numUniforms];
GLint types[numUniforms];
glGetUniformIndices(shaderProgram->programId(), numUniforms, uniformsNames, indices);
glGetActiveUniformsiv(shaderProgram->programId(), numUniforms, indices, GL_UNIFORM_SIZE, sizes);
glGetActiveUniformsiv(shaderProgram->programId(), numUniforms, indices, GL_UNIFORM_OFFSET, offsets);
glGetActiveUniformsiv(shaderProgram->programId(), numUniforms, indices, GL_UNIFORM_TYPE, types);
//data
GLfloat translation[3] = { 0.3f, 0.3f, 0.0f};
GLfloat rotation[3] = { 0.0f, 0.0f, 90.0f};
GLfloat scale[3] = { 0.5f, 0.8f, 0.0f};
memcpy((void *)((GLint)uboData + offsets[vTranslation]), translation, sizes[vTranslation] * ShaderProgram::TypeSize(types[vTranslation]));
//.........这里部分代码省略.........