Пример #1
0
void Mesh::InitTexMesh(const IndexedModel& model)
{
    m_numIndices = model.indices.size();
    
    glGenVertexArraysAPPLE(1, &m_vertexArrayObject);
    glBindVertexArrayAPPLE(m_vertexArrayObject);
    
    glGenBuffers(NUM_BUFFERS, m_vertexArrayBuffers);
    
    glBindBuffer(GL_ARRAY_BUFFER, m_vertexArrayBuffers[POSITION_VB]);
    glBufferData(GL_ARRAY_BUFFER, sizeof(model.positions[0]) * model.positions.size(), &model.positions[0], GL_STATIC_DRAW);
    glEnableVertexAttribArray(0);
    glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);
    
    glBindBuffer(GL_ARRAY_BUFFER, m_vertexArrayBuffers[TEXCOORD_VB]);
    glBufferData(GL_ARRAY_BUFFER, sizeof(model.texCoords[0]) * model.texCoords.size(), &model.texCoords[0], GL_STATIC_DRAW);
    glEnableVertexAttribArray(1);
    glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 0, 0);
    
    glBindBuffer(GL_ARRAY_BUFFER, m_vertexArrayBuffers[NORMAL_VB]);
    glBufferData(GL_ARRAY_BUFFER, sizeof(model.normals[0]) * model.normals.size(), &model.normals[0], GL_STATIC_DRAW);
    glEnableVertexAttribArray(2);
    glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, 0, 0);
    
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_vertexArrayBuffers[INDEX_VB]);
    glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(model.indices[0]) * model.indices.size(), &model.indices[0], GL_STATIC_DRAW);
    
    glBindVertexArrayAPPLE(0);
}
Пример #2
0
    void TextureAtlas::setupVAOAndVBO(){
        
        glGenVertexArraysAPPLE(1,&_vao);
        glBindVertexArrayAPPLE(_vao);
        
        glGenBuffers(2,&_bufferVBO[0]);
        glBindBuffer(GL_ARRAY_BUFFER,_bufferVBO[0]);
        glBufferData(GL_ARRAY_BUFFER,sizeof(V2F_C4F_T2F_Quad) * _capacity,_quads,GL_DYNAMIC_DRAW);
        
#define kStrip sizeof(_quads[0].bl)
        
        // vertices
        glEnableVertexAttribArray(_shader->get_A_PositionId());
        glVertexAttribPointer(_shader->get_A_PositionId(),2,GL_FLOAT,GL_FALSE,kStrip, (GLvoid*)offsetof(V2F_C4F_T2F,vertices));

        // colors
        glEnableVertexAttribArray(_shader->get_A_ColorId());
        glVertexAttribPointer(_shader->get_A_ColorId(),4,GL_FLOAT,GL_FALSE,kStrip,(GLvoid*)offsetof(V2F_C4F_T2F,colors));
        
        // texCoords
        glEnableVertexAttribArray(_shader->get_A_TexCoordsId());
        glVertexAttribPointer(_shader->get_A_TexCoordsId(),2,GL_FLOAT,GL_FALSE,kStrip, (GLvoid*)offsetof(V2F_C4F_T2F,texCoords));
        
        
        // indices
        glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,_bufferVBO[1]);
        glBufferData(GL_ELEMENT_ARRAY_BUFFER,sizeof(_indices[0]) * _capacity * 6,_indices,GL_STATIC_DRAW);
        
        // unbind vao vbos
        glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,0);
        glBindBuffer(GL_ARRAY_BUFFER,0);
        glBindVertexArrayAPPLE(0);
    }
