Hi all!
I am trying to extend the opengl Texture2d so it becomes more useful. What I want to achieve is to pass in custom Position, Rotation, Scale and Color in the drawAtPoint function. The position, rotation and scale part was easy, but I can't make the color multiply or blend with the texture. This is how the code looks like now.
After doing some research I found that I should enable the GL_BLEND and then use a function glColor4f. Like this, before I draw the texure;
But it doesn't work. I initialize my code with the same functions as the CrashLanding sample.
I am glad for any help I can get.
Cheers
Alfons
I am trying to extend the opengl Texture2d so it becomes more useful. What I want to achieve is to pass in custom Position, Rotation, Scale and Color in the drawAtPoint function. The position, rotation and scale part was easy, but I can't make the color multiply or blend with the texture. This is how the code looks like now.
Code:
- (void) drawAtPoint:(CGPoint)position rotation:(float)rotation scale:(CGPoint)scale
{
CGPoint point = CGPointZero;
GLfloat coordinates[] = { 0, _maxT,
_maxS, _maxT,
0, 0,
_maxS, 0 };
GLfloat width = (GLfloat)_width * _maxS,
height = (GLfloat)_height * _maxT;
GLfloat vertices[] = { -width / 2 + point.x, -height / 2 + point.y, 0.0,
width / 2 + point.x, -height / 2 + point.y, 0.0,
-width / 2 + point.x, height / 2 + point.y, 0.0,
width / 2 + point.x, height / 2 + point.y, 0.0 };
glPushMatrix();
glTranslatef(position.x, position.y, 0);
glRotatef(-rotation, 0, 0, 1);
glScalef(scale.x, scale.y, 1.0f);
glBindTexture(GL_TEXTURE_2D, _name);
glVertexPointer(3, GL_FLOAT, 0, vertices);
glTexCoordPointer(2, GL_FLOAT, 0, coordinates);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
glPopMatrix();
}
After doing some research I found that I should enable the GL_BLEND and then use a function glColor4f. Like this, before I draw the texure;
Code:
glEnable(GL_BLEND);
//Blend the texture with 25% alpha
glColor4f(1.0f, 1.0f, 1.0f, 0.25f);
But it doesn't work. I initialize my code with the same functions as the CrashLanding sample.
I am glad for any help I can get.
Cheers
Alfons