当前位置: 首页>>代码示例>>C++>>正文


C++ GLShader类代码示例

本文整理汇总了C++中GLShader的典型用法代码示例。如果您正苦于以下问题:C++ GLShader类的具体用法?C++ GLShader怎么用?C++ GLShader使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了GLShader类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: GEng

/**
* Prepare to run the intro
**/
void Intro::doit()
{
	GLShader *shader;

	if (sg->music != NULL) {
		GEng()->audio->playSong(sg);
	}

	start = SDL_GetTicks();
	lasttime = 0;

	CHECK_OPENGL_ERROR

	// Find 'basic' shader
	map<int, GLShader*>::const_iterator pos = render->shaders.find(SHADER_BASIC);
	if (pos == render->shaders.end()) {
		assert(false);
	} else {
		shader = pos->second;
	}

	// Set shader and uniforms
	glUseProgram(shader->p());
	glm::mat4 projection = glm::ortho<float>(
		0.0f, static_cast<float>(this->render->getWidth()),
		static_cast<float>(this->render->getHeight()), 0.0f,
		1.0f, -1.0f
	);
	glUniformMatrix4fv(shader->uniform("uMVP"), 1, GL_FALSE, &projection[0][0]);
	glUniform1i(shader->uniform("uTex"), 0);

	CHECK_OPENGL_ERROR

	this->updateUI();
}
开发者ID:TheJosh,项目名称:chaotic-rage,代码行数:38,代码来源:intro.cpp

示例2: detachShaders

  bool Shader::compile (ShaderType::Enum target, const CharString &source)
  {
    //Make sure old shaders are detached
    detachShaders();

    //Create a new shader
    GLShader *shader = new GLShader;
    shader->create( target );

    //Add to shader list
    switch (target) {
    case ShaderType::Vertex:
      vertShaders.pushBack( shader ); break;
    case ShaderType::Fragment:
      fragShaders.pushBack( shader ); break; }

    //Compile the source
    bool status = shader->compile( source );

    if (status)
      printf( "%s shader compiled.\n",
        target == ShaderType::Vertex ? "Vertex" : "Fragment" );
    else
      printf( "Failed compiling %s shader!",
        target == ShaderType::Vertex ? "vertex" : "fragment" );

    CharString infoLog = shader->getInfoLog ();
    if (infoLog.length() > 0)
      printf ("Info Log:\n%s\n", infoLog.buffer());

    return status;
  }
开发者ID:ileben,项目名称:GameEngine,代码行数:32,代码来源:geShader.cpp

示例3: Draw

void GLEmitter::Draw(RenderPhase phase, GLShader& shader) const
{
	if(materialPhase != phase) return;

	BufferData();

	shader.Bind();
	shader.SetTexture(0, texture);

	glBindBuffer(GL_ARRAY_BUFFER, buffers[0]);
	glVertexAttribPointer(shader.attributeLocations[0], 4, GL_FLOAT, GL_FALSE, 4 * 10, 0);
	glVertexAttribPointer(shader.attributeLocations[1], 4, GL_FLOAT, GL_FALSE, 4 * 10, (GLvoid*)(4 * 4));
	glVertexAttribPointer(shader.attributeLocations[2], 2, GL_FLOAT, GL_FALSE, 4 * 10, (GLvoid*)(8 * 4));

	glEnableVertexAttribArray(shader.attributeLocations[0]);
	glEnableVertexAttribArray(shader.attributeLocations[1]);
	glEnableVertexAttribArray(shader.attributeLocations[2]);

	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buffers[1]);

	glDrawElements(GL_TRIANGLES, 6 * numParticles, GL_UNSIGNED_SHORT, 0);

	glDisableVertexAttribArray(shader.attributeLocations[0]);
	glDisableVertexAttribArray(shader.attributeLocations[1]);
	glDisableVertexAttribArray(shader.attributeLocations[2]);

	glBindBuffer(GL_ARRAY_BUFFER, 0);
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);

	glUseProgram(0);
}
开发者ID:Vavassor,项目名称:meteor,代码行数:31,代码来源:GLEmitter.cpp

示例4: initialize

