Exemplo n.º 1
0
static void br_opengl_draw_tooltip(duc_graph *g, double x, double y, char *text)
{
	struct opengl_backend_data *bd = g->backend_data;
	double w, h;

	text_size(g, text, &w, &h, FONT_SIZE_TOOLTIP);

	GLfloat vVertices[] = {
		x - g->cx - w - 10, y - g->cy - h - 15,
		x - g->cx         , y - g->cy - h - 15,
		x - g->cx         , y - g->cy         ,
		x - g->cx - w - 10, y - g->cy         ,
	};


	glVertexAttribPointer(bd->loc_pos, 2, GL_FLOAT, GL_FALSE, 2 * sizeof(GLfloat), &vVertices[0]);
	glDisableVertexAttribArray(bd->loc_color);
	glDisableVertexAttribArray(bd->loc_texture);

	glVertexAttrib4f(bd->loc_color, 1, 1, 1, 0);
	GLushort indices[] = { 0, 1, 2, 0, 2, 3 };
	glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, indices);
	
	glVertexAttrib4f(bd->loc_color, 0, 0, 0, 0);
	glDrawArrays(GL_LINE_LOOP, 0, 4);
	
	draw_text(g, x - w - 5, y - h - 5, FONT_SIZE_TOOLTIP, text);
}
Exemplo n.º 2
0
  GeomProgram::GeomProgram () :
    vertex_shader   ("../Common/Shaders/Geom-Vertex.glsl",   GL_VERTEX_SHADER),
    fragment_shader ("../Common/Shaders/Geom-Fragment.glsl", GL_FRAGMENT_SHADER)
  {
    program.add_shader (vertex_shader);
    program.add_shader (fragment_shader);

    program.fix_attrib ("attrib_position", attrib_position);
    //program.fix_attrib ("attrib_normal",   attrib_normal);
    program.fix_attrib ("attrib_tcoords",  attrib_tcoords);
    program.fix_attrib ("attrib_colour",   attrib_colour);

    program.link ();

    program.use ();

    u32 tex_diffuse = program.link_uniform ("tex_diffuse");
    glUniform1i (tex_diffuse, texunit_diffuse);

    glVertexAttrib4f (attrib_colour, 1.0f, 1.0f, 1.0f, 1.0f);
    check_gl ("glVertexAttrib4f");

    program.done ();

    /*world_to_clip  = program.link_uniform ("world_to_clip");
    world_to_eye   = program.link_uniform ("world_to_eye");
    model_to_world = program.link_uniform ("model_to_world");*/
    model_to_clip  = program.link_uniform ("model_to_clip");
  }
Exemplo n.º 3
0
SubCanvas::SubCanvas(Canvas &canvas, RasterPoint _offset, PixelSize _size)
  :relative(_offset)
{
  assert(canvas.offset == OpenGL::translate);
  offset = canvas.offset + _offset;
  
  /* sub canvas bottom right limits can't be outside "parent" canvas. */
  size.cx = std::min<PixelScalar>(_size.cx, canvas.GetSize().cx - _offset.x) ;
  size.cy = std::min<PixelScalar>(_size.cy, canvas.GetSize().cy - _offset.y) ;

  if (relative.x != 0 || relative.y != 0) {
    OpenGL::translate += _offset;

#ifdef USE_GLSL
    glVertexAttrib4f(OpenGL::Attribute::TRANSLATE,
                     OpenGL::translate.x, OpenGL::translate.y, 0, 0);
#else
    glPushMatrix();
#ifdef HAVE_GLES
    glTranslatex((GLfixed)relative.x << 16, (GLfixed)relative.y << 16, 0);
#else
    glTranslatef(relative.x, relative.y, 0);
#endif
#endif /* !USE_GLSL */
  }
  
  if ((relative.x + size.cx < canvas.GetSize().cx) 
          || (relative.y + size.cy < canvas.GetSize().cy)) {

    /* Enable Clipping */
    push_scissor = std::make_unique<GLPushScissor>();
    scissor = std::make_unique<GLCanvasScissor>(*this);
  }
}
Exemplo n.º 4
0
bool
atomic_counters_draw_point(GLuint prog, unsigned buf_size,
                           const uint32_t *buf)
{
        GLuint vao;

        /* Initialize the atomic counter buffer. */
        glBufferData(GL_ATOMIC_COUNTER_BUFFER,
                     buf_size * sizeof(uint32_t),
                     buf, GL_STATIC_DRAW);

        /* Link and set the current shader program. */
        atomic_counters_link(prog);
        glUseProgram(prog);

        /* Draw. */
        glClearColor(0.5, 0.5, 0.5, 0.5);
        glClear(GL_COLOR_BUFFER_BIT);

        glGenVertexArrays(1, &vao);
        glBindVertexArray(vao);
        glVertexAttrib4f(0, 0, 0, 0, 1);

        glDrawArrays(GL_POINTS, 0, 1);

        glDeleteVertexArrays(1, &vao);

        return piglit_check_gl_error(GL_NO_ERROR);
}
Exemplo n.º 5
0
      /*! \brief Sets the value of a vertex attribute, if no attribute
        array is bound.
       
        This function only sets the state if it has been updated.
       */
      inline void setAttribute(GLuint idx, GLfloat x = 0, GLfloat y = 0, GLfloat z = 0, GLfloat w = 0)
      {
	if (idx >= _vertexAttributeState.size())
	  M_throw() << "Attribute index out of range";

	if (idx == 0)
	  M_throw() << "Cannot set the value of the 0th vertex attribute.";

	std::array<GLfloat, 4> newval = {{x,y,z,w}};

#ifdef MAGNET_DEBUG
	std::array<GLfloat, 4> oldval;
	glGetVertexAttribfv(idx, GL_CURRENT_VERTEX_ATTRIB, &oldval[0]);
	detail::errorCheck();

	if (oldval != _vertexAttributeState[idx].current_value)
	  M_throw() << "Vertex attribute state changed without using the GL context!";
#endif

	if (newval == _vertexAttributeState[idx].current_value) return;
	_vertexAttributeState[idx].current_value = newval;

	glVertexAttrib4f(idx, newval[0], newval[1], newval[2], newval[3]);
	detail::errorCheck();
      }
