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

  • SEARCH
  • Home
  • 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 9179607
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T17:50:22+00:00 2026-06-17T17:50:22+00:00

I’m loading textures using OpenGL ES, the below is my code. The graphic is

  • 0

I’m loading textures using OpenGL ES, the below is my code.

The graphic is made up of 2 textures of the same size, the stop button and the blue glow behind.

The first graphic below was taken using the iPad simulator in xCode, and the 2nd on the actual device. The 1st graphic is the correct output as I exported the graphics from Illustrator. However, when I loaded the program on the iPad, it gives me the 2nd graphic. It seems somehow that the blue light texture behind the stop button has become smaller. Why is this so?

I can compensate by making the blue light texture bigger, but it wouldn’t be right as the way it is supposed to look in Illustrator is the 1st graphic.

Here’s my code.

//
//  OpenGLES_Ch3_4ViewController.m
//  OpenGLES_Ch3_4
//

#import "OpenGLES_Ch3_4ViewController.h"
#import "AGLKVertexAttribArrayBuffer.h"
#import "AGLKContext.h"

#define Y_POS 1.0
#define ASPECT_RATIO 0.75f
#define SIZE 0.8

@implementation OpenGLES_Ch3_4ViewController

@synthesize baseEffect;
@synthesize vertexBuffer;
@synthesize textureInfo0;
@synthesize textureInfo1;

/////////////////////////////////////////////////////////////////
// This data type is used to store information for each vertex
typedef struct {
   GLKVector3  positionCoords;
   GLKVector2  textureCoords;
}
SceneVertex;

/////////////////////////////////////////////////////////////////
// Define vertex data for a triangle to use in example
//static const SceneVertex vertices[] = 

static const SceneVertex vertices[] =
{
    {{-1.0f*SIZE, -ASPECT_RATIO*SIZE, 0.0f}, {0.0f, 0.0f}},  // first triangle
    {{ 0.0f*SIZE, -ASPECT_RATIO*SIZE, 0.0f}, {1.0f, 0.0f}},
    {{-1.0f*SIZE,          0.0f*SIZE, 0.0f}, {0.0f, 1.0f}},
    {{ 0.0f*SIZE, -ASPECT_RATIO*SIZE, 0.0f}, {1.0f, 0.0f}},  // second triangle
    {{-1.0f*SIZE,          0.0f*SIZE, 0.0f}, {0.0f, 1.0f}},
    {{ 0.0f*SIZE,          0.0f*SIZE, 0.0f}, {1.0f, 1.0f}},
};

/////////////////////////////////////////////////////////////////
// Called when the view controller's view is loaded
// Perform initialization before the view is asked to draw
- (void)viewDidLoad
{
   [super viewDidLoad];

   // Verify the type of view created automatically by the
   // Interface Builder storyboard
   GLKView *view = (GLKView *)self.view;
   NSAssert([view isKindOfClass:[GLKView class]],
      @"View controller's view is not a GLKView");

   // Create an OpenGL ES 2.0 context and provide it to the
   // view
   view.context = [[AGLKContext alloc] 
      initWithAPI:kEAGLRenderingAPIOpenGLES2];

   // Make the new context current
   [AGLKContext setCurrentContext:view.context];

   // Create a base effect that provides standard OpenGL ES 2.0
   // shading language programs and set constants to be used for 
   // all subsequent rendering
   self.baseEffect = [[GLKBaseEffect alloc] init];
   self.baseEffect.useConstantColor = GL_TRUE;
   self.baseEffect.constantColor = GLKVector4Make(
      1.0f, // Red
      1.0f, // Green
      1.0f, // Blue
      1.0f);// Alpha

   // Set the background color stored in the current context 
   ((AGLKContext *)view.context).clearColor = GLKVector4Make(
      0.0f, // Red 
      0.0f, // Green 
      0.0f, // Blue 
      1.0f);// Alpha 

   // Create vertex buffer containing vertices to draw
   self.vertexBuffer = [[AGLKVertexAttribArrayBuffer alloc]
      initWithAttribStride:sizeof(SceneVertex)
      numberOfVertices:sizeof(vertices) / sizeof(SceneVertex)
      bytes:vertices
      usage:GL_STATIC_DRAW];

   // Setup texture0
   CGImageRef imageRef0 = 
      [[UIImage imageNamed:@"stoplight_full.png"] CGImage];

   self.textureInfo0 = [GLKTextureLoader 
      textureWithCGImage:imageRef0 
      options:[NSDictionary dictionaryWithObjectsAndKeys:
         [NSNumber numberWithBool:YES], 
         GLKTextureLoaderOriginBottomLeft, nil] 
      error:NULL];

    self.textureInfo0_2 = [GLKTextureLoader
                         textureWithCGImage:imageRef0
                         options:nil
                         error:NULL];

   // Setup texture1
   CGImageRef imageRef1 = 
      [[UIImage imageNamed:@"stop_button.png"] CGImage];

   self.textureInfo1 = [GLKTextureLoader 
      textureWithCGImage:imageRef1 
      options:[NSDictionary dictionaryWithObjectsAndKeys:
         [NSNumber numberWithBool:YES], 
         GLKTextureLoaderOriginBottomLeft, nil] 
      error:NULL];

    self.textureInfo1_2 = [GLKTextureLoader
                         textureWithCGImage:imageRef1
                           options:nil
                           error:NULL];

   // Enable fragment blending with Frame Buffer contents
   glEnable(GL_BLEND);
   glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}