void GLConstantBuffer::initialize(const GLShader& shader, GLuint bindingPoint, const char* blockName, GLenum drawUsage)
{
	m_drawUsage = drawUsage;
	m_bindingPoint = bindingPoint;

	m_uboIndex = glGetUniformBlockIndex(shader.getID(), blockName);
	assert(m_uboIndex != GL_INVALID_INDEX);
	if (m_uboIndex == GL_INVALID_INDEX)
		return;

	if (m_ubo)
		glDeleteBuffers(1, &m_ubo);

	CHECK_GL_ERROR();
	glGenBuffers(1, &m_ubo);
	glBindBuffer(GL_UNIFORM_BUFFER, m_ubo);

	glUniformBlockBinding(shader.getID(), m_uboIndex, m_bindingPoint);
	glBindBufferBase(GL_UNIFORM_BUFFER, m_bindingPoint, m_ubo);

	glBindBuffer(GL_UNIFORM_BUFFER, 0);
	
	isInitialized = true;
	CHECK_GL_ERROR();
}
开发者ID:xoppa,项目名称:sdlgame,代码行数:25,代码来源:GLConstantBuffer.cpp

示例5: AnsiStr

bool ShaderManager::addFromFile(const char* name,
                                const AnsiStr& strVShaderFP,
                                const AnsiStr& strFShaderFP,
                                const AnsiStr& strGShaderFP) {

    AnsiStr strTitle = (name != NULL) ? AnsiStr(name) : ExtractFileTitleOnly(strVShaderFP);

    GLShader* aShader = new GLShader();
    if(aShader->compileFromFile(strVShaderFP, strFShaderFP, strGShaderFP)) {
        if(ShaderManagerParent::add(aShader, strTitle.cptr())) {
            AnsiStr strArg = TheEventLogger::Instance().shortenPathBasedOnRoot(strVShaderFP);
            vloginfo("Added Vertex-Geometry-Fragment Shader from file: %s, Name: %s.", strArg.cptr(), name);
            return true;
        }
        else {
            SAFE_DELETE(aShader);
            vlogerror("Unable to add Vertex-Geometry-Fragment Shader from file. Name: %s", name);
            return false;

        }
    }
    else {
        SAFE_DELETE(aShader);
        return false;
    }
}
开发者ID:GraphicsEmpire,项目名称:tetcutter,代码行数:26,代码来源:glshadermanager.cpp

示例6: GLShader

/**
 * Loads the vertex and fragment shader, compiles the program and returns a
 * new and ready for use GLShader* object.
 */
GLShader* GLShader::InitProgramWithShaders(const std::string& vertexShaderFile
                                         , const std::string& fragmentShaderFile)
{
    GLShader* shader = new GLShader();
    qui::VirtualFS fs;
    cpp0x::shared_ptr<char> vertexFile = fs.GetFileContentsAsText(vertexShaderFile);
    char *vertexShader = vertexFile.get();
    if (vertexShader == NULL)
    {
        LOG(FATAL) << "Vertex Shader wasn't loaded!";
    }

    GLuint vsh = qui::GLShader::LoadShader(GL_VERTEX_SHADER, vertexShader);
    cpp0x::shared_ptr<char> fragmentFile = fs.GetFileContentsAsText(fragmentShaderFile);
    char *fragmentShader = fragmentFile.get();
    if (fragmentShader == NULL)
    {
        LOG(FATAL) << "Fragment Shader wasn't loaded!";
    }
    GLuint fsh = qui::GLShader::LoadShader(GL_FRAGMENT_SHADER, fragmentShader);
    shader->SetVertexShader(vsh);
    shader->SetFragmentShader(fsh);
    shader->CreateProgramAndAttachShaders();
    shader->Compile();
    return shader;
}
开发者ID:amogos,项目名称:tests,代码行数:30,代码来源:GLShader.cpp

示例7: glCreateProgram

    GLProgram::GLProgram(const GLShader& shader1, const GLShader& shader2)
    {
        FZ_ASSERT(shader1.getShaderType() != shader2.getShaderType(), "Shader's types must be different.");
        m_program = glCreateProgram();

        glAttachShader(m_program, shader1.getShader());
        glAttachShader(m_program, shader2.getShader());
        CHECK_GL_ERROR_DEBUG();
    }