Exemplo n.º 6
0
void OpenGL::useVertexAttribArrays(uint32 arraybits)
{
	uint32 diff = arraybits ^ state.enabledAttribArrays;

	if (diff == 0)
		return;

	// Max 32 attributes. As of when this was written, no GL driver exposes more
	// than 32. Lets hope that doesn't change...
	for (uint32 i = 0; i < 32; i++)
	{
		uint32 bit = 1 << i;

		if (diff & bit)
		{
			if (arraybits & bit)
				glEnableVertexAttribArray(i);
			else
				glDisableVertexAttribArray(i);
		}
	}

	state.enabledAttribArrays = arraybits;

	// glDisableVertexAttribArray will make the constant value for a vertex
	// attribute undefined. We rely on the per-vertex color attribute being
	// white when no per-vertex color is used, so we set it here.
	// FIXME: Is there a better place to do this?
	if ((diff & ATTRIBFLAG_COLOR) && !(arraybits & ATTRIBFLAG_COLOR))
		glVertexAttrib4f(ATTRIB_COLOR, 1.0f, 1.0f, 1.0f, 1.0f);
}
Exemplo n.º 7
0
void RenderingEngine::render(const vector<Visual>& visuals) const
{
    glClearColor(0.0f, 0.0f, 0.0f, 1);
    glClear(GL_COLOR_BUFFER_BIT);
        
    vector<Visual>::const_iterator visual = visuals.begin();
    for (int visualIndex = 0; visual != visuals.end(); ++visual, ++visualIndex) {
        // Set the viewport transform.
        ivec2 size = visual->viewportSize;
        ivec2 lowerLeft = visual->lowerLeft;
        glViewport(lowerLeft.x, lowerLeft.y, size.x, size.y);

        // Set the model-view transform.
        mat4 rotation = visual->orientation.toMatrix();
        mat4 modelview = rotation * _translation;
        glUniformMatrix4fv(_modelviewUniform, 1, 0, modelview.pointer());

        // Set the projection transform.
        float h = 4.0f * size.y / size.x;
        mat4 projectionMatrix = mat4::frustum(-2, 2, -h / 2, h / 2, 5, 10);
        glUniformMatrix4fv(_projectionUniform, 1, 0, projectionMatrix.pointer());
        
        // Set the color.
        vec3 color = visual->color;
        glVertexAttrib4f(_colorSlot, color.x, color.y, color.z, 1);
        
        // Draw the wireframe.
        const Drawable& drawable = _drawables[visualIndex];
        glBindBuffer(GL_ARRAY_BUFFER, drawable.vertexBuffer);
        glVertexAttribPointer(_positionSlot, 3, GL_FLOAT, GL_FALSE, sizeof(vec3), 0);
        glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, drawable.indexBuffer);
        glDrawElements(GL_LINES, drawable.indexCount, GL_UNSIGNED_SHORT, 0);
    }
}
Exemplo n.º 8
0
void SQPrimitives::drawCubeGeometry(const QVector4D &color)
{
    // Tell OpenGL which VBOs to use
    glBindBuffer(GL_ARRAY_BUFFER, _vboIds[0]);
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _vboIds[1]);

    // Offset for position
    quintptr offset = 0;

    // Tell OpenGL programmable pipeline how to locate vertex position data
    int vertexLocation = _program->attributeLocation("a_position");
    _program->enableAttributeArray(vertexLocation);
    glVertexAttribPointer(vertexLocation, 3, GL_FLOAT, GL_FALSE, sizeof(VertexData), (const void *)offset);

    // Offset for texture coordinate
    offset += sizeof(QVector3D);

    // Tell OpenGL programmable pipeline how to locate vertex texture coordinate data
    int texcoordLocation = _program->attributeLocation("a_texcoord");
    _program->enableAttributeArray(texcoordLocation);
    glVertexAttribPointer(texcoordLocation, 2, GL_FLOAT, GL_FALSE, sizeof(VertexData), (const void *)offset);

    int colorLocation = _program->attributeLocation("a_color");
    glVertexAttrib4f(colorLocation, color.x(), color.y(), color.z(), color.w());

    // Draw cube geometry using indices from VBO 1
    glDrawElements(GL_TRIANGLE_STRIP, 34, GL_UNSIGNED_SHORT, 0);
}
Exemplo n.º 9
0
// --------------------------------------------------------------------------------------------------------------------
void UntexturedObjectsGLTexCoord::Render(const std::vector<Matrix>& _transforms)
{
    // Program
    Vec3 dir = { -0.5f, -1, 1 };
    Vec3 at = { 0, 0, 0 };
    Vec3 up = { 0, 0, 1 };
    dir = normalize(dir);
    Vec3 eye = at - 250 * dir;
    Matrix view = matrix_look_at(eye, at, up);
    Matrix view_proj = mProj * view;

    glUseProgram(m_prog);
    glUniformMatrix4fv(mUniformLocation.ViewProjection, 1, GL_TRUE, &view_proj.x.x);

    // Input Layout
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_ib);
    glBindBuffer(GL_ARRAY_BUFFER, m_vb);
    glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(UntexturedObjectsProblem::Vertex), (void*)offsetof(UntexturedObjectsProblem::Vertex, pos));
    glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, sizeof(UntexturedObjectsProblem::Vertex), (void*)offsetof(UntexturedObjectsProblem::Vertex, color));

    glEnableVertexAttribArray(0);
    glEnableVertexAttribArray(1);

    // Rasterizer State
    glEnable(GL_CULL_FACE);
    glCullFace(GL_FRONT);
    glDisable(GL_SCISSOR_TEST);

    // Blend State
    glDisable(GL_BLEND);
    glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);

    // Depth Stencil State
    glEnable(GL_DEPTH_TEST);
    glDepthMask(GL_TRUE);

    for (auto it = _transforms.begin(); it != _transforms.end(); ++it) {
        const Matrix* m = &*it;
    
        glVertexAttrib4f(2, m->x.x, m->x.y, m->x.z, m->x.w);
        glVertexAttrib4f(3, m->y.x, m->y.y, m->y.z, m->y.w);
        glVertexAttrib4f(4, m->z.x, m->z.y, m->z.z, m->z.w);
        glVertexAttrib4f(5, m->w.x, m->w.y, m->w.z, m->w.w);

        glDrawElements(GL_TRIANGLES, mIndexCount, GL_UNSIGNED_SHORT, nullptr);
    }
}
Exemplo n.º 10
0
void
BufferCanvas::Commit(Canvas &other)
{
  assert(IsDefined());
  assert(active);
  assert(GetWidth() == other.GetWidth());
  assert(GetHeight() == other.GetHeight());

  if (frame_buffer != nullptr) {
    assert(OpenGL::translate.x == 0);
    assert(OpenGL::translate.y == 0);

    frame_buffer->Unbind();

    /* restore the old viewport */

    assert(OpenGL::translate == RasterPoint(0, 0));

#ifdef HAVE_GLES
    /* there's no glPopAttrib() on GL/ES; emulate it */
    glViewport(old_viewport[0], old_viewport[1],
               old_viewport[2], old_viewport[3]);
#else
    glPopAttrib();
#endif

#ifdef USE_GLSL
    OpenGL::projection_matrix = old_projection_matrix;
    OpenGL::UpdateShaderProjectionMatrix();
#else
    glMatrixMode(GL_PROJECTION);
    glPopMatrix();
    glMatrixMode(GL_MODELVIEW);
    glPopMatrix();
#endif

    OpenGL::translate = old_translate;
    OpenGL::viewport_size = old_size;

#ifdef USE_GLSL
    glVertexAttrib4f(OpenGL::Attribute::TRANSLATE,
                     OpenGL::translate.x, OpenGL::translate.y, 0, 0);
#endif

#ifdef SOFTWARE_ROTATE_DISPLAY
    OpenGL::display_orientation = old_orientation;
#endif

    /* copy frame buffer to screen */
    CopyTo(other);
  } else {
    assert(offset == other.offset);

    /* copy screen to texture */
    CopyToTexture(*texture, GetRect());
  }

  active = false;
}
Exemplo n.º 11
0
void RenderFigure()
{
	glCullFace(GL_CW);
	LoadModelViewProjectionMatrixToShader();
	glVertexAttrib4f(GLT_ATTRIBUTE_COLOR, 0.75f, 0.f, 0.f, 1.0f);
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,faces_buffer);
	glDrawElements(GL_TRIANGLES,3*n_faces,GL_UNSIGNED_INT,0);	
}
Exemplo n.º 12
0
void color_light_shader::setup_gl_attribs_val() const noexcept
{
  glVertexAttrib4f(
   static_cast<GLuint>(shader_attrib_location::vertex), 0, 0, 0, 1);

  glVertexAttrib4f(
   static_cast<GLuint>(shader_attrib_location::transformation) + 0, 1, 0, 0, 0);

  glVertexAttrib4f(
   static_cast<GLuint>(shader_attrib_location::transformation) + 1, 0, 1, 0, 0);

  glVertexAttrib4f(
   static_cast<GLuint>(shader_attrib_location::transformation) + 2, 0, 0, 1, 0);

  glVertexAttrib4f(
   static_cast<GLuint>(shader_attrib_location::transformation) + 3, 0, 0, 0, 1);
}
Exemplo n.º 13
0
static void br_opengl_draw_section(duc_graph *g, double a1, double a2, double r1, double r2, double R, double G, double B, double L)
{
	struct opengl_backend_data *bd = g->backend_data;
	int i;

	a1 *= M_PI * 2;
	a2 *= M_PI * 2;

	int ss = (int)((a2 - a1) * r2 / 10 + 2);

	GLfloat vs_fill[ss * 2][6];
	GLfloat vs_line[ss * 2][2];

	double da = (a2-a1) / (ss-1);

	for(i=0; i<ss; i++) {
		double x1, y1, x2, y2;
		x1 = r1 * sin(a1 + da * i); y1 = -r1 * cos(a1 + da * i);
		x2 = r2 * sin(a1 + da * i); y2 = -r2 * cos(a1 + da * i);

		vs_fill[i*2 + 0][0] = x1; 
		vs_fill[i*2 + 0][1] = y1;
		vs_fill[i*2 + 0][2] = R * (g->gradient ? 0.7 : 1.0);
		vs_fill[i*2 + 0][3] = G * (g->gradient ? 0.7 : 1.0);
		vs_fill[i*2 + 0][4] = B * (g->gradient ? 0.7 : 1.0);
		vs_fill[i*2 + 0][5] = 0;
		vs_fill[i*2 + 1][0] = x2; 
		vs_fill[i*2 + 1][1] = y2;
		vs_fill[i*2 + 1][2] = R;
		vs_fill[i*2 + 1][3] = G;
		vs_fill[i*2 + 1][4] = B;
		vs_fill[i*2 + 1][5] = 0;
		
		vs_line[i][0] = x1;
		vs_line[i][1] = y1;
		vs_line[2*ss-i-1][0] = x2; 
		vs_line[2*ss-i-1][1] = y2;
	}

	glDisable(GL_TEXTURE_2D);


	if(R != 1.0 || G != 1.0 || B != 1.0) {
		glEnableVertexAttribArray(bd->loc_pos);
		glEnableVertexAttribArray(bd->loc_color);
		glVertexAttribPointer(bd->loc_pos,   2, GL_FLOAT, GL_FALSE, 6 * sizeof(GLfloat), &vs_fill[0][0]);
		glVertexAttribPointer(bd->loc_color, 4, GL_FLOAT, GL_FALSE, 6 * sizeof(GLfloat), &vs_fill[0][2]);
		glDrawArrays(GL_TRIANGLE_STRIP, 0, ss*2);
	}

	if(L != 0.0) {
		glLineWidth(0.8);
		glDisableVertexAttribArray(bd->loc_color);
		glVertexAttrib4f(bd->loc_color, L, L, L, 0);
		glVertexAttribPointer(bd->loc_pos, 2, GL_FLOAT, GL_FALSE, 0, vs_line);
		glDrawArrays(GL_LINE_LOOP, 0, ss*2);
	}
}
Exemplo n.º 14
0
void
OpenGL::InitShaders()
{
  DeinitShaders();

  solid_shader = CompileProgram(solid_vertex_shader, solid_fragment_shader);
  solid_shader->BindAttribLocation(Attribute::TRANSLATE, "translate");
  solid_shader->BindAttribLocation(Attribute::POSITION, "position");
  solid_shader->BindAttribLocation(Attribute::COLOR, "color");
  LinkProgram(*solid_shader);

  solid_projection = solid_shader->GetUniformLocation("projection");
  solid_modelview = solid_shader->GetUniformLocation("modelview");

  solid_shader->Use();
  glUniformMatrix4fv(solid_modelview, 1, GL_FALSE,
                     glm::value_ptr(glm::mat4()));

  texture_shader = CompileProgram(texture_vertex_shader, texture_fragment_shader);
  texture_shader->BindAttribLocation(Attribute::TRANSLATE, "translate");
  texture_shader->BindAttribLocation(Attribute::POSITION, "position");
  texture_shader->BindAttribLocation(Attribute::TEXCOORD, "texcoord");
  LinkProgram(*texture_shader);

  texture_projection = texture_shader->GetUniformLocation("projection");
  texture_texture = texture_shader->GetUniformLocation("texture");

  texture_shader->Use();
  glUniform1i(texture_texture, 0);

  invert_shader = CompileProgram(invert_vertex_shader, invert_fragment_shader);
  invert_shader->BindAttribLocation(Attribute::TRANSLATE, "translate");
  invert_shader->BindAttribLocation(Attribute::POSITION, "position");
  invert_shader->BindAttribLocation(Attribute::TEXCOORD, "texcoord");
  LinkProgram(*invert_shader);

  invert_projection = invert_shader->GetUniformLocation("projection");
  invert_texture = invert_shader->GetUniformLocation("texture");

  invert_shader->Use();
  glUniform1i(invert_texture, 0);

  alpha_shader = CompileProgram(alpha_vertex_shader, alpha_fragment_shader);
  alpha_shader->BindAttribLocation(Attribute::TRANSLATE, "translate");
  alpha_shader->BindAttribLocation(Attribute::POSITION, "position");
  alpha_shader->BindAttribLocation(Attribute::TEXCOORD, "texcoord");
  alpha_shader->BindAttribLocation(Attribute::COLOR, "color");
  LinkProgram(*alpha_shader);

  alpha_projection = alpha_shader->GetUniformLocation("projection");
  alpha_texture = alpha_shader->GetUniformLocation("texture");

  alpha_shader->Use();
  glUniform1i(alpha_texture, 0);

  glVertexAttrib4f(Attribute::TRANSLATE, 0, 0, 0, 0);
}
void GLESDebugDraw::DrawParticles(const b2Vec2 *centers_old, float32 radius, const b2ParticleColor *colors, int32 count)
{
    /*
     // normally this is how we'd enable them on desktop OpenGL,
     // but for some reason this is not applying textures, so we use alpha instead
     glEnable(GL_POINT_SPRITE);
     glTexEnvi(GL_POINT_SPRITE, GL_COORD_REPLACE, GL_TRUE);
     */
    const float particle_size_multiplier = 8;  // no falloff
    const float global_alpha = 0.35f;  // instead of texture

    mShaderProgram->setUniformLocationWith1f(mPointSizeLocation, radius * mRatio * particle_size_multiplier);

    GL::blendFunc(GL_SRC_ALPHA, GL_ONE);

    b2Vec2 *centers = (b2Vec2 *) alloca(sizeof(b2Vec2) * count);
    for(int i=0; i<count; i++) {
        centers[i].x = centers_old[i].x *mRatio;
        centers[i].y = centers_old[i].y *mRatio;
    }

    glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 2, GL_FLOAT, GL_FALSE, 0, centers);
    glVertexAttrib4f(GLProgram::VERTEX_ATTRIB_TEX_COORDS, 0, 0, 1, 1);

	if (0 /*colors*/)
	{
        // hack to render with proper alpha on desktop for Testbed
        b2ParticleColor * mcolors = const_cast<b2ParticleColor *>(colors);
        for (int i = 0; i < count; i++)
        {
            mcolors[i].a = static_cast<uint8>(global_alpha * 255);
        }
        glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_COLOR, 4, GL_UNSIGNED_BYTE, GL_TRUE, 0, &colors[0].r);
	}
	else
	{
        glVertexAttrib4f(GLProgram::VERTEX_ATTRIB_COLOR, 1, 1, 1, global_alpha);
        mShaderProgram->setUniformLocationWith4f(mColorLocation, 1, 1, 1, global_alpha);
	}

	glDrawArrays(GL_POINTS, 0, count);
    CC_INCREMENT_GL_DRAWN_BATCHES_AND_VERTICES(1,count);
}
Exemplo n.º 16
0
void RasterizerCanvasGLES2::_draw_polygon(const int *p_indices, int p_index_count, int p_vertex_count, const Vector2 *p_vertices, const Vector2 *p_uvs, const Color *p_colors, bool p_singlecolor) {

	glBindBuffer(GL_ARRAY_BUFFER, data.polygon_buffer);

	uint32_t buffer_ofs = 0;

	glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(Vector2) * p_vertex_count, p_vertices);
	glEnableVertexAttribArray(VS::ARRAY_VERTEX);
	glVertexAttribPointer(VS::ARRAY_VERTEX, 2, GL_FLOAT, GL_FALSE, sizeof(Vector2), NULL);
	buffer_ofs += sizeof(Vector2) * p_vertex_count;

	if (p_singlecolor) {
		glDisableVertexAttribArray(VS::ARRAY_COLOR);
		Color m = *p_colors;
		glVertexAttrib4f(VS::ARRAY_COLOR, m.r, m.g, m.b, m.a);
	} else if (!p_colors) {
		glDisableVertexAttribArray(VS::ARRAY_COLOR);
		glVertexAttrib4f(VS::ARRAY_COLOR, 1, 1, 1, 1);
	} else {
		glBufferSubData(GL_ARRAY_BUFFER, buffer_ofs, sizeof(Color) * p_vertex_count, p_colors);
		glEnableVertexAttribArray(VS::ARRAY_COLOR);
		glVertexAttribPointer(VS::ARRAY_COLOR, 4, GL_FLOAT, GL_FALSE, sizeof(Color), ((uint8_t *)0) + buffer_ofs);
		buffer_ofs += sizeof(Color) * p_vertex_count;
	}

	if (p_uvs) {
		glBufferSubData(GL_ARRAY_BUFFER, buffer_ofs, sizeof(Vector2) * p_vertex_count, p_uvs);
		glEnableVertexAttribArray(VS::ARRAY_TEX_UV);
		glVertexAttribPointer(VS::ARRAY_TEX_UV, 2, GL_FLOAT, GL_FALSE, sizeof(Vector2), ((uint8_t *)0) + buffer_ofs);
		buffer_ofs += sizeof(Vector2) * p_vertex_count;
	} else {
		glDisableVertexAttribArray(VS::ARRAY_TEX_UV);
	}

	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, data.polygon_index_buffer);
	glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, 0, sizeof(int) * p_index_count, p_indices);

	glDrawElements(GL_TRIANGLES, p_index_count, GL_UNSIGNED_INT, 0);

	glBindBuffer(GL_ARRAY_BUFFER, 0);
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
}
Exemplo n.º 17
0
void THFrame::DrawTexture(const THVector2& p,const THVector2& center,const THVector2& size,const THRot2& rot,const THTexture *tex)
{
	glBindTexture(GL_TEXTURE_2D,tex->image->textureID);
	glVertexAttrib2fv(THDefaultProgram.rotationHandler,(const GLfloat*)&rot);
	glVertexAttrib2fv(THDefaultProgram.scaleHandler,(const GLfloat*)&size);
	glVertexAttrib2fv(THDefaultProgram.positionHandler,(const GLfloat*)&p);
	glVertexAttrib4f(THDefaultProgram.textureHandler,tex->position.x,tex->position.y,tex->size.x,tex->size.y);
	glVertexAttrib2fv(THDefaultProgram.centerHandler,(const GLfloat*)&center);

	glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
}
Exemplo n.º 18
0
void GLSLProgram<real>::SetupDefautState()
{
	// Set default attributes
	glVertexAttrib3f( 0, 0.0, 0.0, 0.0 );
	glVertexAttrib3f( 1, 1.0, 0.0, 0.0 );
	glVertexAttrib3f( 2, 0.0, 0.0, 0.0 );
	glVertexAttrib4f( 3, 1.0, 1.0, 1.0, 1.0 );

	// No wireframe
	glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
}
Exemplo n.º 19
0
void RenderSystem::setAttributeValue(
    int slot,
    float a,
    float b,
    float c,
    float d
) {
    glVertexAttrib4f(
        slot, a, b, c, d
    );
    CROSS_GL_ASSERT();
}
 void RenderingEngine::Render(const vector<Visual>& visuals) const
 {
     glClearColor(0.5f, 0.5f, 0.5f, 1);
     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
     
     vector<Visual>::const_iterator visual = visuals.begin();
     for (int visualIndex = 0; visual != visuals.end(); ++visual, ++visualIndex) {
         
         // Set the viewport transform.
         ivec2 size = visual->ViewportSize;
         ivec2 lowerLeft = visual->LowerLeft;
         glViewport(lowerLeft.x, lowerLeft.y, size.x, size.y);
         
         // Set the light position.
         vec4 lightPosition(0.25, 0.25, 1, 0);
         glUniform3fv(m_uniforms.LightPosition, 1, lightPosition.Pointer());
         
         // Set the model-view transform.
         mat4 rotation = visual->Orientation.ToMatrix();
         mat4 modelview = rotation * m_translation;
         glUniformMatrix4fv(m_uniforms.Modelview, 1, 0, modelview.Pointer());
         
         // Set the normal matrix.
         // It's orthogonal, so its Inverse-Transpose is itself!
         mat3 normalMatrix = modelview.ToMat3();
         glUniformMatrix3fv(m_uniforms.NormalMatrix, 1, 0, normalMatrix.Pointer());
         
         // Set the projection transform.
         float h = 4.0f * size.y / size.x;
         mat4 projectionMatrix = mat4::Frustum(-2, 2, -h / 2, h / 2, 5, 10);
         glUniformMatrix4fv(m_uniforms.Projection, 1, 0, projectionMatrix.Pointer());
         
         // Set the diffuse color.
         vec3 color = visual->Color * 0.75f;
         glVertexAttrib4f(m_attributes.Diffuse, color.x, color.y, color.z, 1);
         
         // Draw the surface.
         int stride = sizeof(vec3) + sizeof(vec3) + sizeof(vec2);
         const GLvoid* normalOffset = (const GLvoid*) sizeof(vec3);
         const GLvoid* texCoordOffset = (const GLvoid*) (2 * sizeof(vec3));
         GLint position = m_attributes.Position;
         GLint normal = m_attributes.Normal;
         GLint texCoord = m_attributes.TextureCoord;
         const Drawable& drawable = m_drawables[visualIndex];
         glBindBuffer(GL_ARRAY_BUFFER, drawable.VertexBuffer);
         glVertexAttribPointer(position, 3, GL_FLOAT, GL_FALSE, stride, 0);
         glVertexAttribPointer(normal, 3, GL_FLOAT, GL_FALSE, stride, normalOffset);
         glVertexAttribPointer(texCoord, 2, GL_FLOAT, GL_FALSE, stride, texCoordOffset);
         glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, drawable.IndexBuffer);
         glDrawElements(GL_TRIANGLES, drawable.IndexCount, GL_UNSIGNED_SHORT, 0);
     }
 }
