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 8752675
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T13:16:52+00:00 2026-06-13T13:16:52+00:00

Ultimately I am trying to use a single image to texture a number of

  • 0

Ultimately I am trying to use a single image to texture a number of objects (hexagons) by supplying different texture co-ordinates to each object.
Using OpenGL ES 2.0 and GLKit I came up with a method of doing so only to discover that for some reason the objects won’t render if I malloc and initialize the Vertex arrays manually. I especially don’t understand why this is because the statically assigned version of the vertex arrays work just fine.

Up front here is the struct I am using:

typedef struct {
GLKVector3 position;
GLKVector4 color;
GLKVector2 texCoords;
}Vertex;

So if I do this in a hexagon’s implementation, I can see the various hexagons with the texture applied:

Vertex _Vertices[] = {
{{ 0,    0,     0}, {1, 1, 1, 0}, {0.50, 0.50}},//Z
{{ 1,    0,     0}, {1, 1, 1, 0}, {1.00, 0.50}},//A
{{ 0.5, -0.866, 0}, {1, 1, 1, 0}, {0.75, 0.00}},//B
{{-0.5, -0.866, 0}, {1, 1, 1, 0}, {0.25, 0.00}},//C
{{-1,    0,     0}, {1, 1, 1, 0}, {0,    0.50}},//D
{{-0.5,  0.866, 0}, {1, 1, 1, 0}, {0.25, 1.00}},//E
{{ 0.5,  0.866, 0}, {1, 1, 1, 0}, {0.75, 1.00}} //F
};

However if I instead comment out the above declaration and add an instance variable of the same name (Vertex *Vertices instead of Vertex Vertices[] since I can’t malloc to an array directly) then do the following, nothing renders:

-(void)setVertices{
_Vertices = malloc(sizeof(Vertex) * 7);

//Z
_Vertices[0].position.x = 0;
_Vertices[0].position.y = 0;
_Vertices[0].position.z = 0;
_Vertices[0].color.r = 1;
_Vertices[0].color.g = 1;
_Vertices[0].color.b = 1;
_Vertices[0].color.a = 0;
_Vertices[0].texCoords.x = 0.5;
_Vertices[0].texCoords.y = 0.5;

//A
_Vertices[1].position.x = 1;
_Vertices[1].position.y = 0;
_Vertices[1].position.z = 0;
_Vertices[1].color.r = 1;
_Vertices[1].color.g = 1;
_Vertices[1].color.b = 1;
_Vertices[1].color.a = 0;
_Vertices[1].texCoords.x = 1;
_Vertices[1].texCoords.y = 0.5;


//B
_Vertices[2].position.x = 0.5;
_Vertices[2].position.y = -0.866;
_Vertices[2].position.z = 0;
_Vertices[2].color.r = 1;
_Vertices[2].color.g = 1;
_Vertices[2].color.b = 1;
_Vertices[2].color.a = 0;
_Vertices[2].texCoords.x = 0.75;
_Vertices[2].texCoords.y = 0.00;


//C
_Vertices[3].position.x = -0.5;
_Vertices[3].position.y = -0.866;
_Vertices[3].position.z = 0;
_Vertices[3].color.r = 1;
_Vertices[3].color.g = 1;
_Vertices[3].color.b = 1;
_Vertices[3].color.a = 0;
_Vertices[3].texCoords.x = 0.25;
_Vertices[3].texCoords.y = 0;


//D
_Vertices[4].position.x = -1;
_Vertices[4].position.y = 0;
_Vertices[4].position.z = 0;
_Vertices[4].color.r = 1;
_Vertices[4].color.g = 1;
_Vertices[4].color.b = 1;
_Vertices[4].color.a = 0;
_Vertices[4].texCoords.x = 0;
_Vertices[4].texCoords.y = 0.5;


//E
_Vertices[5].position.x = -0.5;
_Vertices[5].position.y = 0.866;
_Vertices[5].position.z = 0;
_Vertices[5].color.r = 1;
_Vertices[5].color.g = 1;
_Vertices[5].color.b = 1;
_Vertices[5].color.a = 0;
_Vertices[5].texCoords.x = 0.25;
_Vertices[5].texCoords.y = 1;


//F
_Vertices[6].position.x = 0.5;
_Vertices[6].position.y = 0.866;
_Vertices[6].position.z = 0;
_Vertices[6].color.r = 1;
_Vertices[6].color.g = 1;
_Vertices[6].color.b = 1;
_Vertices[6].color.a = 0;
_Vertices[6].texCoords.x = 0.75;
_Vertices[6].texCoords.y = 1;
}