Пример #3
0
void rxImage::draw(const float& x, const float& y, const float& w, const float& h) {
	bool vao_bound = false;

	if(!buffer_created) {
		vao_bound = true;
		glGenVertexArraysAPPLE(1, &vao); eglGetError();
		glBindVertexArrayAPPLE(vao); eglGetError();
		glGenBuffers(1, &vbo); eglGetError();
		glBindBuffer(GL_ARRAY_BUFFER, vbo); eglGetError();

		vector<VertexPT> buffer(6);
		buffer[0].set(0, 0, 0, 0, 1);
		buffer[1].set(w, 0, 0, 1, 1);
		buffer[2].set(w, h, 0, 1, 0);
		buffer[3].set(w, h, 0, 1, 0);
		buffer[4].set(0, h, 0, 0, 0);
		buffer[5].set(0, 0, 0, 0, 1);
		glBufferData(GL_ARRAY_BUFFER, sizeof(VertexPT) * buffer.size(), buffer[0].getPtr(), GL_DYNAMIC_DRAW); eglGetError();
		glEnableVertexAttribArray(shader.getAttribute("pos")); eglGetError();
		glEnableVertexAttribArray(shader.getAttribute("tex")); eglGetError();
		glVertexAttribPointer(shader.getAttribute("pos"), 3, GL_FLOAT, GL_FALSE, sizeof(VertexPT), (GLvoid*)offsetof(VertexPT, pos)); eglGetError();
		glVertexAttribPointer(shader.getAttribute("tex"), 2, GL_FLOAT, GL_FALSE, sizeof(VertexPT), (GLvoid*)offsetof(VertexPT, tex)); eglGetError();
		buffer_created = true;
		prev_w = w;
		prev_h = h;
	}
	else if( (prev_w != 0 && prev_w != w) || (prev_h != 0 && prev_h != h) ) {
		vector<VertexPT> buffer(6);
		buffer[0].set(0, 0, 0, 0, 1);
		buffer[1].set(w, 0, 0, 1, 1);
		buffer[2].set(w, h, 0, 1, 0);
		buffer[3].set(w, h, 0, 1, 0);
		buffer[4].set(0, h, 0, 0, 0);
		buffer[5].set(0, 0, 0, 0, 1);
		glBindBuffer(GL_ARRAY_BUFFER, vbo); eglGetError();
		glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(VertexPT) * buffer.size(), buffer[0].getPtr()); eglGetError();
		prev_w = w;
		prev_h = h;	
	}
	
	if(!vao_bound) {
		glBindVertexArrayAPPLE(vao); eglGetError();
	}	

	shader.enable();
	glEnable(GL_TEXTURE_2D); eglGetError();
	glActiveTexture(GL_TEXTURE0); eglGetError();
	glBindTexture(GL_TEXTURE_2D, tex.getID()); eglGetError();
	shader.uniform1i("texture", 0);
	
	model_matrix.setPosition(x, y,0);
	shader.uniformMat4fv("modelview_matrix", model_matrix.getPtr());
	glDrawArrays(GL_TRIANGLES, 0, 6); eglGetError();
	
	shader.disable();
	glDisable(GL_TEXTURE_2D);
	glBindVertexArrayAPPLE(0);
	glBindBuffer(GL_ARRAY_BUFFER, 0);
	
}
Пример #4
0
void Track::draw() {
    glBindVertexArrayAPPLE(vertexArrayObjectHandle);
    glDrawElements(GL_TRIANGLES,
                   vertexCount,
                   GL_UNSIGNED_INT,
                   0);
    glBindVertexArrayAPPLE(0);
}
Пример #5
0
void YUV420PGrabber::unbindVAO() {
#if YUV420P_USE_APPLE_VAO
  glBindVertexArrayAPPLE(0);
#else
  glBindVertexArray(0);
#endif
}
Пример #6
0
void
init( void )
{
    vec3 vertices[4] = {
	vec3( 0.0, 0.0, -1.0 ),
	vec3( 0.0, 0.942809, 0.333333 ),
	vec3( -0.816497, -0.471405, 0.333333 ),
	vec3( 0.816497, -0.471405, 0.333333 )
    };	

    // Subdivide the original tetrahedron
    divide_tetra( vertices[0], vertices[1], vertices[2], vertices[3],
		  NumTimesToSubdivide );

    // Create a vertex array object
    GLuint vao;
    glGenVertexArraysAPPLE( 1, &vao );
    glBindVertexArrayAPPLE( vao );

    // Create and initialize a buffer object
    GLuint buffer;
    glGenBuffers( 1, &buffer );
    glBindBuffer( GL_ARRAY_BUFFER, buffer );

    // First, we create an empty buffer of the size we need by passing
    //   a NULL pointer for the data values
    glBufferData( GL_ARRAY_BUFFER, sizeof(points) + sizeof(colors),
		  NULL, GL_STATIC_DRAW );

    // Next, we load the real data in parts.  We need to specify the
    //   correct byte offset for placing the color data after the point
    //   data in the buffer.  Conveniently, the byte offset we need is
    //   the same as the size (in bytes) of the points array, which is
    //   returned from "sizeof(points)".
    glBufferSubData( GL_ARRAY_BUFFER, 0, sizeof(points), points );
    glBufferSubData( GL_ARRAY_BUFFER, sizeof(points), sizeof(colors), colors );

    // Load shaders and use the resulting shader program
    GLuint program = InitShader( "vshader24.glsl", "fshader24.glsl" );
    glUseProgram( program );

    // Initialize the vertex position attribute from the vertex shader    
    GLuint vPosition = glGetAttribLocation( program, "vPosition" );
    glEnableVertexAttribArray( vPosition );
    glVertexAttribPointer( vPosition, 3, GL_FLOAT, GL_FALSE, 0,
                           BUFFER_OFFSET(0) );

    // Likewise, initialize the vertex color attribute.  Once again, we
    //    need to specify the starting offset (in bytes) for the color
    //    data.  Just like loading the array, we use "sizeof(points)"
    //    to determine the correct value.
    GLuint vColor = glGetAttribLocation( program, "vColor" );
    glEnableVertexAttribArray( vColor );
    glVertexAttribPointer( vColor, 3, GL_FLOAT, GL_FALSE, 0,
                           BUFFER_OFFSET(sizeof(points)) );

    glEnable( GL_DEPTH_TEST );

    glClearColor( 1.0, 1.0, 1.0, 1.0 ); /* white background */
}
Пример #7
0
void init()
{

 // Create a vertex array object
    GLuint vao;
    glGenVertexArraysAPPLE( 1, &vao );
    glBindVertexArrayAPPLE( vao );

/* set up buffer object */

   glGenBuffers(1, buffers);
   glBindBuffer(GL_ARRAY_BUFFER, buffers[0]);
   glBufferData(GL_ARRAY_BUFFER, sizeof(square), square, GL_STATIC_DRAW);

   program = InitShader("vshader48.glsl", "fshader48.glsl");
   glUseProgram( program );

   loc = glGetAttribLocation(program, "vPosition");
   glEnableVertexAttribArray(loc);
   glVertexAttribPointer(loc, 4, GL_FLOAT, GL_FALSE, 0, 0);
   matrix_loc = glGetUniformLocation(program, "model_view");
   projection_loc = glGetUniformLocation(program, "projection");
   color_loc = glGetUniformLocation(program, "fcolor");

   for(int i =0; i<4; i++) for(int j =0; j<4;j++) m[i][j] = 0.0;
   m[0][0] = m[1][1] = m[2][2] = 1.0;
   m[3][1] = -1.0/light[1];

   glClearColor(1.0, 1.0, 1.0, 1.0); /* white background */
}
Пример #8
0
void VAO::bind() {
    if(vao_id == -1) {
        create();
    }
    glBindVertexArrayAPPLE(vao_id);
    eglGetError();
}
Пример #9
0
// OpenGL initialization
void
init()
{
    mesh();

    // Create a vertex array object
    GLuint vao;
    glGenVertexArraysAPPLE( 1, &vao );
    glBindVertexArrayAPPLE( vao );

    // Create and initialize a buffer object
    GLuint buffer;
    glGenBuffers( 1, &buffer );
    glBindBuffer( GL_ARRAY_BUFFER, buffer );
    glBufferData( GL_ARRAY_BUFFER, sizeof(points), points, GL_STATIC_DRAW ); 

    // Load shaders and use the resulting shader program
    GLuint program = InitShader( "vmesh.glsl", "fmesh.glsl" );
    glUseProgram( program );

    // set up vertex arrays
    GLuint vPosition = glGetAttribLocation( program, "vPosition" );
    glEnableVertexAttribArray( vPosition );
    glVertexAttribPointer( vPosition, 4, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(0) );

    timeParam = glGetUniformLocation(program, "time");
    MVP_loc = glGetUniformLocation(program, "ModelViewProjection");
    
    glClearColor( 1.0, 1.0, 1.0, 1.0 );
    glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
}
Пример #10
0
void Effects::bind() {
	glBindVertexArrayAPPLE(vao);
	shader.begin();

	glActiveTexture(GL_TEXTURE0); 
	shader.setUniform1i("img", 0);
	glBindTexture(GL_TEXTURE_2D, fbo_tex);
}
Пример #11
0
void Cube::InitDraw(){

    // Initialize the data array on CPU

    m_Points[0] = Eigen::Vector4f( -0.5, -0.5,  0.5, 1.0 );
    m_Points[1] = Eigen::Vector4f( -0.5,  0.5,  0.5, 1.0 );
    m_Points[2] = Eigen::Vector4f(  0.5,  0.5,  0.5, 1.0 );
    m_Points[3] = Eigen::Vector4f(  0.5, -0.5,  0.5, 1.0 );
    m_Points[4] = Eigen::Vector4f( -0.5, -0.5, -0.5, 1.0 );
    m_Points[5] = Eigen::Vector4f( -0.5,  0.5, -0.5, 1.0 );
    m_Points[6] = Eigen::Vector4f(  0.5,  0.5, -0.5, 1.0 );
    m_Points[7] = Eigen::Vector4f(  0.5, -0.5, -0.5, 1.0 );
    
    m_Vertices = new Eigen::Vector4f[36];
	m_Normals = new Eigen::Vector3f[36];
    m_Index = 0;
    
    //generate the 6 faces with distinct colors
    GenFace( 5, 1, 0, 3, 2 );
    GenFace( 1, 2, 3, 7, 6 );
    GenFace( 2, 3, 0, 4, 7 );
    GenFace( 3, 6, 5, 1, 2 );
    GenFace( 4, 4, 5, 6, 7 );
    GenFace( 0, 5, 4, 0, 1 );

    //Create the Vertex Array and Buffers, bind them
#ifdef __APPLE__
    glGenVertexArraysAPPLE(1, &m_vertexArrayObject);
    glBindVertexArrayAPPLE(m_vertexArrayObject);//use as current vertex array
#else
	glGenVertexArrays(1, &m_vertexArrayObject);
    glBindVertexArray(m_vertexArrayObject);//use as current vertex array
#endif
    glGenBuffers(1, &m_vertexBufferObject);//generate buffer for current vertex array
    glBindBuffer(GL_ARRAY_BUFFER, m_vertexBufferObject);//use as current buffer

     //Send data from CPU to GPU
    glBufferData(GL_ARRAY_BUFFER, (sizeof(m_Vertices[0]) + sizeof(m_Normals[0]))*36, NULL, GL_STATIC_DRAW);//send data to current buffer
    glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(m_Vertices[0])*36, m_Vertices);
	glBufferSubData(GL_ARRAY_BUFFER, sizeof(m_Vertices[0])*36, sizeof(m_Normals[0])*36, m_Normals);
    
    
    //load and compile shaders on GPU, use current shader program
    m_shader = Util::InitShader( "vPhong.glsl", "fPhong.glsl" );
    glUseProgram(m_shader);
    
    
    // Link the Shader with the buffer data
    // initialize the vertex position attribute from the vertex shader
    GLuint position = glGetAttribLocation( m_shader, "vPosition" );
    glEnableVertexAttribArray( position );
    glVertexAttribPointer(position, 4, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(0)); 

	GLuint normal = glGetAttribLocation(m_shader, "vNormal");
    glEnableVertexAttribArray(normal);
    glVertexAttribPointer(normal, 3, GL_FLOAT, GL_FALSE,0, BUFFER_OFFSET(sizeof(m_Vertices[0])*36));
    
}
Пример #12
0
void Extensions3DOpenGL::bindVertexArrayOES(Platform3DObject array)
{
    m_context->makeContextCurrent();
#if !PLATFORM(GTK) && !PLATFORM(QT) && !PLATFORM(EFL) && defined(GL_APPLE_vertex_array_object) && GL_APPLE_vertex_array_object
    glBindVertexArrayAPPLE(array);
#else
    UNUSED_PARAM(array);
#endif
}
Пример #13
0
_JATTA_EXPORT void Jatta::OpenGL::VertexArray::Unbind()
{
#   ifdef JATTA_MACOS
    glBindVertexArrayAPPLE(0);
#   else
    glBindVertexArray(0);
#   endif
    GLCHECK("Failed to unbind vertex array.");
}
Пример #14
0
void Extensions3DOpenGL::bindVertexArrayOES(Platform3DObject array)
{
    m_context->makeContextCurrent();
#if GL_APPLE_vertex_array_object
    glBindVertexArrayAPPLE(array);
#else
    ASSERT_UNUSED(array, supports(array));
#endif
}
Пример #15
0
/* Initialize buffers. 
 * Takes a SceneObject and a vector of pairs representing the 
 * attributes in the shader.
 * pair<0, GLuint> - point data
 * pair<1, GLuint> - color data
 * pair<2, GLuint> - normals data
 */