Exemplo n.º 21
0
void THFrame::DrawImage(const THVector2& p,const THVector2& size,const THImage& img)
{
	glBindTexture(GL_TEXTURE_2D,img.textureID);

	glVertexAttrib2f(THDefaultProgram.rotationHandler,1.0f,0.0f);
	glVertexAttrib4f(THDefaultProgram.textureHandler,0.0f,0.0f,1.0f,1.0f);
	glVertexAttrib2f(THDefaultProgram.centerHandler,0.0f,0.0f);

	glVertexAttrib2fv(THDefaultProgram.scaleHandler,(const GLfloat*)&size);
	glVertexAttrib2fv(THDefaultProgram.positionHandler,(const GLfloat*)&p);

	glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
}
Exemplo n.º 22
0
void RenderPlane(float size)
{
	glFrontFace(GL_CCW);

	glBegin(GL_QUADS);
		glVertexAttrib4f(GLT_ATTRIBUTE_COLOR, 0.75f, 0.75f, 0.75f, 1.0f);

		glVertex3f(-size, size, 0.0f); 
		glVertex3f(-size, -size, 0.0f);
		glVertex3f(size, -size, 0.0f);
		glVertex3f(size, size, 0.0f);
	glEnd();
}
Exemplo n.º 23
0
void Target_draw() {
	Matrix projectionMatrix;
	float ratio;
	float stringWidth;
	char indexString[32];
	
	glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
	glClear(GL_COLOR_BUFFER_BIT);
	
	ratio = (float) viewportWidth / viewportHeight;
	projectionMatrix = Matrix_ortho(Matrix_identity(), -ratio, ratio, -1.0f, 1.0f, -1.0f, 1.0f);
	
	if (GLGraphics_getOpenGLAPIVersion() == GL_API_VERSION_ES2) {
		glUniformMatrix4fv(matrixUniform, 1, GL_FALSE, projectionMatrix.m);
		glUniform1i(textureUniform, 0);
		glVertexAttrib4f(2, 1.0f, 1.0f, 1.0f, 1.0f);
		
	} else {
		glMatrixMode(GL_PROJECTION);
		glLoadMatrixf(projectionMatrix.m);
		glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
	}
	
	stringWidth = font->measureString(font, "Hello, world!", 13);
	font->drawString(font, "Hello, world!", 13, 0.1f, stringWidth * -0.05f, 0.0f, 0.0f);
	
	stringWidth = font->measureString(font, freeformText, strlen(freeformText));
	font->drawString(font, freeformText, strlen(freeformText), 0.0625f, stringWidth * -0.03125f, -0.0625f, 0.0f);
	
	if (GLGraphics_getOpenGLAPIVersion() == GL_API_VERSION_ES2) {
		glVertexAttrib4f(2, 0.875f, 0.875f, 0.5f, 1.0f);
	} else {
		glColor4f(0.875f, 0.875f, 0.5f, 1.0f);
	}
	snprintf(indexString, 32, "%u, %s", (unsigned int) lastIndexAtWidth, lastLeadingEdge ? "true" : "false");
	stringWidth = font->measureString(font, indexString, strlen(indexString));
	font->drawString(font, indexString, strlen(indexString), 0.05f, stringWidth * -0.025f, 0.1f, 0.0f);
}
Exemplo n.º 24
0
void Renderer10::Render() const
{
    glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
    glClear(GL_COLOR_BUFFER_BIT);
    
    // Configure blending
    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    
    // Red Quad
    mat4 modelview;
    
    glVertexAttrib4f(m_attribColor, 1.0f, 0.0f, 0.0f, 1.0f);
    glUniformMatrix4fv(m_uniformModelview, 1, GL_FALSE, modelview.Pointer());
    DrawQuad();
    
    // Green Quad
    modelview = modelview.Translate(-0.5f, -0.5f, 0.0f);
    
    glVertexAttrib4f(m_attribColor, 0.0f, 1.0f, 0.0f, 0.5f);
    glUniformMatrix4fv(m_uniformModelview, 1, GL_FALSE, modelview.Pointer());
    DrawQuad();
}
Exemplo n.º 25
0
static void draw_text(duc_graph *g, double _x, double _y, double size, char *text)
{
	struct opengl_backend_data *bd = g->backend_data;

	double x = _x - g->cx;
	double y = _y - g->cy - size * bd->font_scale * STB_SOMEFONT_LINE_SPACING;
		
	glDisableVertexAttribArray(bd->loc_color);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

	char *p1 = text;
	char *p2 = text;

	while(*p2) {
		while(*p2 && *p2 != '\n' && *p2 != '\r') {
			p2++;
		}

		glVertexAttrib4f(bd->loc_color, 1, 1, 1, 0);
		draw_text_line(g, x-1, y+0, size, p1, p2-p1);
		draw_text_line(g, x+1, y-0, size, p1, p2-p1);
		draw_text_line(g, x-0, y+1, size, p1, p2-p1);
		draw_text_line(g, x+0, y-1, size, p1, p2-p1);
		glVertexAttrib4f(bd->loc_color, 0, 0, 0, 0);
		draw_text_line(g, x+0, y, size, p1, p2-p1);

		if(!*p2) break;

		y += size * bd->font_scale * STB_SOMEFONT_LINE_SPACING * 1.5;
		x = _x - g->cx;

		p2 ++;
		p1 = p2;
	}

	glBlendFunc(GL_ONE, GL_ZERO);
}
Exemplo n.º 26
0
void RasterizerCanvasGLES2::_draw_generic(GLuint p_primitive, int p_vertex_count, const Vector2 *p_vertices, const Vector2 *p_uvs, const Color *p_colors, bool p_singlecolor) {

	glBindBuffer(GL_ARRAY_BUFFER, data.polygon_buffer);

	uint32_t buffer_ofs = 0;

	glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(Vector2) * p_vertex_count, p_vertices);
	glEnableVertexAttribArray(VS::ARRAY_VERTEX);
	glVertexAttribPointer(VS::ARRAY_VERTEX, 2, GL_FLOAT, GL_FALSE, sizeof(Vector2), (uint8_t *)0);
	buffer_ofs += sizeof(Vector2) * p_vertex_count;

	if (p_singlecolor) {
		glDisableVertexAttribArray(VS::ARRAY_COLOR);
		Color m = *p_colors;
		glVertexAttrib4f(VS::ARRAY_COLOR, m.r, m.g, m.b, m.a);
	} else if (!p_colors) {
		glDisableVertexAttribArray(VS::ARRAY_COLOR);
		glVertexAttrib4f(VS::ARRAY_COLOR, 1, 1, 1, 1);
	} else {
		glBufferSubData(GL_ARRAY_BUFFER, buffer_ofs, sizeof(Color) * p_vertex_count, p_colors);
		glEnableVertexAttribArray(VS::ARRAY_COLOR);
		glVertexAttribPointer(VS::ARRAY_COLOR, 4, GL_FLOAT, GL_FALSE, sizeof(Color), ((uint8_t *)0) + buffer_ofs);
		buffer_ofs += sizeof(Color) * p_vertex_count;
	}

	if (p_uvs) {
		glBufferSubData(GL_ARRAY_BUFFER, buffer_ofs, sizeof(Vector2) * p_vertex_count, p_uvs);
		glEnableVertexAttribArray(VS::ARRAY_TEX_UV);
		glVertexAttribPointer(VS::ARRAY_TEX_UV, 2, GL_FLOAT, GL_FALSE, sizeof(Vector2), ((uint8_t *)0) + buffer_ofs);
	} else {
		glDisableVertexAttribArray(VS::ARRAY_TEX_UV);
	}

	glDrawArrays(p_primitive, 0, p_vertex_count);

	glBindBuffer(GL_ARRAY_BUFFER, 0);
}
Exemplo n.º 27
0
SubCanvas::~SubCanvas()
{
  assert(offset == OpenGL::translate);

  if (relative.x != 0 || relative.y != 0) {
    OpenGL::translate -= relative;

#ifdef USE_GLSL
    glVertexAttrib4f(OpenGL::Attribute::TRANSLATE,
                     OpenGL::translate.x, OpenGL::translate.y, 0, 0);
#else
    glPopMatrix();
#endif
  }
}
Exemplo n.º 28
0
      /*! \brief Initializes the OpenGL context and state tracking.
       */
      inline void init()
      {
	_frameCounter = 0;
	_context = getCurrentContextKey();
	std::cout << "GL-Context " << _context << ": Created a new OpenGL context" << std::endl;	
	//////////Capability testing /////////////////////////////

	//Check for errors before running glew
	detail::errorCheck();
	//We must set this true as glew uses deprecated code
	//(glGetString) for testing for extensions
	glewExperimental=true;
	if (glewInit() != GLEW_OK)
	  M_throw() << "GL-Context " << _context << "Failed to initialise GLEW!";
	//Suppress GL errors generated by glew, by fetching and
	//discarding the last GL error;
	glGetError();

	std::cout << "GL-Context " << _context 
		  << ": OpenGL version " 
		  << detail::glGet<GL_MAJOR_VERSION>() << "."
		  << detail::glGet<GL_MINOR_VERSION>() << std::endl;	
#ifdef MAGNET_DEBUG
	if (testExtension("GL_ARB_debug_output"))
	  {
	    glDebugMessageCallbackARB(&Context::DebugCallback, NULL);
	    glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB);
	  }