Here is my setup function:

-(void)setupGL{
self.effect = [[GLKBaseEffect alloc] init];

glGenBuffers(1, &_vertexBuffer);
glBindBuffer(GL_ARRAY_BUFFER, _vertexBuffer);
glBufferData(GL_ARRAY_BUFFER, sizeof(_Vertices), _Vertices, GL_STATIC_DRAW);

glGenBuffers(1, &_indexBuffer);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _indexBuffer);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(_Indices), _Indices, GL_STATIC_DRAW);
}

And here is my draw function:

-(void)draw{
glPushGroupMarkerEXT(0,"drawHex");
_effect.texture2d0.envMode = GLKTextureEnvModeReplace;
_effect.texture2d0.target = GLKTextureTarget2D;
_effect.texture2d0.name = _texture.name;
[self.effect prepareToDraw];
glBindBuffer(GL_ARRAY_BUFFER, _vertexBuffer);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _indexBuffer);

glEnableVertexAttribArray(GLKVertexAttribPosition);
glVertexAttribPointer(GLKVertexAttribPosition, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (const GLvoid *) offsetof(Vertex, position));

glEnableVertexAttribArray(GLKVertexAttribColor);
glVertexAttribPointer(GLKVertexAttribColor, 4, GL_FLOAT, GL_FALSE, sizeof(Vertex), (const GLvoid *) offsetof(Vertex, color));

glEnableVertexAttribArray(GLKVertexAttribTexCoord0);
glVertexAttribPointer(GLKVertexAttribTexCoord0, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), (const GLvoid *) offsetof(Vertex, texCoords));

//draw
glDrawElements(GL_TRIANGLES, sizeof(_Indices)/sizeof(_Indices[0]),GL_UNSIGNED_BYTE, 0);
glPopGroupMarkerEXT();
}

If it matters the texture is created once outside the object and then a pointer to it is passed in. Creating the texture like this:

-(void)setTextureImage:(UIImage *)image {
NSError *error;
_hexTexture = [GLKTextureLoader textureWithCGImage:image.CGImage options:nil error:&error];
if (error) {
    NSLog(@"Error loading texture from image: %@",error);
}}

I am new to all of this and it is getting quite frustrating trying to figure out what is going on here.

In my vast searching about I saw something about ‘capture opengl es frame’ but it doesn’t seem to be enabled for the iphone simulator in Xcode so I can’t dig into it 🙁

I would really like to know why this is happening.

I can provide more code or explanations if it will help.

Any thoughts?

  • 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-13T13:16:52+00:00Added an answer on June 13, 2026 at 1:16 pm

    About glBufferData’s param,
    sizeof(_Vertices) is not same between static and dynamic.
    If you wanna use dynamic, you must use sizeof(Vertex)*7 instead of sizeof(_Vertices).

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

Sidebar

Related Questions

I am trying to use FileHelper library for parsing a text file. Ultimately the
using Visual.Web.Developer.2010.Express; using SQL.Server.Management.Studio.2008.R2; What I'm ultimately trying to do is update a sql
I'm trying to use the libxml-enumerator package on Windows, which (ultimately) needs to use
I'm trying to use the libxml-enumerator package on Windows, which (ultimately) needs to use
I'm trying to use a solution for serializing exceptions using jaxb. ( http://forums.java.net/jive/thread.jspa?messageID=256122 )
I'm trying to use haxr 3000.8.5 to upload images to a WordPress blog using
Trying to remove duplicate array elements without using array_unique. I am trying to use
Ultimately I'm trying to write out a range into a text file. When I
Ultimately I am trying to run some code which depends on the value (or
So what I am trying to do ultimately is read a line, do some

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.