Example #1
0
 Triangle::Triangle()
 {
     std::vector<float> positions = {
         0.0f,  0.5f,  0.0f,
         0.5f, -0.5f,  0.0f,
         -0.5f, -0.5f,  0.0f
     };
     std::vector<float> uvs = {
         0.5f,  0.0f,
         1.0f,  1.0f,
         0.0f,  1.0f
     };
     vao().addBuffer(positions, 3);
     vao().addBuffer(uvs, 2);
 }
Example #2
0
unsigned int UpdateSpecialItem(std::vector<std::shared_ptr<VisibleObject> > &objVec, Map &map,
                               const unsigned int requiredScore, ResourceManager &resMan)
{
    unsigned int score(requiredScore);
    if(score > 5000)
        score += 5000;
    else
        score *= 1.5;

    std::shared_ptr<unsigned int> texture(resMan.GetTexture("scenery2.png"));
    std::shared_ptr<unsigned int> vao(resMan.GetVao("vao bottom right"));

    for(auto & obj : objVec)
    {
        std::shared_ptr<unsigned int> objVao(obj->GetNextVao());
        if(objVao)
        {
            if(*(obj->GetTexture()) == *texture && *objVao == *vao)
            {
                obj->SwitchVaos();
                map.UpdateSpecialObj(glm::ivec2((int)obj->GetX(), (int)obj->GetY()));
                break;
            }
        }
    }
    return score;
}
Example #3
0
GLFWwindow			*setup_program(t_properties *properties)
{
	static const float	verts[] = {-1, 1, -1, -1, 1, -1, 1, 1};
	static const GLuint	inds[] = {0, 1, 3, 1, 2, 3};
	GLFWwindow			*window;

	properties->width = 1000;
	properties->height = 1000;
	window = make_glfw(properties->width, properties->height);
	glClearColor(0, 0, 0, 1);
	properties->model = vao();
	properties->verts = data_buffer((GLvoid *)verts, sizeof(verts));
	properties->indices = index_buffer((GLvoid *)inds, sizeof(inds));
	vao_add_indices(properties->model, properties->indices);
	vao_add_vdata(properties->model, properties->verts, 2, GL_FALSE);
	ft_putnbr(glGetError());
	ft_putendl(" -0");
	properties->shaders[0] = load_vertex();
	properties->shaders[1] = load_fragment(properties->map);
	properties->program = shader_program(properties->shaders, 2);
	ft_putnbr(glGetError());
	ft_putendl(" -1");
	glUseProgram(properties->program);
	glBindVertexArray(properties->model);
	glEnableVertexAttribArray(0);
	init_uniforms(properties->program);
	return (window);
}
Example #4
0
 fixie::vertex_array get_default_vertex_array(const caps& caps)
 {
     vertex_array vao(caps.max_texture_units());
     vao.vertex_attribute() = default_vertex_attribute();
     vao.normal_attribute() = default_normal_attribute();
     vao.color_attribute() = default_color_attribute();
     for_each_n<size_t>(0U, vao.texcoord_attribute_count(), [&](size_t i){ vao.texcoord_attribute(i) = default_texcoord_attribute(); });
     return vao;
 }
