コード例 #1
0
ファイル: Shader.cpp プロジェクト: rawern/DirectLook
	GLuint Shader::compile(void)
	{
		// Generate vertex shader
		m_VertexShader = createShader( GL_VERTEX_SHADER, m_VertexShaderFilename.c_str() );
		if(m_VertexShader == 0)
		{
			return 0;
		}
		
		// Generate fragment shader
		m_FragmentShader = createShader( GL_FRAGMENT_SHADER, m_FragmentShaderFilename.c_str() );
		if(m_FragmentShader == 0)
		{
			return 0;
		}

		// Generate shader program
		m_ShaderProgram = createShaderProgram( m_VertexShader, m_FragmentShader );
		if(m_ShaderProgram == 0)
		{
			return 0;
		}

		// No errors
		return 1;
	}
コード例 #2
0
ファイル: lab3-6.c プロジェクト: lulzmachine/OpenGLHF
int init()
{
  // Place one-time initialization code here

  // load model
  model = loadModel("../models/various/teapot.obj");
  setModelCenter(model, 0.f, 0.f, 0.f);
  setModelRadius(model, 0.3f);

  // Create vertex shader
  GLuint vertexShader = createShaderFromFile(GL_VERTEX_SHADER, "lab3-6.vs");
  if (!vertexShader)
    return 0;

  // Create fragment shader
  GLuint fragmentShader = createShaderFromFile(GL_FRAGMENT_SHADER, "lab3-6.fs"); 
  if (!fragmentShader)
    return 0;

  // Create shader program
  shaderProgram = createShaderProgram(vertexShader, fragmentShader);
  if (!shaderProgram)
    return 0;

  shaderTimeLocation = getUniformLocation(shaderProgram, "time");
  return 1;
}
コード例 #3
0
ファイル: Shader.cpp プロジェクト: rawern/DirectLook
	GLuint Shader::reload(void)
	{
		// Loesche den Shader Code aus dem Grafikspeicher und weise allen IDs den Wert 0 zu:
		deleteShader();
		m_VertexShader   = 0;
		m_FragmentShader = 0;
		m_ShaderProgram  = 0;

		// Create vertex shader
		m_VertexShader = createShader( GL_VERTEX_SHADER, m_VertexShaderFilename.c_str() );
		if(m_VertexShader == 0)
		{
			return 0;
		}
		
		// Create fragment shader
		m_FragmentShader = createShader( GL_FRAGMENT_SHADER, m_FragmentShaderFilename.c_str() );
		if(m_FragmentShader == 0)
		{
			return 0;
		}

		// Generate shader program
		m_ShaderProgram = createShaderProgram( m_VertexShader, m_FragmentShader );
		if(m_ShaderProgram == 0)
		{
			return 0;
		}

		// No errors
		return 1;
	}
コード例 #4
0
ファイル: Shader.cpp プロジェクト: bella8905/OpenGL_Practice
// bind shaders by vertex shader file and fragment shader fie
void CShader::createShaderProgram() {
    GLint vs = -1;
    GLint gs = -1;
    GLint ts = -1;
    GLint fs = -1;

    vs = createShader( _vs.c_str(), GL_VERTEX_SHADER );
    fs = createShader( _fs.c_str(), GL_FRAGMENT_SHADER );
    assert(  vs >= 0 );
    assert(  fs >= 0 );

    if( _gs!= "" ) {
        gs = createShader( _gs.c_str(), GL_GEOMETRY_SHADER );
        assert( gs >= 0 );
    }

    // bypass tessellation shader for now
    if( _ts != "" ) {
        // ts = createShader( _ts.c_str(), gl_tessshader)
    }

    _sp = createShaderProgram( vs, gs, ts, fs );  
    
    _inited = true;
}
コード例 #5
0
	void GL2LineRenderer::initGLbuffers()
	{
		vao = new GLVAO();

		// Set up position buffer
		glGenBuffers(1, &vboPositionColorIndex);
		glBindBuffer(GL_ARRAY_BUFFER, vboPositionColorIndex);
		vao->setInterleavedPC34(vboPositionColorIndex);

		// Create shader
		shaderIndex = createShaderProgram(
			"attribute vec3 vPosition;\n"
			"attribute vec4 vColor;\n"
			"varying vec4 fColor;\n"
			"uniform mat4 uVP;\n"
			"void main() {\n"
				"gl_Position = uVP * vec4(vPosition, 1.0);\n"
				"fColor = vColor;\n"
			"}\n",

			"varying vec4 fColor;\n"
			"void main() {\n"
				"gl_FragColor = fColor;\n"
			"}\n"
		);

		shaderVPIndex = glGetUniformLocation(shaderIndex, "uVP");
	}