#endif
	///////Variable initialisation ///////////////////////////
	_viewPortState = detail::glGet<GL_VIEWPORT>();

	_vertexAttributeState.resize(detail::glGet<GL_MAX_VERTEX_ATTRIBS>());
	for (GLuint i(1); i < _vertexAttributeState.size(); ++i)
	  {
	    glVertexAttrib4f(i, 0,0,0,1);
	    detail::errorCheck();
	  }	  

	color(0,1,1,1);
	resetInstanceTransform();

	//Bind the dummy VAO object (so hacky)
	glGenVertexArrays(1, &_dummyVAO);
	detail::errorCheck();
	glBindVertexArray(_dummyVAO);
	detail::errorCheck();
      }
Exemplo n.º 29
0
void VBOSphere::render() {
    if (vertexVBO == -1) {
        prepareVBO();
    }
	glPushMatrix();
	setMatrix();
    
#ifdef OPENGL_ES1
	glColor4f(objectColor.r, objectColor.g, objectColor.b, objectColor.a);
	glDisableClientState(GL_COLOR_ARRAY);
#else
    glDisableVertexAttribArray(shaderVertexColor);
    glVertexAttrib4f(shaderVertexColor, objectColor.r, objectColor.g, objectColor.b, objectColor.a);
#endif

	glBindBuffer(GL_ARRAY_BUFFER, vertexVBO);
#ifdef OPENGL_ES1
	glEnableClientState(GL_VERTEX_ARRAY);
	glVertexPointer(3, GL_FLOAT, 0, 0);
#else
	glEnableVertexAttribArray(shaderVertexPosition);
    glVertexAttribPointer(shaderVertexPosition, 3, GL_FLOAT, GL_FALSE, 0, 0);
#endif

	glBindBuffer(GL_ARRAY_BUFFER, vertexNormalVBO);
#ifdef OPENGL_ES1
	glEnableClientState(GL_NORMAL_ARRAY);
	glNormalPointer(GL_FLOAT, 0, 0);
#else
	glEnableVertexAttribArray(shaderVertexNormal);
    glVertexAttribPointer(shaderVertexNormal, 3, GL_FLOAT, GL_FALSE, 0, 0);
#endif
    
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, faceVBO);
	glDrawElements(GL_TRIANGLES, faceCount * 3, GL_UNSIGNED_SHORT, 0);