开发者ID:bambamyi,项目名称:FORZE2D,代码行数:9,代码来源:FZGLProgram.cpp

示例8: vertices

/**
 * Constructor.
 */
GLVertexBufferObject::GLVertexBufferObject(GLShader& shader
                                         , GLTexture* texture)
    : vertices(nullptr)
    , indices(nullptr)
    , vSize(0)
    , iSize(0)
    , vertexStride(vertexStride)
    , shader(shader)
    , texture(texture)
{
    shaderVertexHandle = glGetAttribLocation (shader.GetProgramObject(), qui::SHADER_VERTEX_POSITION); 
    shaderTextureHandle = glGetAttribLocation (shader.GetProgramObject(), qui::SHADER_TEXTURE_COORDS);
}
开发者ID:amogos,项目名称:tests,代码行数:16,代码来源:GLVertexBufferObject.cpp

示例9: glAssert

void BackgroundSubtractorLOBSTER_<ParallelUtils::eGLSL>::dispatch(size_t nStage, GLShader& oShader) {
    lvDbgExceptionWatch;
    glAssert(nStage<m_nComputeStages);
    if(nStage==0) {
        if(m_dCurrLearningRate>0)
            oShader.setUniform1ui("nResamplingRate",(GLuint)ceil(m_dCurrLearningRate));
        else
            oShader.setUniform1ui("nResamplingRate",BGSLOBSTER_DEFAULT_LEARNING_RATE);
    }
    else //nStage==1 && BGSLOBSTER_GLSL_USE_POSTPROC
        glMemoryBarrier(GL_SHADER_IMAGE_ACCESS_BARRIER_BIT);
    glDispatchCompute((GLuint)ceil((float)m_oFrameSize.width/m_vDefaultWorkGroupSize.x),(GLuint)ceil((float)m_oFrameSize.height/m_vDefaultWorkGroupSize.y),1);
}
开发者ID:caomw,项目名称:litiv,代码行数:13,代码来源:BackgroundSubtractorLOBSTER.cpp

示例10: SPADES_MARK_FUNCTION

		GLShader *GLProgramManager::CreateShader(const std::string &name) {
			SPADES_MARK_FUNCTION();

			SPLog("Loading GLSL shader '%s'", name.c_str());
			std::string text = FileManager::ReadAllBytes(name.c_str());
			GLShader::Type type;

			if (name.find(".fs") != std::string::npos)
				type = GLShader::FragmentShader;
			else if (name.find(".vs") != std::string::npos)
				type = GLShader::VertexShader;
			else if (name.find(".gs") != std::string::npos)
				type = GLShader::GeometryShader;
			else
				SPRaise("Failed to determine the type of a shader: %s", name.c_str());

			GLShader *s = new GLShader(device, type);

			std::string finalSource;

			if (settings.r_hdr) {
				finalSource += "#define USE_HDR 1\n";
				finalSource += "#define LINEAR_FRAMEBUFFER 1\n";
			} else {
				finalSource += "#define USE_HDR 0\n";
				finalSource += "#define LINEAR_FRAMEBUFFER 0\n";
			}
			if (settings.r_fogShadow) {
				finalSource += "#define USE_VOLUMETRIC_FOG 1\n";
			} else {
				finalSource += "#define USE_VOLUMETRIC_FOG 0\n";
			}

			if (settings.r_ssao) {
				finalSource += "#define USE_SSAO 1\n";
			} else {
				finalSource += "#define USE_SSAO 0\n";
			}

			finalSource += text;

			s->AddSource(finalSource);

			Stopwatch sw;
			s->Compile();
			SPLog("Successfully compiled GLSL program '%s' in %.3fms", name.c_str(), // should this be "program" or "shader"?
			      sw.GetTime() * 1000.);
			return s;
		}
开发者ID:Rootmars,项目名称:openspades,代码行数:49,代码来源:GLProgramManager.cpp

示例11: render_text