コード例 #6
0
ファイル: Shader.cpp プロジェクト: bella8905/OpenGL_Practice
void CShader::initSP( const std::string& t_vs, const std::string& t_fs, const std::string& t_gs, const std::string& t_ts ) {
    _vs = t_vs;
    _fs = t_fs;
    _gs = t_gs;
    _ts = t_ts;
    createShaderProgram();
}
コード例 #7
0
    void initializeGL()
    {
        QOpenGLFunctions::initializeOpenGLFunctions();
        createShaderProgram(); m_pgm.bind();

        // Set lighting information
        m_pgm.setUniformValue("lightSource.ambient",  QVector3D( 0.0f, 0.0f, 0.0f )); // opengl fixed-function default
        m_pgm.setUniformValue("lightSource.diffuse",  QVector3D( 1.0f, 1.0f, 1.0f )); // opengl fixed-function default
        m_pgm.setUniformValue("lightSource.specular", QVector3D( 1.0f, 1.0f, 1.0f )); // opengl fixed-function default
        m_pgm.setUniformValue("lightSource.position", QVector3D( 1.0f, 1.0f, 1.0f )); // NOT DEFAULT VALUE
        m_pgm.setUniformValue("lightModel.ambient",   QVector3D( 0.2f, 0.2f, 0.2f )); // opengl fixed-function default
        m_pgm.setUniformValue("material.emission",    QVector3D( 0.0f, 0.0f, 0.0f )); // opengl fixed-function default
        m_pgm.setUniformValue("material.specular",    QVector3D( 1.0f, 1.0f, 1.0f )); // NOT DEFAULT VALUE
        m_pgm.setUniformValue("material.shininess",   10.0f);                         // NOT DEFAULT VALUE
        createGeometry();

        m_view.setToIdentity();
        glEnable(GL_DEPTH_TEST);
        glEnable(GL_TEXTURE_2D);

        glActiveTexture(GL_TEXTURE0);
        m_pgm.setUniformValue("texUnit", 0);
        createTexture();

        glClearColor(.5f,.5f,.5f,1.f);
    }