#ifdef OPENGL_ES1
	glDisableClientState(GL_VERTEX_ARRAY);
	glDisableClientState(GL_NORMAL_ARRAY);
#endif
	glBindBuffer(GL_ARRAY_BUFFER, 0);
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);

	glPopMatrix();
}
Exemplo n.º 30
0
GLuint ShapeVAOs::square() {
    if (this->_square == 0) {
        std::vector<float> square = Geometry::rectangle(0.0, 0.0, 1.0, 1.0);
        glGenVertexArraysOES(1, &this->_square);
        glBindVertexArrayOES(this->_square);
        GLuint buffer;
        glGenBuffers(1, &buffer);
        glBindBuffer(GL_ARRAY_BUFFER, buffer);
        glBufferData(GL_ARRAY_BUFFER, sizeof(float)*square.size(), &square[0], GL_STATIC_DRAW);
        glEnableVertexAttribArray(ShaderProgramAttributePosition);
        glVertexAttribPointer(ShaderProgramAttributePosition, 2, GL_FLOAT, GL_FALSE, 2*sizeof(float), 0);
        glDisableVertexAttribArray(ShaderProgramAttributeColor);
        glVertexAttrib4f(ShaderProgramAttributeColor, 1.0, 1.0, 1.0, 1.0); 
        glBindBuffer(GL_ARRAY_BUFFER, 0);
        glBindVertexArrayOES(0);
    }
    return this->_square;
}