Example #5
0
void VertBatch::draw()
{
	// this pushes the VAO, which needs to be popped
	setupBuffers();
	ScopedVao vao( mVao );
	
	auto ctx = context();
	ctx->setDefaultShaderVars();
	ctx->drawArrays( mPrimType, 0, (GLsizei)mVertices.size() );
}
Example #6
0
void OsuVRUISlider::drawVR(Graphics *g, Matrix4 &mvp)
{
	OsuVRUIElement::drawVR(g, mvp);
	if (!m_bIsVisible) return;

	const float lineThickness = 0.0035f;

	Color color = (m_bIsCursorInside || m_bIsActive) ? 0xffffffff : 0xff666666;

	// border line mesh
	VertexArrayObject vao(Graphics::PRIMITIVE::PRIMITIVE_QUADS);

	vao.addVertex(0, 0, 0);
	vao.addVertex(lineThickness, 0, 0);
	vao.addVertex(lineThickness, -m_vSize.y, 0);
	vao.addVertex(0, -m_vSize.y, 0);

	vao.addVertex(m_vSize.x, 0, 0);
	vao.addVertex(m_vSize.x - lineThickness, 0, 0);
	vao.addVertex(m_vSize.x - lineThickness, -m_vSize.y, 0);
	vao.addVertex(m_vSize.x, -m_vSize.y, 0);

	vao.addVertex(0, 0, 0);
	vao.addVertex(m_vSize.x, 0, 0);
	vao.addVertex(m_vSize.x, -lineThickness, 0);
	vao.addVertex(0, -lineThickness, 0);

	vao.addVertex(0, -m_vSize.y, 0);
	vao.addVertex(m_vSize.x, -m_vSize.y, 0);
	vao.addVertex(m_vSize.x, -m_vSize.y + lineThickness, 0);
	vao.addVertex(0, -m_vSize.y + lineThickness, 0);

	// percentage fill mesh
	VertexArrayObject vao2(Graphics::PRIMITIVE::PRIMITIVE_QUADS);

	vao2.addVertex(0, 0, 0);
	vao2.addVertex(m_vSize.x*m_fCurPercent, 0, 0);
	vao2.addVertex(m_vSize.x*m_fCurPercent, -m_vSize.y, 0);
	vao2.addVertex(0, -m_vSize.y, 0);

	// position
	Matrix4 translation;
	translation.translate(m_vPos.x, m_vPos.y, 0);
	Matrix4 finalMVP = mvp * translation;

	// draw border line and fill
	m_vr->getShaderUntexturedGeneric()->enable();
	m_vr->getShaderUntexturedGeneric()->setUniformMatrix4fv("matrix", finalMVP);
	{
		g->setColor(color);
		g->drawVAO(&vao);
		g->drawVAO(&vao2);
	}
	m_vr->getShaderUntexturedGeneric()->disable();
}
void PointsRenderer::updateVaoAndVbo(const Cloud::Key &key, const std::shared_ptr<Cloud> &cloud) {
  auto points = cloud->point_cloud()->points;
  set_size(key, points.size());
  vbo(key)->copyData(points.size() * sizeof(Cloud::PointT), points.data());
  cinder::gl::ScopedVao svao(vao(key));
  cinder::gl::ScopedBuffer svbo(vbo(key));
  cinder::gl::enableVertexAttribArray(0);
  cinder::gl::enableVertexAttribArray(1);
  cinder::gl::vertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, sizeof(Cloud::PointT), (const GLvoid*)offsetof(Cloud::PointT, data));
  cinder::gl::vertexAttribPointer(1, 4, GL_UNSIGNED_BYTE, GL_FALSE, sizeof(Cloud::PointT), (const GLvoid*)offsetof(Cloud::PointT, rgba));
}
Example #8
0
void Particles::createBuffer(){
	float quadCentered[] = {
				-0.5f, -0.5f, 0.0f, 0.0f,
				-0.5f,  0.5f, 0.0f, 1.0f,
			  	0.5f, -0.5f, 1.0f, 0.0f,
				0.5f,  0.5f, 1.0f, 1.0f,
		};
	vao.setup();
	vao.vbo[0].setup(quadCentered, 16, false).attrib(0).pointer_float(4).divisor(0);
	vao.vbo[1].setup(sizeof(ParticleBilboard)/sizeof(float)*MAX_PARTICLES, true);

	ParticleBilboard::setVaoPointers(vao.vbo[1], 1);
	vao();
}
Example #9
0
void OsuVRUIImageButton::drawVR(Graphics *g, Matrix4 &mvp)
{
	OsuVRUIButton::drawVR(g, mvp);
	if (!m_bIsVisible) return;
	if (m_image == NULL) return;

	// icon mesh
	VertexArrayObject vao(Graphics::PRIMITIVE::PRIMITIVE_QUADS);

	const Color color = m_bIsCursorInside ? COLORf(1.0f, 0.4f + 0.6f*m_fAnimation, 0.4f + 0.6f*m_fAnimation, 0.4f + 0.6f*m_fAnimation) : COLORf(1.0f, 0.4f, 0.4f, 0.4f);

	const float animationDistance = m_fAnimation * 0.02f;

	vao.addVertex(0, 0, animationDistance);
	vao.addTexcoord(0, 0);
	vao.addColor(color);
	vao.addVertex(m_vSize.x, 0, animationDistance);
	vao.addTexcoord(1, 0);
	vao.addColor(color);
	vao.addVertex(m_vSize.x, -m_vSize.y, animationDistance);
	vao.addTexcoord(1, 1);
	vao.addColor(color);
	vao.addVertex(0, -m_vSize.y, animationDistance);
	vao.addTexcoord(0, 1);
	vao.addColor(color);

	// position
	Matrix4 translation;
	translation.translate(m_vPos.x, m_vPos.y, 0);
	Matrix4 finalMVP = mvp * translation;

	// draw icon
	m_vr->getShaderTexturedGeneric()->enable();
	m_vr->getShaderTexturedGeneric()->setUniformMatrix4fv("matrix", finalMVP);
	{
		if (m_image != NULL)
			m_image->bind();

		g->drawVAO(&vao);

		if (m_image != NULL)
			m_image->unbind();
	}
	m_vr->getShaderTexturedGeneric()->disable();
}
Example #10
0
void Grass::initVBO(CommonResources &resources){
	vao.setup();
	vao.vbo[VERTICES] = resources.vao.vbo[VERTICES];
	vao.vbo[VERTICES].bind().attrib(VERTICES).pointer_float(4).divisor(0);
	vao.vbo[UVS] = resources.vao.vbo[UVS];
	vao.vbo[UVS].bind().attrib(UVS).pointer_float(2).divisor(0);
	vao.vbo[NORMALS] = resources.vao.vbo[NORMALS];
	vao.vbo[NORMALS].bind().attrib(NORMALS).pointer_float(4).divisor(0);
	vao.ibo = resources.vao.ibo;
	vao.ibo.bind();

	vao.vbo[POSITIONS].setup(sizeof(GrassField)*MAX_FIELD_COUNT/sizeof(float), true)
		.attrib(POSITIONS).pointer_float(4, (sizeof(SingleGrassPatch)), (void*)offsetof(SingleGrassPatch, position)).divisor(1)
		.attrib(SCALE).pointer_float(1, sizeof(SingleGrassPatch), (void*)offsetof(SingleGrassPatch, size)).divisor(1)
		.attrib(FALLOF).pointer_float(1, sizeof(SingleGrassPatch), (void*)offsetof(SingleGrassPatch, fallof)).divisor(1);
	vao();

	GrassField::init();
}
void VertexAttributeBindingImplementation_Legacy::finish(const VertexAttributeBinding * binding) const
{
    assert(bindingData(binding) != nullptr);

    vao(binding)->bind();

    void * offset = nullptr;

    if (vbo(binding))
    {
        vbo(binding)->bind(GL_ARRAY_BUFFER);
        const auto offset64 = static_cast<GLuint64>(bindingData(binding)->baseoffset + bindingData(binding)->format.relativeoffset);
        offset = reinterpret_cast<void *>(offset64);
    }
    else
    {
        Buffer::unbind(GL_ARRAY_BUFFER);
    }

    const GLint attribute = attributeIndex(binding);

    switch (bindingData(binding)->format.method)
    {
    case Format::Method::I:
        glVertexAttribIPointer(attribute, bindingData(binding)->format.size, bindingData(binding)->format.type
            , bindingData(binding)->stride, offset);
        break;

    case Format::Method::L:
        glVertexAttribLPointer(attribute, bindingData(binding)->format.size, bindingData(binding)->format.type
            , bindingData(binding)->stride, offset);
        break;

    default:
        glVertexAttribPointer(attribute, bindingData(binding)->format.size, bindingData(binding)->format.type
            , bindingData(binding)->format.normalized, bindingData(binding)->stride, offset);
    }
}
Example #12
0
void NGLScene::paintGL()
{
  // clear the screen and depth buffer
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  glViewport(0,0,m_win.width,m_win.height);
  // Rotation based on the mouse position for our global
  // transform
  ngl::Mat4 rotX;
  ngl::Mat4 rotY;
  // create the rotation matrices
  rotX.rotateX(m_win.spinXFace);
  rotY.rotateY(m_win.spinYFace);
  // multiply the rotations
  m_mouseGlobalTX=rotY*rotX;
  // add the translations
  m_mouseGlobalTX.m_m[3][0] = m_modelPos.m_x;
  m_mouseGlobalTX.m_m[3][1] = m_modelPos.m_y;
  m_mouseGlobalTX.m_m[3][2] = m_modelPos.m_z;

  auto *shader=ngl::ShaderLib::instance();
  shader->use(ngl::nglColourShader);
  ngl::Mat4 MVP=m_project*m_view*m_mouseGlobalTX;
  shader->setUniform("MVP",MVP);

  // draw the mesh
  std::vector<ngl::Vec3> mesh = m_animData->getRawDataPointerAtFrame(m_frame);
 // ngl::msg->addMessage(fmt::format("frame {0}",m_frame));
 // ngl::msg->addMessage(fmt::format("data {0} {1} {2} ",mesh[0][0],mesh[0][1],mesh[0][2]));
  auto size=mesh.size();
  glPointSize(4);
  std::unique_ptr<ngl::AbstractVAO> vao(ngl::VAOFactory::createVAO(ngl::simpleVAO,GL_POINTS));
  vao->bind();
  vao->setData(ngl::AbstractVAO::VertexData( size*sizeof(ngl::Vec3),mesh[0].m_x));
  vao->setVertexAttributePointer(0,3,GL_FLOAT,sizeof(ngl::Vec3),0);
  vao->setNumIndices(size);
  vao->draw();
  vao->unbind();
}
void VertexAttributeBindingImplementation_Legacy::setAttributeDivisor(const VertexAttributeBinding * binding, GLuint divisor) const
{
    vao(binding)->bind();

    glVertexAttribDivisor(binding->attributeIndex(), divisor);
}
Example #14
0
void CreateResources(ResourceManager &resourceManager)
{
    std::vector<Textures> texVec;
    std::vector<Sounds> soundVec;

    if(!resourceManager.GetTexture("geoff.png"))
        texVec.push_back(Textures("geoff.png"));
    if(!resourceManager.GetTexture("wolf.png"))
        texVec.push_back(Textures("wolf.png"));
    if(!resourceManager.GetTexture("bear.png"))
        texVec.push_back(Textures("bear.png"));
    if(!resourceManager.GetTexture("scenery.png"))
        texVec.push_back(Textures("scenery.png"));
    if(!resourceManager.GetTexture("scenery2.png"))
        texVec.push_back(Textures("scenery2.png"));
    if(!resourceManager.GetTexture("text.png"))
        texVec.push_back(Textures("text.png"));
    if(!resourceManager.GetTexture("snake.png"))
        texVec.push_back(Textures("snake.png"));

    if(!resourceManager.GetSound("bear.ogg"))
        soundVec.push_back(Sounds("bear.ogg"));
    if(!resourceManager.GetSound("chainsaw.ogg"))
        soundVec.push_back(Sounds("chainsaw.ogg"));
    if(!resourceManager.GetSound("chop.ogg"))
        soundVec.push_back(Sounds("chop.ogg"));
    if(!resourceManager.GetSound("death.ogg"))
        soundVec.push_back(Sounds("death.ogg"));
    if(!resourceManager.GetSound("snake.ogg"))
        soundVec.push_back(Sounds("snake.ogg"));
    if(!resourceManager.GetSound("wolfhowl.ogg"))
        soundVec.push_back(Sounds("wolfhowl.ogg"));
    if(!resourceManager.GetSound("woodpile.ogg"))
        soundVec.push_back(Sounds("woodpile.ogg"));

    resourceManager.GetOrCreateProgram("textured.vs", "textured.fs");
    resourceManager.GetOrCreateProgram("character.vs", "textured.fs");
    resourceManager.GetOrCreateProgram("colouredsquare.vs", "colouredsquare.fs");

    std::shared_ptr<unsigned int> buffer(resourceManager.GetVao("buffer"));

    if(!buffer)
    {
        buffer = std::make_shared<unsigned int>(CreateBuffer());
        resourceManager.AddVao("buffer", buffer);
    }
    if(!resourceManager.GetVao("full vao"))
    {
        std::shared_ptr<unsigned int> vao(new unsigned int (CreateVAO(*buffer, 1)));
        resourceManager.AddVao("full vao", vao);
    }
    if(!resourceManager.GetVao("vao top left"))
    {
        std::shared_ptr<unsigned int> vaoTopLeft(new unsigned int (CreateVAO(*buffer, 2)));
        resourceManager.AddVao("vao top left", vaoTopLeft);
    }
    if(!resourceManager.GetVao("vao top right"))
    {
        std::shared_ptr<unsigned int> vaoTopRight(new unsigned int (CreateVAO(*buffer, 3)));
        resourceManager.AddVao("vao top right", vaoTopRight);
    }
    if(!resourceManager.GetVao("vao bottom left"))
    {
        std::shared_ptr<unsigned int> vaoBottomLeft(new unsigned int (CreateVAO(*buffer, 4)));
        resourceManager.AddVao("vao bottom left", vaoBottomLeft);
    }
    if(!resourceManager.GetVao("vao bottom right"))
    {
        std::shared_ptr<unsigned int> vaoBottomRight(new unsigned int (CreateVAO(*buffer, 5)));
        resourceManager.AddVao("vao bottom right", vaoBottomRight);
    }
    if(!resourceManager.GetVao("vao plain colour"))
    {
        std::shared_ptr<unsigned int> vaoPlainColour(new unsigned int (SetupStandardVAO(*buffer)));
        resourceManager.AddVao("vao plain colour", vaoPlainColour);
    }

    CreateTexturesAndSound(texVec, soundVec);
    for(auto object(texVec.begin()); object != texVec.end(); ++object)
    {
        std::shared_ptr<unsigned int> ptr(
                    new unsigned int(CreateOpenGLTexture((*object).texVec, (*object).width,
                                                         (*object).height)));
        resourceManager.AddTexture((*object).filename, ptr);
    }
    texVec.clear();
    for(auto object(soundVec.begin()); object != soundVec.end(); ++object)
    {
        std::shared_ptr<unsigned int> ptr(
                    new unsigned int(object->sound));
        resourceManager.AddSound((*object).filename, ptr);
    }
    soundVec.clear();
}
Example #15
0
 void Triangle::draw() const
 {
     vao().bind();
     glDrawArrays(GL_TRIANGLES, 0, 3);
 }