コード例 #8
0
ファイル: Program.c プロジェクト: Dimitryk/repo
void init(void){
	gouraudShading = createShaderProgram("vertexShaderSource.vert","fragmentShaderSource.frag", g_projectionBlockIndex);
	if(gouraudShading->linkStatus == GL_FALSE)
		exit(0);
	initWireRect();

	setPrespectiveProjection();
	genUniformBuffer();

	loadLights();

	gLoadIdentity();
	gSaveTop(orientationMatrix);

	glEnable(GL_CULL_FACE);
	glCullFace(GL_BACK);
	glFrontFace(GL_CCW);

	glEnable(GL_DEPTH_TEST);
	glDepthMask(GL_TRUE);
	glDepthFunc(GL_LEQUAL);
	glDepthRange(0.0f, 1.0f);
	glEnable(GL_DEPTH_CLAMP);

	objectsArray = (meshObject**)malloc(sizeof(meshObject*) * MAX_OBJECTS);
	loadPointMeshFile();
	loadPointMeshFile();
	userDefinedSegmentVertex = createArrayListf();
	userDefinedSegmentColor = createArrayListui();
	setMarkingColor();
}
コード例 #9
0
ファイル: Manager.cpp プロジェクト: JoaoLReis/OpenGL
Manager::Manager()
{
	camera = new Camera();
	camera->setPerspective(tFOVY, WINDOW_WIDTH / WINDOW_HEIGHT, tNEAR, tFAR);
	camera->setCenter(glm::vec3(-NUMTILESX / 2, -NUMTILESY / 2, -40.0f));
	camera->updateCamera();
	mapList = new std::vector<Scene*>;
	preloadedObjs = new std::vector<Piece*>;
	PieceReader::getInstance().init();
	ShaderProgram* sh = createShaderProgram("..\\shaders\\vertex_shader.glsl", "..\\shaders\\fragment_shader.glsl");
	ShaderProgram* sh2D = createShaderProgram("..\\shaders\\vertex_shader_2d.glsl", "..\\shaders\\fragment_shader_2d.glsl");
	starter = 0;
	obj = 0;
	initInterface(sh2D);
	initMapList(sh);
	preLoadPieces(sh);
}
コード例 #10
0
ファイル: cpbox.cpp プロジェクト: ComputationalPhysics/waves
void CPBox::ensureInitialized()
{
    if(!m_funcs) {
        m_funcs = new QOpenGLFunctions(QOpenGLContext::currentContext());
        generateVBOs();
        createShaderProgram();
    }
}
コード例 #11
0
ContentLayerChromium::SharedValues::SharedValues(GraphicsContext3D* context)
    : m_context(context)
    , m_contentShaderProgram(0)
    , m_shaderSamplerLocation(-1)
    , m_shaderMatrixLocation(-1)
    , m_shaderAlphaLocation(-1)
    , m_initialized(false)
    , m_npotSupported(false)
{
    // Shaders for drawing the layer contents.
    char vertexShaderString[] =
        "attribute vec4 a_position;   \n"
        "attribute vec2 a_texCoord;   \n"
        "uniform mat4 matrix;         \n"
        "varying vec2 v_texCoord;     \n"
        "void main()                  \n"
        "{                            \n"
        "  gl_Position = matrix * a_position; \n"
        "  v_texCoord = a_texCoord;   \n"
        "}                            \n";

    // Note differences between Skia and Core Graphics versions:
    //  - Skia uses BGRA
    //  - Core Graphics uses RGBA
    char fragmentShaderString[] =
        "precision mediump float;                            \n"
        "varying vec2 v_texCoord;                            \n"
        "uniform sampler2D s_texture;                        \n"
        "uniform float alpha;                                \n"
        "void main()                                         \n"
        "{                                                   \n"
        "  vec4 texColor = texture2D(s_texture, v_texCoord); \n"
#if PLATFORM(SKIA)
        "  gl_FragColor = vec4(texColor.z, texColor.y, texColor.x, texColor.w) * alpha; \n"
#elif PLATFORM(CG)
        "  gl_FragColor = vec4(texColor.x, texColor.y, texColor.z, texColor.w) * alpha; \n"
#else
#error "Need to implement for your platform."
#endif
        "}                                                   \n";

    m_contentShaderProgram = createShaderProgram(m_context, vertexShaderString, fragmentShaderString);
    if (!m_contentShaderProgram) {
        LOG_ERROR("ContentLayerChromium: Failed to create shader program");
        return;
    }

    m_shaderSamplerLocation = m_context->getUniformLocation(m_contentShaderProgram, "s_texture");
    m_shaderMatrixLocation = m_context->getUniformLocation(m_contentShaderProgram, "matrix");
    m_shaderAlphaLocation = m_context->getUniformLocation(m_contentShaderProgram, "alpha");
    ASSERT(m_shaderSamplerLocation != -1);
    ASSERT(m_shaderMatrixLocation != -1);
    ASSERT(m_shaderAlphaLocation != -1);

    m_npotSupported = GLC(context, context->getString(GraphicsContext3D::EXTENSIONS).contains("GL_OES_texture_npot"));

    m_initialized = true;
}
コード例 #12
0
void intro_init( void )
{
	initGLTools();

	// create noise Texture
#ifdef FLOAT_TEXTURE
	for (int i = 0; i < NOISE_TEXTURE_SIZE * NOISE_TEXTURE_SIZE * NOISE_TEXTURE_SIZE * 4; i++)
	{
		noiseData[i] = frand() - 0.5f;
	}
#else
	for (int i = 0; i < NOISE_TEXTURE_SIZE * NOISE_TEXTURE_SIZE * NOISE_TEXTURE_SIZE * 4; i++)
	{
		noiseData[i] = (unsigned char)rand();
	}
#endif

	// Create and link shader and stuff:
	// I will have to separate these to be able to use more than one shader...
	// TODO: I should make some sort of compiling and linking loop...
	
	if (!createShaderProgram("vertex.glsl", NULL, "fragment.glsl",
						     &(shaderPrograms[0])))
	{
		return;
	}

	// Set texture.
	glEnable(GL_TEXTURE_3D); // automatic?
	glGenTextures(1, &noiseTexture);
	glBindTexture(GL_TEXTURE_3D, noiseTexture);
	glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_REPEAT);
	glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_REPEAT);
	glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_REPEAT);
	//glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, NOISE_TEXTURE_SIZE, NOISE_TEXTURE_SIZE, NOISE_TEXTURE_SIZE, 0, GL_RGBA, 
	//	         GL_UNSIGNED_BYTE, noiseData);
#ifdef FLOAT_TEXTURE
	glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA32F,
				 NOISE_TEXTURE_SIZE, NOISE_TEXTURE_SIZE, NOISE_TEXTURE_SIZE,
				 0, GL_RGBA, GL_FLOAT, noiseData);
#else
	glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8,
				 NOISE_TEXTURE_SIZE, NOISE_TEXTURE_SIZE, NOISE_TEXTURE_SIZE,
				 0, GL_RGBA, GL_UNSIGNED_BYTE, noiseData);
