Jump to content
  • Advertisement
Sign in to follow this  
KKTHXBYE

OpenGL Can't draw anything OGLES2 glsl 100

This topic is 1201 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

im trying to draw something on android with opengl es 2 support, now i am unable to see anythig

 

 

 

so first i create a shader:

after successful compiling and linking 

i fetch 

            vertex_pos 		= glGetAttribLocation(program,"Vpos");
            texture_coord 	= glGetAttribLocation(program,"Vtexcoord");
            vertex_normal 	= glGetAttribLocation(program,"Vnormal");
            vertex_color 	= glGetAttribLocation(program,"Vcolor");

            MVP[0] = glGetUniformLocation(program, "MVP1");
            MVP[1] = glGetUniformLocation(program, "MVP2");
            MVP[2] = glGetUniformLocation(program, "MVP3");
            MVP[3] = glGetUniformLocation(program, "MVP4");


program is GLuint

then i load model form a file and send data to gpu with:

void SendToGPU(TShaderObject shader)
{

	 glGenBuffers(1, &m_Buffer);
	 glBindBuffer(GL_ARRAY_BUFFER, m_Buffer);
	 glBufferData(GL_ARRAY_BUFFER, sizeof(TTGLVertex<T,float,float>) * header.LENGTH, AOS, GL_STATIC_DRAW);

    glVertexAttribPointer(shader.vertex_pos, 3, GL_FLOAT, GL_FALSE,	sizeof(TTGLVertex<T,float,float>),		(void*)(offsetof(struct TFloatVertex, v)));
    glVertexAttribPointer(shader.texture_coord, 2, GL_FLOAT, GL_FALSE, sizeof(TTGLVertex<T,float,float>),  	(void*)(offsetof(struct TFloatVertex, t)));
    glVertexAttribPointer(shader.vertex_normal, 3, GL_FLOAT, GL_TRUE, 	sizeof(TTGLVertex<T,float,float>), 	(void*)(offsetof(struct TFloatVertex, n)));
    glVertexAttribPointer(shader.vertex_color, 4, GL_FLOAT, GL_FALSE, sizeof(TTGLVertex<T,float,float>),  	(void*)(offsetof(struct TFloatVertex, c)));


    glEnableVertexAttribArray(shader.vertex_pos);
    glEnableVertexAttribArray(shader.texture_coord);
    glEnableVertexAttribArray(shader.vertex_normal);
    glEnableVertexAttribArray(shader.vertex_color);

    glBindBuffer(GL_ARRAY_BUFFER, 0);

}

where:
TTGLVertex<float,float,float> * AOS; //AOS is a shortcut of Array of Structure

template <class Vert, class Normal, class Color> class TTGLVertex
{
public:
	t3dpoint<Vert> v;
	textpoint t;
	t3dpoint<Normal> n;
	t4dpoint<Color> c;
};

struct TFloatVertex
{
	t3dpoint<float> v;  //float x; float y; float z;
	textpoint t; 		//float x; float y;
	t3dpoint<float> n;  //float x; float y; float z;
	t4dpoint<float> c;  //float x; float y; float z; float w;
};

now to actually draw anything i call a function:

 void  DrawSimpleModel(TShaderObject shader)
{
	    glBindBuffer(GL_ARRAY_BUFFER, m_Buffer);
	    glVertexAttribPointer(shader.vertex_pos, 3, GL_FLOAT, GL_FALSE,	sizeof(TTGLVertex<T,float,float>),	(void*)(offsetof(struct TFloatVertex, v)));
	    glVertexAttribPointer(shader.texture_coord, 2, GL_FLOAT, GL_FALSE, sizeof(TTGLVertex<T,float,float>),  (void*)(offsetof(struct TFloatVertex, t)));
	    glVertexAttribPointer(shader.vertex_normal, 3, GL_FLOAT, GL_TRUE, 	sizeof(TTGLVertex<T,float,float>),  (void*)(offsetof(struct TFloatVertex, n)));
	    glVertexAttribPointer(shader.vertex_color, 4, GL_FLOAT, GL_FALSE, sizeof(TTGLVertex<T,float,float>),  (void*)(offsetof(struct TFloatVertex, c)));

	    //glDrawArrays to determine if we need to go through loop and draw everything or we can simply call it once since the model has onlt gl_triangles
	    int i;
	    for (i = 0; i < HOW_MANY_FACES_IN_MODEL; i++)
	    glDrawArrays(GL_TRIANGLES, VBO_BE[i].INDEX_START , VBO_BE[i].length);
}

now shaders:

vertex

attribute vec3 Vpos;
attribute vec2 Vtexcoord;
attribute vec3 Vnormal;
attribute vec4 Vcolor;


uniform vec4 MVP1;
uniform vec4 MVP2;
uniform vec4 MVP3;
uniform vec4 MVP4;

vec4 vertexClip;

float dp43(vec4 matrow, vec3 p)
{
return ( (matrow.x*p.x) + (matrow.y*p.y) + (matrow.z*p.z) + matrow.w );
}


 
void main()
{
vertexClip.x = dp43(MVP1, Vpos);
vertexClip.y = dp43(MVP2, Vpos);
vertexClip.z = dp43(MVP3, Vpos);
vertexClip.w = dp43(MVP4, Vpos);

gl_Position = vertexClip;

}



fragment

void main()
{
gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
}

and thats all i think i provided enought info

 

cheers

 

 

oh yes i set MVP matrix  - the camera is always facing 0,0,0 point where the model should be 

Edited by WiredCat

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!