Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8094671
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T20:52:06+00:00 2026-06-05T20:52:06+00:00

Overview I’m trying to build a graphic in my game by combining a few

  • 0

Overview

I’m trying to build a graphic in my game by combining a few images and gradients. I started by using Core Graphics which worked wonderfully, but was abysmally slow. I’ve now tried to port it over to OpenGL using GLKit and I’m very close, but there’s one last issue:

I’ve already drawn a texture into a triangle on the screen. Now, over the top of it, I’d like to draw a gradient. To draw a gradient, I figured it’d be easiest to just draw a triangle with a black color at two of the vertices and a fully transparent (alpha=0) color on the third. The gradient renders fine by itself, but when it is rendered over the top of the texture, it appears as if the alpha of the texture is also affected and causes the background to show through.

What I want:

enter image description here

What I get instead:

enter image description here

I admit that I’m not too familiar with OpenGL or GLKit. I suspect that the texture’s alpha at every point on the triangle is (1 – gradient alpha) which would explain why the texture is fully opaque in the corner and why both the texture and gradient seem to have partial transparency in the middle.

Can I accomplish what I want with GLKit? Does it even relate to GLKit and GLKBaseEffect, or am I just doing some funky multi-texturing thing in OpenGL that I can turn off?

Code Snippets

Render function in my sprite class, for drawing the texture:

typedef struct {
    CGPoint geometryVertex;
    CGPoint textureVertex;
} TexturedVertex;

- (void)renderTriangleStrip:(TexturedVertex *)coordinates ofSize:(NSInteger)size {
    self.effect.texture2d0.envMode = GLKTextureEnvModeReplace;
    self.effect.texture2d0.name = self.textureInfo.name;
    self.effect.texture2d0.enabled = YES;

    self.effect.transform.modelviewMatrix = self.transform;

    [self.effect prepareToDraw];

    glEnableVertexAttribArray(GLKVertexAttribPosition);
    glEnableVertexAttribArray(GLKVertexAttribTexCoord0);

    long offset = (long)coordinates;        
    glVertexAttribPointer(GLKVertexAttribPosition, 2, GL_FLOAT, GL_FALSE, sizeof(TexturedVertex), (void *) (offset + offsetof(TexturedVertex, geometryVertex)));
    glVertexAttribPointer(GLKVertexAttribTexCoord0, 2, GL_FLOAT, GL_FALSE, sizeof(TexturedVertex), (void *) (offset + offsetof(TexturedVertex, textureVertex)));

    glDrawArrays(GL_TRIANGLE_STRIP, 0, size);

    glDisableVertexAttribArray(GLKVertexAttribPosition);
    glDisableVertexAttribArray(GLKVertexAttribTexCoord0);
}

Render function in my shape class, for drawing the triangle w/gradient:

typedef struct {
    CGPoint position;
    GLKVector4 color;
} ColoredVertex;

- (void)renderVertices:(ColoredVertex *)vertices ofSize:(NSInteger)size {
    self.effect.texture2d0.envMode = GLKTextureEnvModeDecal;
    self.effect.texture2d0.enabled = NO;

    self.effect.useConstantColor = NO;

    self.effect.transform.modelviewMatrix = self.transform;

    [self.effect prepareToDraw];

    glEnableVertexAttribArray(GLKVertexAttribPosition);
    glEnableVertexAttribArray(GLKVertexAttribColor);

    long offset = (long)vertices;
    glVertexAttribPointer(GLKVertexAttribPosition, 2, GL_FLOAT, GL_FALSE, sizeof(ColoredVertex), (void *) (offset + offsetof(ColoredVertex, position)));
    glVertexAttribPointer(GLKVertexAttribColor, 4, GL_FLOAT, GL_FALSE, sizeof(ColoredVertex), (void *) (offset + offsetof(ColoredVertex, color)));

    glDrawArrays(GL_TRIANGLE_FAN, 0, size);

    glDisableVertexAttribArray(GLKVertexAttribPosition);
    glDisableVertexAttribArray(GLKVertexAttribColor);
}

Thanks in advance for your help!

Edit: It seems like glBlendFunc(…) might contain my answer. But I don’t understand the different modes. Am I on the right track here?

Edit: Still no solution yet, but I’ve updated my assumptions in the question.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T20:52:07+00:00Added an answer on June 5, 2026 at 8:52 pm

    I’m not sure to understand your problem, so I’ll try to restate it as I get it.

    1. You draw your checker background
    2. You draw an opaque triangle textures with your noisy texture
    3. You draw a triangle with a color gradient, which you want to affect the colors underneath it.

    I understand that it is pass 3 that causes you problems.

    If this is it, what you need to do to obtain your reference image is to draw your gradient triangle using a proper blending mode, and proper vertex colors. In your case, two black colors and one white color.

    For you case, the blending would be setup using :

    glEnable(GL_BLEND);
    glBlendFunc(GL_ZERO, GL_SRC_COLOR);
    

    This will instruct OpenGL to draw you triangle so that the resulting pixel color is given by dst = 0 * src + src * dst, which is dst = dst * src.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Overview I have an iOS project in which I am using Core data I
Overview I am trying to get a photo feed on to my site using
Quick overview Trying to insert a Business Object using ObjectDataSource (on a GridView) Get
Overview From the GR32 library, I am using TImgView32 to render a grid which
Overview: I'm working on some windows service using Visual Basic 2010, which deployed on
Overview I have an iOS app which sends local notifications at specific dates. I
Overview: I have an advancedDataGrid that I am using a GroupingCollection on and I
Overview I am using CompositeWPF to create an app using C#. This really should
Overview I have an iOS project which contains 2 navigation controllers as shown in
Overview: Trying to write a trigger for a SQL Server 2008 database. TableA and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.