/////////////////////////////////////////////////////////////////
// GLKView delegate method: Called by the view controller's view
// whenever Cocoa Touch asks the view controller's view to
// draw itself. (In this case, render into a frame buffer that
// shares memory with a Core Animation Layer)
- (void)glkView:(GLKView *)view drawInRect:(CGRect)rect
{   
   // Clear back frame buffer (erase previous drawing)
   [(AGLKContext *)view.context clear:GL_COLOR_BUFFER_BIT];

   [self.vertexBuffer prepareToDrawWithAttrib:GLKVertexAttribPosition
      numberOfCoordinates:3
      attribOffset:offsetof(SceneVertex, positionCoords)
      shouldEnable:YES];
   [self.vertexBuffer prepareToDrawWithAttrib:GLKVertexAttribTexCoord0
      numberOfCoordinates:2
      attribOffset:offsetof(SceneVertex, textureCoords)
      shouldEnable:YES];

   self.baseEffect.texture2d0.name = self.textureInfo0.name;
   self.baseEffect.texture2d0.target = self.textureInfo0.target;
   [self.baseEffect prepareToDraw];

   // Draw triangles using the vertices in the 
   // currently bound vertex buffer
   [self.vertexBuffer drawArrayWithMode:GL_TRIANGLES
      startVertexIndex:0
      numberOfVertices:sizeof(vertices) / sizeof(SceneVertex)];

   self.baseEffect.texture2d0.name = self.textureInfo1.name;
   self.baseEffect.texture2d0.target = self.textureInfo1.target;
   [self.baseEffect prepareToDraw];

   // Draw triangles using currently bound vertex buffer
   [self.vertexBuffer drawArrayWithMode:GL_TRIANGLES
      startVertexIndex:0
      numberOfVertices:sizeof(vertices) / sizeof(SceneVertex)];
 }

Desired - iPad Simulator

iPad 3

  • 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-17T17:50:23+00:00Added an answer on June 17, 2026 at 5:50 pm

    To me, the second texture does not look smaller, just dimmer.
    Your laptop and iPad most likely have displays with different gammas.

    There are many ways to correct for gamma, a terrific introduction is provided here.

    It is worth noting many modern cards can do it for you these days too, but so far unsupported on OpenGL ES as far as I know: sRGB Color Formats.

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

Sidebar

Related Questions

I used javascript for loading a picture on my website depending on which small
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am using JSon response to parse title,date content and thumbnail images and place
I have this code to decode numeric html entities to the UTF8 equivalent character.
I am using the SimpleRSS gem to parse a WordPress RSS feed. The only
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString

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.