void GLFont::render_text(GLShader& shader, const string& text, float x, float y, float scale, const Color& color)
{
    // Activate corresponding render state
    shader.bind();

    vec4f rgba = color.toVec4f();
    glUniform3f(glGetUniformLocation(shader.program(), "textColor"), rgba.x, rgba.y, rgba.z);
    glActiveTexture(GL_TEXTURE0);
    glBindVertexArray(m_vao);

    // Iterate through all characters
    std::string::const_iterator c;
    for (c = text.begin(); c != text.end(); c++)
    {
        Character ch = m_alphabet[*c];

        GLfloat xpos = x + ch.Bearing.x * scale;
        GLfloat ypos = y - (ch.Size.y - ch.Bearing.y) * scale;

        GLfloat w = ch.Size.x * scale;
        GLfloat h = ch.Size.y * scale;
        // Update VBO for each character
        GLfloat vertices[6][4] = {
            { xpos,     ypos + h,   0.0, 0.0 },
            { xpos,     ypos,       0.0, 1.0 },
            { xpos + w, ypos,       1.0, 1.0 },

            { xpos,     ypos + h,   0.0, 0.0 },
            { xpos + w, ypos,       1.0, 1.0 },
            { xpos + w, ypos + h,   1.0, 0.0 }
        };
        // Render glyph texture over quad
        glBindTexture(GL_TEXTURE_2D, ch.TextureID);
        // Update content of VBO memory
        glBindBuffer(GL_ARRAY_BUFFER, m_vbo);
        glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(vertices), vertices); // Be sure to use glBufferSubData and not glBufferData

        glBindBuffer(GL_ARRAY_BUFFER, 0);
        // Render quad
        glDrawArrays(GL_TRIANGLES, 0, 6);
        // Now advance cursors for next glyph (note that advance is number of 1/64 pixels)
        x += (ch.Advance >> 6) * scale; // Bitshift by 6 to get value in pixels (2^6 = 64 (divide amount of 1/64th pixels by 64 to get amount of pixels))
    }

    glBindVertexArray(0);
    glBindTexture(GL_TEXTURE_2D, 0);

    shader.unbind();
}
开发者ID:GraphicsEmpire,项目名称:tetcutter,代码行数:49,代码来源:glfont.cpp

示例12: ShaderCompileErrorCheck

		std::string ShaderCompileErrorCheck(GLShader& shader)
		{
			using namespace gl;
			using namespace std;

			GLint compiled;
			glGetShaderiv(shader, GL_LINK_STATUS, &compiled);

			if (!compiled)
			{
				string log;

				GLsizei log_size;
				glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &log_size);

				log.resize(log_size + 1);
				glGetShaderInfoLog(shader, log_size, &log_size, &log[0]);

				ON_SCOPE_EXIT([&]{ shader.Delete(); });

				return log;
			}
			
			return "success";
		}
开发者ID:HBMP,项目名称:CGSamele,代码行数:25,代码来源:glShader.cpp

示例13: drawEffectMobile