#endif

	// Create vertex buffer object
	glGenBuffers(1, &vertexBufferID);
	glBindBuffer(GL_ARRAY_BUFFER, vertexBufferID);

	// RLY?
	//glEnable(GL_CULL_FACE);

	// Initialize the singleton particle system.
	particleSystem.init();
}
コード例 #13
0
ファイル: ShaderLibTests.cpp プロジェクト: NCCA/NGL
TEST(ShaderLib,loadPartsFailFragment)
{
  auto shader = ngl::ShaderLib::instance();
  shader->createShaderProgram("Test4",ngl::ErrorExit::OFF);
  constexpr auto Fragment="Test4Frag";
  shader->attachShader( Fragment, ngl::ShaderType::FRAGMENT ,ngl::ErrorExit::OFF);
  shader->loadShaderSource(Fragment,"files/fragErr.glsl");
  EXPECT_FALSE(shader->compileShader(Fragment))<<"error compiling vert shader";

}
コード例 #14
0
// the program starts here
void MainAppFunc() {
    // initialise GLFW
    if(!glfwInit())
        throw std::runtime_error("glfwInit failed");

    // open a window with GLFW
    glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
    glfwWindowHint(GLFW_RESIZABLE, GL_TRUE);
    MainWindow = glfwCreateWindow((int)SCREEN_SIZE.x, (int)SCREEN_SIZE.y,"Draw Basic Shapes",NULL,NULL);
    if(!MainWindow)
        throw std::runtime_error("glfwOpenWindow failed. Can your hardware handle OpenGL 4.2?");

    // GLFW settings
    glfwMakeContextCurrent(MainWindow);
    // initialise GLEW
    glewExperimental = GL_TRUE; //stops glew crashing on OSX :-/
    if(glewInit() != GLEW_OK)
        throw std::runtime_error("glewInit failed");

    // print out some info about the graphics drivers
    std::cout << "OpenGL version: " << glGetString(GL_VERSION) << std::endl;
    std::cout << "GLSL version: " << glGetString(GL_SHADING_LANGUAGE_VERSION) << std::endl;
    std::cout << "Vendor: " << glGetString(GL_VENDOR) << std::endl;
    std::cout << "Renderer: " << glGetString(GL_RENDERER) << std::endl;

    // make sure OpenGL version 3.2 API is available
    if(!GLEW_VERSION_4_2)
        throw std::runtime_error("OpenGL 4.2 API is not available.");

    // load vertex and fragment shaders into opengl
    //LoadShaders();
   if(!createShaderProgram())
   {
       std::cerr << "Could not create the shaders";
   }

    // create buffer and fill it with the points of the triangle
    LoadTriangle();

    // run while the window is open
    while(!glfwWindowShouldClose(MainWindow)){

        // process pending events
        glfwPollEvents();
        // draw one frame
        Render(MainWindow);
    }

    // clean up and exit
    glfwTerminate();
}
コード例 #15
0
ファイル: ShaderLibTests.cpp プロジェクト: NCCA/NGL
TEST(ShaderLib,loadPartsFailVertex)
{

  auto shader = ngl::ShaderLib::instance();
  shader->createShaderProgram("Test3",ngl::ErrorExit::OFF);
  constexpr auto Vertex="Test3Vert";
  shader->attachShader( Vertex, ngl::ShaderType::VERTEX ,ngl::ErrorExit::OFF);
  shader->loadShaderSource(Vertex,"files/vertErr.glsl");
  EXPECT_FALSE(shader->compileShader(Vertex))<<"error compiling vert shader";


}
コード例 #16
0
static void initGlObjects() {
    glGenBuffers(1, &verticesVBO);
    glBindBuffer(GL_ARRAY_BUFFER, verticesVBO);
    glBufferData(GL_ARRAY_BUFFER, 9*sizeof(float), vertices, GL_STATIC_DRAW);
    glBindBuffer(GL_ARRAY_BUFFER, 0);

    glGenBuffers(1, &verticesVBO2);
    glBindBuffer(GL_ARRAY_BUFFER, verticesVBO2);
    glBufferData(GL_ARRAY_BUFFER, 9*sizeof(float), vertices2, GL_STATIC_DRAW);
    glBindBuffer(GL_ARRAY_BUFFER, 0);

    shaderProgram = createShaderProgram(vertexShaderSrc, fragmentShaderSrc);
}
コード例 #17
0
ファイル: part1.cpp プロジェクト: klutt/datorgrafikass1
void init(void)
{
    glClearColor(0.0, 0.0, 0.0, 1.0);

    loadMesh((modelDir() + "bunny.obj"), &globals.mesh);

    std::string vshaderFilename = shaderDir() + "mesh.vert";
    std::string fshaderFilename = shaderDir() + "mesh.frag";
    createShaderProgram(vshaderFilename, fshaderFilename, &globals.program);

    createMeshVAO(globals.mesh, globals.program, &globals.meshVAO);

    initializeTrackball();
}
コード例 #18
0
ファイル: Shader.cpp プロジェクト: ryanseys/opengl-molecules
/**
 * Creates a shader program from files vsFileName and fsFileName.
 *
 * @param  vsFileName      Filename of vertex shader.
 * @param  fsFileName      Filename of fragment shader.
 * @param  shaderProgramid A handle to the shader program.
 * @return                 0 if successful !=0 if error.
 */
