Loading Texture with opengl es 2

Loading Texture with opengl es 2
0.0 0


Is anybody know how to load or some good tutorial for texture with opengl es 2 and use it in draw…
I didn’t find any with opengl 2
Thank you all


Follow this tutorial:


Replace the open gl part with the following code snippet:
// mTexture : Texture you want to bind on the polygon.
// mVertices : 2D array of vertices of the polygon.
// mTexCoords : 2D array of UV values of your texture.
// mSegments : number of the segments used.@

ccGLBindTexture2D(mTexture->getName()); mTexture->getShaderProgram()->use(); mTexture->getShaderProgram()->setUniformForModelViewProjectionMatrix(); ccGLEnableVertexAttribs( kCCVertexAttribFlag_Position | kCCVertexAttribFlag_TexCoords); glVertexAttribPointer(kCCVertexAttrib_Position, 2, GL_FLOAT, GL_FALSE, 0, mVertices); glVertexAttribPointer(kCCVertexAttrib_TexCoords, 2, GL_FLOAT, GL_FALSE, 0, mTexCoords); glDrawArrays(GL_TRIANGLE_FAN, 0,mSegments+2);


Thank you for your good response Vikas…
I am following this link :
I have done upto 2 part but i am not getting that texture on the screen as in 3rd part.I am trying to find some solution of it…

Here are the 2 methods of the MyNode class made from your link…

MyNode::MyNode() {
// Load the texture
texture = cocos2d::CCTextureCache::sharedTextureCache()>addImage;
GLfloat size = texture
// Vertices for the square (we’ll be using a triangle strip)
vertices[0] = Vertex2DMake(size, size);
vertices[1] = Vertex2DMake;
vertices[2] = Vertex2DMake;
vertices[3] = Vertex2DMake;
CCLOG (“Vertex initialized”);
// Because the texture is flipped about its x-axis,
// we flip the y coordinates to correct this.
textCoords[0] = Vertex2DMake;
textCoords[1] = Vertex2DMake;
textCoords[2] = Vertex2DMake;
textCoords[3] = Vertex2DMake;
CCLOG (“Tex initialized”);
And draw method :
void MyNode::draw
// For Texture loading open gl 2———————

// —————————————————
And in main layer class i have called like this :
MyNode* node1 = new MyNode;

Do you have any idea about it?And if you have successfully done that sample in opengl2 than can you post some code…


Check this sample I have done in Visual Studio 2010.

Also in your case author is using GL_TRIANGLE_STRIP method to map texture on a rectangle.


Thank you for the link Vikas…
I have finished the part 4 implementation and attached are 2 files for MyNode…


Hope it will be working fine


Yes it is working as expected.Just left part is to make ball so that it will not break its shape(trying some combination of freq and damping ratio)…Thank you for all the help Vikas…
I have attached the screenshot of output…


Great solution any idea how rotate the ball based on left/right touches?