void GLRender::drawEffectMobile(GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2, const CString& key, GLfloat localTime, GLfloat worldTime) {
	GLCamera* cam = this->cameras->gui;
	cam->update();
	GLfloat* projection16fv = cam->projection16fv.v;

	GLShader* shader;
	try {
		shader = shaders->get(key);
	} catch (...) {
		return;
	}
	GLuint program = shader->program;
	GLuint uLayerProjectionMatrix = (GLuint)glGetUniformLocation(program, "uLayerProjectionMatrix");
	GLuint aVertexPosition = (GLuint)glGetAttribLocation(program, "aVertexPosition");
	GLuint aTextureCoord = (GLuint)glGetAttribLocation(program, "aTextureCoord");
	GLuint uTime = (GLuint)glGetUniformLocation(program, "uTime");
	GLuint uTexture0 = (GLuint)glGetUniformLocation(program, "uTexture0");
	GLuint uTexture1 = (GLuint)glGetUniformLocation(program, "uTexture1");
 
	static Vector<GLint> effectTexturesVector = Vector<GLint>(2);
	static GLint* effectTextures = effectTexturesVector.items();
	effectTextures[0] = uTexture0;
	effectTextures[1] = uTexture1;
	enableBlend();
	GLuint index = shader->bind(0, effectTexturesVector);
	
	glUniform2f(uTime, localTime - floorf(localTime), worldTime - floorf(worldTime));
 
	glUniformMatrix4fv(uLayerProjectionMatrix, 1, GL_FALSE, projection16fv);
 
	glBindBuffer(GL_ARRAY_BUFFER, m_squareBuffer);
	glBufferData(GL_ARRAY_BUFFER, 8 * sizeof(GLfloat), makeRect(x1, y1, x2, y2), GL_DYNAMIC_DRAW);
	glVertexAttribPointer(aVertexPosition, 2, GL_FLOAT, GL_FALSE, 0, NULL);
	glEnableVertexAttribArray(aVertexPosition);
	
	glBindBuffer(GL_ARRAY_BUFFER, m_textureBuffer);
	glBufferData(GL_ARRAY_BUFFER, 8 * sizeof(GLfloat), makeRect(0, 0, 1, 1), GL_DYNAMIC_DRAW);
	glVertexAttribPointer(aTextureCoord, 2, GL_FLOAT, GL_FALSE, 0, NULL);
	glEnableVertexAttribArray(aTextureCoord);
	
	glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
 
	glDisableVertexAttribArray(aVertexPosition);
	glDisableVertexAttribArray(aTextureCoord);
 
	cleanup(index);
}
开发者ID:Jappsy,项目名称:jappsy,代码行数:47,代码来源:uGLRender.cpp

示例14: Assert

Shader* AmjuGLOpenGLES2::LoadShader(const std::string& shaderFileName)
{
  AMJU_CALL_STACK;

  GLShader* s = new GLShader;
  // TODO Add "ogl" to shader file name
  // TODO Two separate files for frag and vertex
  if (!s->Load(shaderFileName))
  {
    std::cout << "FAILED TO LOAD SHADER!! " << shaderFileName << "\n";
    Assert(0);
    
    delete s;
    return nullptr; // new ShaderNull;
  }
  return s;
}
开发者ID:jason-amju,项目名称:amjulib,代码行数:17,代码来源:AmjuGL-OpenGLES.2.cpp

示例15: int

void ExplosionEffect::paintWindow(EffectWindow* w, int mask, QRegion region, WindowPaintData& data)
{
    // Make sure we have OpenGL compositing and the window is vidible and not a
    //  special window
    bool useshader = (mValid && mWindows.contains(w));
    if (useshader) {
        double maxscaleadd = 1.5f;
        double scale = 1 + maxscaleadd * mWindows[w];
        data.setXScale(scale);
        data.setYScale(scale);
        data.translate(int(w->width() / 2 * (1 - scale)), int(w->height() / 2 * (1 - scale)));
        data.multiplyOpacity(0.99);  // Force blending
        ShaderManager *manager = ShaderManager::instance();
        GLShader *shader = manager->pushShader(ShaderManager::GenericShader);
        QMatrix4x4 screenTransformation = shader->getUniformMatrix4x4("screenTransformation");
        manager->popShader();
        ShaderManager::instance()->pushShader(mShader);
        mShader->setUniform("screenTransformation", screenTransformation);
        mShader->setUniform("factor", (float)mWindows[w]);
        mShader->setUniform("scale", (float)scale);
        mShader->setUniform("windowSize", QVector2D(w->width(), w->height()));
        glActiveTexture(GL_TEXTURE4);
        mStartOffsetTex->bind();
        glActiveTexture(GL_TEXTURE5);
        mEndOffsetTex->bind();
        glActiveTexture(GL_TEXTURE0);
        data.shader = mShader;
    }

    // Call the next effect.
    effects->paintWindow(w, mask, region, data);

    if (useshader) {
        ShaderManager::instance()->popShader();
        glActiveTexture(GL_TEXTURE4);
        mStartOffsetTex->unbind();
        glActiveTexture(GL_TEXTURE5);
        mEndOffsetTex->unbind();
        glActiveTexture(GL_TEXTURE0);
    }
}
开发者ID:mgottschlag,项目名称:kwin-tiling,代码行数:41,代码来源:explosion.cpp


注:本文中的GLShader类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。