int Shader::createShaderProgram(char * vsFileName, char * fsFileName, unsigned int *shaderProgramid) {

  int rc = 0;

  rc = createShaderObj(vsFileName, GL_VERTEX_SHADER, &vertShaderid);
  if (rc == 0) {
    rc = createShaderObj(fsFileName, GL_FRAGMENT_SHADER, &fragShaderid);
  }
  if (rc == 0) {
    rc = createShaderProgram(vertShaderid, fragShaderid,shaderProgramid);
  }

  return(rc);
}
コード例 #19
0
ファイル: TextRenderer.cpp プロジェクト: smistad/FAST
TextRenderer::TextRenderer() {
    createInputPort<Text>(0);
    mStyle = STYLE_NORMAL;
    mPosition = POSITION_CENTER;
	mFontSize = 18;
	mColor = Color::Green();
    createStringAttribute("position", "Text position", "Position of text in view (center/bottom_left/bottom_right/top_left/top_right)", "top_left");
    createIntegerAttribute("font_size", "Font size", "Font size", mFontSize);

    createShaderProgram({
        Config::getKernelSourcePath() + "/Visualization/TextRenderer/TextRenderer.vert",
        Config::getKernelSourcePath() + "/Visualization/TextRenderer/TextRenderer.frag",
    });
}
コード例 #20
0
osg::ref_ptr<osg::Program> OSGShaderFactory::createShaderProgram( const std::string& vertexProgram, const std::string& geometryProgram, const std::string& fragmentProgram, int verticesOutEnum, int inputeTypeEnum, int outputTypeEnum )
{
    osg::ref_ptr<osg::Program> program = createShaderProgram( vertexProgram, fragmentProgram );
    
    osg::ref_ptr<osg::Shader> geometryShader = getShader( geometryProgram, osg::Shader::GEOMETRY );
    
    program->addShader( geometryShader );
    
    program->setParameter( GL_GEOMETRY_VERTICES_OUT_EXT, verticesOutEnum );
    program->setParameter( GL_GEOMETRY_INPUT_TYPE_EXT, inputeTypeEnum );
    program->setParameter( GL_GEOMETRY_OUTPUT_TYPE_EXT, outputTypeEnum );
    
    return program;
}
コード例 #21
0
ContentLayerChromium::SharedValues::SharedValues(GraphicsContext3D* context)
    : m_context(context)
    , m_contentShaderProgram(0)
    , m_shaderSamplerLocation(-1)
    , m_shaderMatrixLocation(-1)
    , m_shaderAlphaLocation(-1)
    , m_initialized(false)
{
    // Shaders for drawing the layer contents.
    char vertexShaderString[] =
        "attribute vec4 a_position;   \n"
        "attribute vec2 a_texCoord;   \n"
        "uniform mat4 matrix;         \n"
        "varying vec2 v_texCoord;     \n"
        "void main()                  \n"
        "{                            \n"
        "  gl_Position = matrix * a_position; \n"
        "  v_texCoord = a_texCoord;   \n"
        "}                            \n";

    // Color is in BGRA order.
    char fragmentShaderString[] =
        "precision mediump float;                            \n"
        "varying vec2 v_texCoord;                            \n"
        "uniform sampler2D s_texture;                        \n"
        "uniform float alpha;                                \n"
        "void main()                                         \n"
        "{                                                   \n"
        "  vec4 texColor = texture2D(s_texture, v_texCoord); \n"
        "  gl_FragColor = vec4(texColor.z, texColor.y, texColor.x, texColor.w) * alpha; \n"
        "}                                                   \n";

    m_contentShaderProgram = createShaderProgram(m_context, vertexShaderString, fragmentShaderString);
    if (!m_contentShaderProgram) {
        LOG_ERROR("ContentLayerChromium: Failed to create shader program");
        return;
    }

    m_shaderSamplerLocation = m_context->getUniformLocation(m_contentShaderProgram, "s_texture");
    m_shaderMatrixLocation = m_context->getUniformLocation(m_contentShaderProgram, "matrix");
    m_shaderAlphaLocation = m_context->getUniformLocation(m_contentShaderProgram, "alpha");
    ASSERT(m_shaderSamplerLocation != -1);
    ASSERT(m_shaderMatrixLocation != -1);
    ASSERT(m_shaderAlphaLocation != -1);

    m_initialized = true;
}
コード例 #22
0
CanvasLayerChromium::SharedValues::SharedValues()
    : m_canvasShaderProgram(0)
    , m_shaderSamplerLocation(-1)
    , m_shaderMatrixLocation(-1)
    , m_shaderAlphaLocation(-1)
    , m_initialized(false)
{
    char vertexShaderString[] =
        "attribute vec4 a_position;   \n"
        "attribute vec2 a_texCoord;   \n"
        "uniform mat4 matrix;         \n"
        "varying vec2 v_texCoord;     \n"
        "void main()                  \n"
        "{                            \n"
        "  gl_Position = matrix * a_position; \n"
        "  v_texCoord = a_texCoord;   \n"
        "}                            \n";

    // Canvas layers need to be flipped vertically and their colors shouldn't be
    // swizzled.
    char fragmentShaderString[] =
        "precision mediump float;                            \n"
        "varying vec2 v_texCoord;                            \n"
        "uniform sampler2D s_texture;                        \n"
        "uniform float alpha;                                \n"
        "void main()                                         \n"
        "{                                                   \n"
        "  vec4 texColor = texture2D(s_texture, vec2(v_texCoord.x, 1.0 - v_texCoord.y)); \n"
        "  gl_FragColor = vec4(texColor.x, texColor.y, texColor.z, texColor.w) * alpha; \n"
        "}                                                   \n";

    m_canvasShaderProgram = createShaderProgram(vertexShaderString, fragmentShaderString);
    if (!m_canvasShaderProgram) {
        LOG_ERROR("CanvasLayerChromium: Failed to create shader program");
        return;
    }

    m_shaderSamplerLocation = glGetUniformLocation(m_canvasShaderProgram, "s_texture");
    m_shaderMatrixLocation = glGetUniformLocation(m_canvasShaderProgram, "matrix");
    m_shaderAlphaLocation = glGetUniformLocation(m_canvasShaderProgram, "alpha");
    ASSERT(m_shaderSamplerLocation != -1);
    ASSERT(m_shaderMatrixLocation != -1);
    ASSERT(m_shaderAlphaLocation != -1);

    m_initialized = true;
}
コード例 #23
0
ファイル: ShaderLibTests.cpp プロジェクト: NCCA/NGL
TEST(ShaderLib,failLink)
{
  constexpr auto *shaderName="Test5";
  auto shader = ngl::ShaderLib::instance();
  shader->createShaderProgram(shaderName,ngl::ErrorExit::OFF);
  constexpr auto Vertex="Test5Vert";
  shader->attachShader( Vertex, ngl::ShaderType::VERTEX );
  shader->loadShaderSource(Vertex,"files/vertLinkErr.glsl");
  EXPECT_TRUE(shader->compileShader(Vertex))<<"error compiling vert shader";
  constexpr auto Fragment="Test5Frag";
  shader->attachShader( Fragment, ngl::ShaderType::FRAGMENT );
  shader->loadShaderSource(Fragment,"files/fragLinkErr.glsl");
  EXPECT_TRUE(shader->compileShader(Fragment))<<"error compiling vert shader";
  shader->attachShaderToProgram(shaderName,Vertex);
  shader->attachShaderToProgram(shaderName,Fragment);
  EXPECT_FALSE(shader->linkProgramObject(shaderName))<<"This should not link as in and out don't match";
}
コード例 #24
0
ファイル: shader.cpp プロジェクト: bryantcurto/disc
/*
 * INITIALIZE Shader Program
 *
 * This function reads in the source code for shaders, 
 * compiles each shader, and links the shaders into
 * a shader program.
 * ShaderException is thrown if an error occurs in any
 * of the previous steps.
 */