void initBuffers(SceneObject *so, std::vector< std::pair<int,GLuint> > addresses)
{
	glBindVertexArrayAPPLE(so->vao);

	for (int i=0; i<addresses.size(); i++)
	{
		if (addresses[i].first == 0)
		{
			glGenBuffers(1, &so->vertexbuffer);
			glBindBuffer(GL_ARRAY_BUFFER, so->vertexbuffer);
			glBufferData(GL_ARRAY_BUFFER, sizeof(glm::vec4)*so->numVertices, NULL, GL_STATIC_DRAW);
			glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(glm::vec4)*so->numVertices, so->points);
			
			glEnableVertexAttribArray(addresses[i].second);
			glVertexAttribPointer(addresses[i].second, 4, GL_FLOAT, GL_FALSE, 0, (GLvoid*)(0));
		}
		
		if (addresses[i].first == 1)
		{
			glGenBuffers(1, &so->colorbuffer);
			glBindBuffer(GL_ARRAY_BUFFER, so->colorbuffer);
			glBufferData(GL_ARRAY_BUFFER, sizeof(glm::vec4)*so->numVertices, NULL, GL_STATIC_DRAW);
			glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(glm::vec4)*so->numVertices, so->colors);
			
			glEnableVertexAttribArray(addresses[i].second);
			glVertexAttribPointer(addresses[i].second, 4,GL_FLOAT, GL_FALSE, 0, (GLvoid*)(0));
		}
		
		if (addresses[i].first == 2)
		{
			glGenBuffers(1, &so->normalbuffer);
			glBindBuffer(GL_ARRAY_BUFFER, so->normalbuffer);
			glBufferData(GL_ARRAY_BUFFER, sizeof(glm::vec4)*so->numVertices, NULL, GL_STATIC_DRAW);
			glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(glm::vec4)*so->numVertices, so->normals);
			
			glEnableVertexAttribArray(addresses[i].second);
			glVertexAttribPointer(addresses[i].second, 4,GL_FLOAT, GL_FALSE, 0, (GLvoid*)(0));
		}

	}

	glBindVertexArrayAPPLE(0);

}
void Extensions3DOpenGL::bindVertexArrayOES(Platform3DObject array)
{
    if (!array)
        return;

    m_context->makeContextCurrent();
#if defined GL_APPLE_vertex_array_object && GL_APPLE_vertex_array_object
    glBindVertexArrayAPPLE(array);
#endif
}
Пример #17
0
void Cylinder::draw(bool edges, bool mesh)
{
	// Use current object's program
	glUseProgram(m_program);

	// Bind buffers
#ifdef __APPLE__
    glBindVertexArrayAPPLE(m_vertexArrayObject); 
#else
	glBindVertexArray(m_vertexArrayObject);
#endif
    glBindBuffer(GL_ARRAY_BUFFER, m_vertexBufferObject);
	glBindTexture(GL_TEXTURE_2D, m_textureBufferObject);

	// Get transformation matrices (POSSIBLE ERRORS -> ROTATION AROUND Y)
	mat4 transform = RotateY(m_rotAngle.y) * Translate(m_location) * RotateZ(m_rotAngle.z) * RotateX(m_rotAngle.x) * Scale(m_size);

	// Pass uniform data to the shader program
	glUniformMatrix4fv(glGetUniformLocation(m_program, "wMo"), 1, GL_TRUE, transform);
	glUniformMatrix4fv(glGetUniformLocation(m_program, "cMw"), 1, GL_TRUE, m_camPtr->getTranslation());
	glUniformMatrix4fv(glGetUniformLocation(m_program, "proj"), 1, GL_TRUE, m_camPtr->getPerspective());

	// vShader
	glUniform4fv(glGetUniformLocation(m_program, "camPos"), 1, m_camPtr->getPosition());
	glUniform4fv(glGetUniformLocation(m_program, "lightPos"), 1, m_lightPtr->getPosition());
	
	// fShader
	glUniform1f(glGetUniformLocation(m_program, "Ambient"), m_ambient);
	glUniform1f(glGetUniformLocation(m_program, "Diffuse"), m_diffuse);
	glUniform1f(glGetUniformLocation(m_program, "Specular"), m_specular);
	glUniform1f(glGetUniformLocation(m_program, "Shininess"), m_shininess);
	glUniform4fv(glGetUniformLocation(m_program, "lightColor"), 1, m_lightPtr->getColor());

	// Draw edges
	if(edges)
	{
		glUniform4fv(glGetUniformLocation(m_program, "Color"), 1, vec4(0.0, 0.0, 1.0, 1.0));
		glEnable(GL_POLYGON_OFFSET_FILL);
		glPolygonOffset(0.5, 0.5);
		glDrawArrays(GL_LINES, m_numVertices, m_numEdges);
		glDisable(GL_POLYGON_OFFSET_FILL);
	}

	// Draw objects
	if(m_textureOn)
		glUniform1i(glGetUniformLocation(m_program, "EnableTex"), 1);
	glUniform4fv(glGetUniformLocation(m_program, "Color"), 1, m_color);
	if(mesh)
		glDrawArrays(GL_LINE_STRIP, 0, m_numVertices);
	else
		glDrawArrays(GL_TRIANGLES, 0, m_numVertices);
	glUniform1i(glGetUniformLocation(m_program, "EnableTex"), 0);
}
Пример #18
0
void Extensions3DOpenGL::bindVertexArrayOES(Platform3DObject array)
{
    m_context->makeContextCurrent();
#if (PLATFORM(GTK) || PLATFORM(EFL) || PLATFORM(WIN) || PLATFORM(IOS))
    if (isVertexArrayObjectSupported())
        glBindVertexArray(array);
#elif defined(GL_APPLE_vertex_array_object) && GL_APPLE_vertex_array_object
    glBindVertexArrayAPPLE(array);
#else
    UNUSED_PARAM(array);
#endif
}
Пример #19
0
void
init( void )
{
    colorcube();

    /* set up particles with random locations and velocities */
    for ( int i = 0; i < num_particles; i++ ) {
        particles[i].mass = 1.0;
        particles[i].color = i % NUM_COLORS;
        for ( int j = 0; j < 3; j++ ) {
            particles[i].position[j] =
                2.0 * ( ( float ) rand() / RAND_MAX ) - 1.0;
            particles[i].velocity[j] =
                speed * 2.0 * ( ( float ) rand() / RAND_MAX ) - 1.0;
        }
        particles[i].position[3] = 1.0;
    }

    // Create a vertex array object
    GLuint vao;
    glGenVertexArraysAPPLE( 1, &vao );
    glBindVertexArrayAPPLE( vao );

    // Create and initialize a buffer object
    glGenBuffers( 1, &buffer );
    glBindBuffer( GL_ARRAY_BUFFER, buffer );
    glBufferData( GL_ARRAY_BUFFER, sizeof(points) + sizeof(point_colors),
		  NULL, GL_STATIC_DRAW );
    glBufferSubData( GL_ARRAY_BUFFER, 0, sizeof(points), points );
    glBufferSubData( GL_ARRAY_BUFFER, sizeof(points), sizeof(point_colors), point_colors );

    // Load shaders and use the resulting shader program
    GLuint program = InitShader( "vshader91.glsl", "fshader91.glsl" );
    glUseProgram( program );

    // set up vertex arrays
    GLuint vPosition = glGetAttribLocation( program, "vPosition" );
    glEnableVertexAttribArray( vPosition );
    glVertexAttribPointer( vPosition, 4, GL_FLOAT, GL_FALSE, 0,
			   BUFFER_OFFSET(0) );

    GLuint vColor = glGetAttribLocation( program, "vColor" ); 
    glEnableVertexAttribArray( vColor );
    glVertexAttribPointer( vColor, 4, GL_FLOAT, GL_FALSE, 0,
			   BUFFER_OFFSET(sizeof(points)) );

    model_view_loc = glGetUniformLocation( program, "ModelView" );
    projection_loc = glGetUniformLocation( program, "Projection" );

    glClearColor( 0.5, 0.5, 0.5, 1.0 );
    glPointSize( point_size );
}
Пример #20
0
void display()
{
	glClear(GL_COLOR_BUFFER_BIT);
#if defined(WIN)
	glBindVertexArray(VAOs[Triangles]);
#endif
#if defined(MAC)
    glBindVertexArrayAPPLE(VAOs[Triangles]);
#endif
	glDrawArrays(GL_TRIANGLES,0,NumVertices);
	
	glFlush();
}
Пример #21
0
_JATTA_EXPORT void Jatta::OpenGL::VertexArray::Bind()
{
    if (vertexArray == 0)
    {
        throw std::runtime_error("Cannot bind invalid vertex array.");
    }
#   ifdef JATTA_MACOS
    glBindVertexArrayAPPLE(vertexArray);
#   else
    glBindVertexArray(vertexArray);
#   endif
    GLCHECK("Failed to bind vertex array.");
}
Пример #22
0
void init(){
  print_version_info();

  print_err("start init");
  vec2 points[NumPoints];

  // Specifiy the vertices for a triangle
  vec2 vertices[3] = {
      vec2( -1.0, -1.0 ), vec2( 0.0, 1.0 ), vec2( 1.0, -1.0 )
  };

  // Select an arbitrary initial point inside of the triangle
  points[0] = vec2( 0.25, 0.50 );

  // compute and store N-1 new points
  for ( int i = 1; i < NumPoints; ++i ) {
      int j = rand() % 3;   // pick a vertex at random

      // Compute the point halfway between the selected vertex
      //   and the previous point
      points[i] = ( points[i - 1] + vertices[j] ) / 2.0;
  }

  // print_err("finish making points");
  // Create a vertex array object
  GLuint vao[1];
  glGenVertexArraysAPPLE( 1, vao );
  glBindVertexArrayAPPLE( vao[0] );
  // print_err("gen and bind vertex arrays");
  

  // Create and initialize a buffer object
  GLuint buffer;
  glGenBuffers( 1, &buffer );
  glBindBuffer( GL_ARRAY_BUFFER, buffer );
  glBufferData( GL_ARRAY_BUFFER, sizeof(points), points, GL_STATIC_DRAW );
  // print_err("bind buffer and buffer data");

  // Load shaders and use the resulting shader program
  GLuint program = InitShader( "vertex1.glsl", "frag1.glsl" );
  glUseProgram(program);
  print_err("glUseProgram");

  // Initialize the vertex position attribute from the vertex shader
  GLuint loc = glGetAttribLocation( program, "vPosition" );
  glEnableVertexAttribArray( loc );
  glVertexAttribPointer( loc, 2, GL_FLOAT, GL_FALSE, 0,
                         BUFFER_OFFSET(0) );

  glClearColor( 1.0, 1.0, 1.0, 1.0 ); // white background
}
Пример #23
0
void init(void) {
    vec2 points[6] = {
        vec2(-0.5, -0.5),vec2(0.5, -0.5),
        vec2(0.5, 0.5),  vec2(0.5, 0.5),
        vec2(-0.5, 0.5), vec2(-0.5, -0.5)
    };
    
    GLuint vao, buffer;
    glGenVertexArraysAPPLE(1, &vao);
    glBindVertexArrayAPPLE(vao);
    
    
    
}
Пример #24
0
void
init( void )
{
    vec3 points[NumPoints];

    // Specifiy the vertices for a tetrahedron
    vec3 vertices[] = {
	vec3( -0.5, -0.5, -0.5 ),
	vec3(  0.5, -0.5, -0.5 ),
	vec3(  0.0,  0.5,  0.0 ),
	vec3(  0.0, -0.5,  0.5 )
    };

    // Select an arbitrary initial point inside of the triangle
    points[0] = vec3( 0.0, 0.0, 0.0 );

    // compute and store N-1 new points
    for ( int i = 1; i < NumPoints; ++i ) {
        int j = rand() % 3;   // pick a vertex at random

        // Compute the point halfway between the selected vertex
        //   and the previous point
        points[i] = ( points[i - 1] + vertices[j] ) / 2.0;
    }


    // Create a vertex array object
    GLuint vao;
    glGenVertexArraysAPPLE( 1, &vao );
    glBindVertexArrayAPPLE( vao );

    // Create and initialize a buffer object
    GLuint buffer;
    glGenBuffers( 1, &buffer );
    glBindBuffer( GL_ARRAY_BUFFER, buffer );
    glBufferData( GL_ARRAY_BUFFER, sizeof(points), points, GL_STATIC_DRAW );

    // Load shaders and use the resulting shader program
    GLuint program = InitShader( "vshader23.glsl", "fshader23.glsl" );
    glUseProgram( program );

    // Initialize the vertex position attribute from the vertex shader
    GLuint loc = glGetAttribLocation( program, "vPosition" );
    glEnableVertexAttribArray( loc );
    glVertexAttribPointer( loc, 3, GL_FLOAT, GL_FALSE, 0, 
                           BUFFER_OFFSET(0) );

    glClearColor( 1.0, 1.0, 1.0, 1.0 ); // white background
}
Пример #25
0
void Cube::Draw(int type, const Camera& camera,const Light& light){
	
    //Get new position of the cube and update the model view matrix
    Eigen::Affine3f wMo;//object to world matrix
    Eigen::Affine3f cMw;
    Eigen::Affine3f proj;

    glUseProgram(m_shader);
#ifdef __APPLE__
    glBindVertexArrayAPPLE(m_vertexArrayObject); 
#else
	glBindVertexArray(m_vertexArrayObject);
#endif
    
    glBindBuffer(GL_ARRAY_BUFFER, m_vertexBufferObject);//use as current buffer
  
	GLuint camera_position = glGetUniformLocation(m_shader, "cameraPosition");
    GLuint light_position = glGetUniformLocation(m_shader, "lightPosition");
	GLuint color = glGetUniformLocation(m_shader, "Color");

    GLuint object2world = glGetUniformLocation(m_shader, "wMo");
    GLuint world2camera = glGetUniformLocation(m_shader, "cMw"); 
	GLuint projection = glGetUniformLocation(m_shader, "proj");

    wMo = m_Trans;

    proj = Util::Perspective( camera.m_fovy, camera.m_aspect, camera.m_znear, camera.m_zfar );
	cMw = camera.m_cMw;//Angel::LookAt(camera.position,camera.lookat, camera.up );
 
    glUniformMatrix4fv( object2world , 1, GL_FALSE, wMo.data() );
    glUniformMatrix4fv( world2camera, 1, GL_FALSE, cMw.data());
    glUniformMatrix4fv( projection, 1, GL_FALSE, proj.data());
	glUniform4fv(camera_position, 1, camera.m_position.data());
    glUniform4fv(light_position, 1, light.m_position.data());
	Eigen::Vector4f l_color(m_Color[0],m_Color[1],m_Color[2],1.0);
  	glUniform4fv(color,1,l_color.data());
	
	switch (type) {
        case DRAW_MESH:
            glDrawArrays(GL_LINES, 0, 36);
            break;
        case DRAW_PHONG:
            glDrawArrays(GL_TRIANGLES, 0, 36);
            break;
    }
    

}
Пример #26
0
void init() 
{
	// Create a vertex array object
	GLuint vao[1];
	#ifdef __APPLE__       // For use with OS X
		glGenVertexArraysAPPLE(1, vao );
		glBindVertexArrayAPPLE(vao[0] );
	#else		       // Other (Linux)
		glGenVertexArrays(1, vao );
		glBindVertexArray(vao[0] );       
	#endif

	// Create and initialize a buffer object
	    GLuint buffer;
	    glGenBuffers( 2, &buffer );
	    glBindBuffer( GL_ARRAY_BUFFER, buffer );
	    glBufferData( GL_ARRAY_BUFFER, sizeof(points) + sizeof(colors),
			  NULL, GL_STATIC_DRAW );
	    glBufferSubData( GL_ARRAY_BUFFER, 0, sizeof(points), points );
	    glBufferSubData( GL_ARRAY_BUFFER, sizeof(points), sizeof(colors), colors );



	// Load shaders and use the resulting shader program
	GLuint program = InitShader( "v_bezier.glsl", "f_bezier.glsl" );
	glUseProgram( program );

	// set up vertex arrays
	    GLuint vPosition = glGetAttribLocation( program, "vPosition" );
	    glEnableVertexAttribArray( vPosition );
	    glVertexAttribPointer( vPosition, 4, GL_FLOAT, GL_FALSE, 0,
				   BUFFER_OFFSET(0) );

	    GLuint vColor = glGetAttribLocation( program, "vColor" ); 
	    glEnableVertexAttribArray( vColor );
	    glVertexAttribPointer( vColor, 4, GL_FLOAT, GL_FALSE, 0,
				   BUFFER_OFFSET(sizeof(points)) );
	
	// Generate the Projection Matrix and send to vertex shader:
	GLuint Projection_loc = glGetUniformLocation( program, "Projection" );
	glUniformMatrix4fv( Projection_loc, 1, GL_TRUE, Ortho( -1,1,-1,1, -1 ,1 ) );

    	glShadeModel(GL_FLAT);
	glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
	// set clear color to white
	glClearColor (0.95, 0.95, 0.95, 1.0);

}
Пример #27
0
void Winner::draw_shape(  ){
   
#ifdef __APPLE__
   glBindVertexArrayAPPLE( vao );
#else
   glBindVertexArray( vao ); 
#endif

   glUniform1i( drawmode, 2 );

   glBindBuffer( GL_ARRAY_BUFFER, buffer );
   glBindTexture( GL_TEXTURE_2D, texture );
   glDrawArrays( GL_TRIANGLES, 0, num_points_main + num_points_p + num_points_p2);


}
Пример #28
0
void ModelRenderMesh::setup() {
#ifdef RENDER_PIPELINE
    // TODO
#else
    // Create the buffers for the vertices atttributes
    #ifdef RENDER_VAO_NORMAL
        glGenVertexArrays(1, &geometryVAO);
        glBindVertexArray(geometryVAO);
    #else
        glGenVertexArraysAPPLE(1, &geometryVAO);
        glBindVertexArrayAPPLE(geometryVAO);
    #endif

    // Create the buffers for the vertices atttributes
    glGenBuffers(7, m_Buffers);
#endif
}
Пример #29
0
void Extensions3DOpenGL::bindVertexArrayOES(Platform3DObject array)
{
    m_context->makeContextCurrent();
#if (PLATFORM(GTK) || PLATFORM(EFL) || PLATFORM(WIN))
    if (isVertexArrayObjectSupported())
        glBindVertexArray(array);
#elif PLATFORM(QT)
#if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0)
    if (isVertexArrayObjectSupported())
        m_vaoFunctions->glBindVertexArray(array);
#endif
#elif defined(GL_APPLE_vertex_array_object) && GL_APPLE_vertex_array_object
    glBindVertexArrayAPPLE(array);
#else
    UNUSED_PARAM(array);
#endif
}
Пример #30
-1
void Mesh::Draw()
{
	glBindVertexArrayAPPLE(m_vertexArrayObject);

	//glDrawElements(GL_TRIANGLES, m_numIndices, GL_UNSIGNED_INT, 0);
	glDrawElementsBaseVertex(GL_TRIANGLES, m_numIndices, GL_UNSIGNED_INT, 0, 0);

	glBindVertexArrayAPPLE(0);
}