void shader::init() {
    QFile vertFile(vertSrcPath);
    QFile fragFile(fragSrcPath);
    
    // Test if Vertex File can be Opened
    if (!vertFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
        ShaderException exc("Failed to Open Vertex Shader File");
        throw exc;
    }
    // Test if Fragment File can be Opened
    if (!fragFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
        ShaderException exc("Failed to Open Fragment Shader File");
        throw exc;
    }
    
    // Get data from Vertex file and close
    QByteArray vertFileData = vertFile.readAll();
    vertFile.close();
    // Get data from Fragment file and close
    QByteArray fragFileData = fragFile.readAll();
    fragFile.close();
    
    // Nothing Read from Vertex Shader
    if (!vertFileData.data()) {
        ShaderException exc("Failed to Read Vertex Shader File");
        throw exc;
    }
    // Nothing Read from Fragment Shader
    if (!fragFileData.data()) {
        ShaderException exc("Failed to Read Fragment Shader File");
        throw exc;
    }

    // Otherwise, create shaders! //
    
    // Create Shaders //
    createShader(Vertex_Shader, vertexShader, vertFileData.data());
    createShader(Fragment_Shader, fragShader, fragFileData.data());
    
    // Create Program //
    createShaderProgram();
}
コード例 #25
0
PagShaderProgram::PagShaderProgram(QString name)
{
    initializeOpenGLFunctions();

    program = glCreateProgram();
    if (program == 0) {
        qDebug() << "No se puede crear el shader program";
    }

    GLuint vertexShaderObject = compileShader(":/"+name+".vert", GL_VERTEX_SHADER);
    GLuint fragmentShaderObject = compileShader(":/"+name+".frag", GL_FRAGMENT_SHADER);
    GLuint geometryShaderObject = compileShader(":/"+name+".geom", GL_GEOMETRY_SHADER);

    glAttachShader(program, vertexShaderObject);
    glAttachShader(program, fragmentShaderObject);
    glAttachShader(program, geometryShaderObject);

    shaderProgram = createShaderProgram(name, program);

}
コード例 #26
0
ファイル: TextDrawer.cpp プロジェクト: fzurita/mupen64plus-ae
void TextDrawer::init()
{
	if (m_pAtlas != nullptr)
		return;

	char strBuffer[PLUGIN_PATH_SIZE];
	const char *fontfilename;
	if (getFontFileName(strBuffer))
		fontfilename = strBuffer;
	else
		return;

	/* Initialize the FreeType2 library */
	if (FT_Init_FreeType(&ft)) {
		fprintf(stderr, "Could not init freetype library\n");
		return;
	}

	/* Load a font */
	if (FT_New_Face(ft, fontfilename, 0, &face)) {
		fprintf(stderr, "Could not open font %s\n", fontfilename);
		return;
	}

	m_program = createShaderProgram(strDrawTextVertexShader, strDrawTextFragmentShader);
	if(m_program == 0)
		return;

	m_uTex = glGetUniformLocation(m_program, "uTex");
	m_uColor = glGetUniformLocation(m_program, "uColor");

	if(m_uTex == -1 || m_uColor == -1)
		return;

	// Create the vertex buffer object
	glGenBuffers(1, &m_vbo);

	/* Create texture atlas for selected font size */
	m_pAtlas = new Atlas(face, config.font.size);
}
コード例 #27
0
SpriteBatcher::SpriteBatcher()
    : camera(NULL), vao(0), program(0), lastTexture(0), drawn(0)
{
    // Create shader program
    GLuint vertex = createShader(VERTEX_SRC, GL_VERTEX_SHADER);
    GLuint fragment = createShader(FRAGMENT_SRC, GL_FRAGMENT_SHADER);
    program = createShaderProgram(vertex, fragment);
    linkShader(program);
    validateShader(program);

    glDetachShader(program, vertex);
    glDeleteShader(vertex);
    glDetachShader(program, fragment);
    glDeleteShader(fragment);

    // Create vertex array and prepare buffers for being updated >= once per frame
    glGenVertexArrays(1, &vao);
    glGenBuffers(2, buffers);

    glBindVertexArray(vao);

    glBindBuffer(GL_ARRAY_BUFFER, buffers[VCTBO]);
    glBufferData(GL_ARRAY_BUFFER, 0, NULL, GL_DYNAMIC_DRAW);
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buffers[EBO]);
    glBufferData(GL_ELEMENT_ARRAY_BUFFER, 0, NULL, GL_DYNAMIC_DRAW);
    
    // Attributes
    glBindBuffer(GL_ARRAY_BUFFER, buffers[VCTBO]);
    glEnableVertexAttribArray(0); // position
    glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 8 * sizeof(float), (void*)0);
    glEnableVertexAttribArray(1); // color
    glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, 8 * sizeof(float), (void*)(2 * sizeof(float)));
    glEnableVertexAttribArray(2); // texture coordinates
    glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, 8 * sizeof(float), (void*)(6 * sizeof(float)));

    glBindVertexArray(0);

    glBindBuffer(GL_ARRAY_BUFFER, 0);
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
}
コード例 #28
0
ファイル: main.cpp プロジェクト: gakimaru2/public
GLuint createAndLinkShaderProgram(const GLuint vertex_shader_handle, const GLuint fragment_shader_handle)
{
	const GLuint program_handle  = createShaderProgram();
	if (program_handle == 0){ return 0; }
	
	glAttachShader(program_handle, vertex_shader_handle);
	glAttachShader(program_handle, fragment_shader_handle);

	glBindAttribLocation(program_handle, ATTRLOC_VERTEX_POSITION, "VertexPosition");
	glBindAttribLocation(program_handle, ATTRLOC_VERTEX_TEXCOORD, "TexCoord");

	glBindFragDataLocation(program_handle, FRAGLOC_COLOR, "FragColor");

	glLinkProgram(program_handle);
	{
		const GLint shader_link_result = getShaderResult(program_handle, GL_LINK_STATUS);
		if (shader_link_result == GL_FALSE){ return 0; }
	}
	
	g_UNIFORMLOC_BLOCK = glGetUniformBlockIndex(program_handle, "BlobSettings");
	if (g_UNIFORMLOC_BLOCK != INVALID_LOC)
	{
		glGetActiveUniformBlockiv(program_handle, g_UNIFORMLOC_BLOCK, GL_UNIFORM_BLOCK_DATA_SIZE, &g_UNIFORM_BLOCK_SIZE);
		if (g_UNIFORM_BLOCK_SIZE > 0)
		{
			g_UNIFORM_BLOCK_BUFF = new GLubyte[g_UNIFORM_BLOCK_SIZE];
			const GLchar* names[] = { "InnerColor", "OuterColor", "RadiusInner", "RadiusOuter" };
			const GLint name_num = countof(names);
			GLuint indices[name_num];
			glGetUniformIndices(program_handle, name_num, names, indices);
			glGetActiveUniformsiv(program_handle, name_num, indices, GL_UNIFORM_OFFSET, g_UNIFORM_BLOCK_OFFSET);
			
			glGenBuffers(1, &g_UNIFORM_HANDLE);
			glBindBuffer(GL_UNIFORM_BUFFER, g_UNIFORM_HANDLE);
		}
	}

	return program_handle;
}
コード例 #29
0
ファイル: main.cpp プロジェクト: gakimaru2/public
GLuint createAndLinkShaderProgram(const GLuint vertex_shader_handle, const GLuint fragment_shader_handle)
{
	const GLuint program_handle  = createShaderProgram();
	if (program_handle == 0){ return 0; }
	
	glAttachShader(program_handle, vertex_shader_handle);
	glAttachShader(program_handle, fragment_shader_handle);

	glBindAttribLocation(program_handle, ATTRLOC_VERTEX_POSITION, "VertexPosition");
	glBindAttribLocation(program_handle, ATTRLOC_VERTEX_COLOR, "VertexColor");

	glBindFragDataLocation(program_handle, FRAGLOC_COLOR, "FragColor");

	glLinkProgram(program_handle);
	{
		const GLint shader_link_result = getShaderResult(program_handle, GL_LINK_STATUS);
		if (shader_link_result == GL_FALSE){ return 0; }
	}
	
	g_UNIFORMLOC_ROTATION_MAT = glGetUniformLocation(program_handle, "RotationMatrix");
	
	return program_handle;
}
コード例 #30
0
ファイル: ShaderLibTests.cpp プロジェクト: NCCA/NGL
TEST(ShaderLib,editShader)
{

  auto shader = ngl::ShaderLib::instance();
  auto *shaderName="Edit";

  shader->createShaderProgram(shaderName,ngl::ErrorExit::OFF);
  constexpr auto Vertex="EditVert";
  shader->attachShader( Vertex, ngl::ShaderType::VERTEX ,ngl::ErrorExit::OFF);
  shader->loadShaderSource(Vertex,"files/EditVert.glsl");
  EXPECT_TRUE(shader->editShader(Vertex,"@breakMe","1.0"))<<"edit shader set breakMe ";
  EXPECT_TRUE(shader->editShader(Vertex,"@numLights","2"))<<"edit shader";
  EXPECT_TRUE(shader->compileShader(Vertex))<<"error compiling vert shader";
  constexpr auto Fragment="EditFrag";
  shader->attachShader( Fragment, ngl::ShaderType::FRAGMENT,ngl::ErrorExit::OFF );
  shader->loadShaderSource(Fragment,"files/EditFrag.glsl");
  EXPECT_TRUE(shader->editShader(Fragment,"@numLights","2"))<<"edit shader";
  EXPECT_TRUE(shader->compileShader(Fragment))<<"error compiling vert shader";
  shader->attachShaderToProgram(shaderName,Vertex);
  shader->attachShaderToProgram(shaderName,Fragment);
  EXPECT_TRUE(shader->linkProgramObject(shaderName))<<"First Link";
  (*shader)[shaderName]->use();
  EXPECT_TRUE(shader->getCurrentShaderName()==shaderName);
  // Now re-edit
  shader->resetEdits(Vertex);
  shader->resetEdits(Fragment);
  EXPECT_TRUE(shader->editShader(Vertex,"@numLights","5"))<<"edit shader 2nd";
  EXPECT_TRUE(shader->editShader(Vertex,"@breakMe","1.0"))<<"edit shader set breakMe 2nd";
  EXPECT_TRUE(shader->editShader(Fragment,"@numLights","5"))<<"edit shader";
  EXPECT_TRUE(shader->compileShader(Vertex))<<"error compiling vert shader";
  EXPECT_TRUE(shader->compileShader(Fragment))<<"error compiling vert shader";
  EXPECT_TRUE(shader->linkProgramObject(shaderName));




}