Note that there are some explanatory texts on larger screens.

plurals
  1. PODisplaying images in open gl es 2.0 on iPhone
    primarykey
    data
    text
    <p>So I just started working on something in Open GL ES 2.0. I get the general impression that the switch from the 1.1 template to the 2.0 template in Xcode has caused some confusion for everyone, so as a result, there isn't much helpful on 2.0 (if there is anything really good and informative out there like 71squared's videos on the 1.1 template except for 2.0, your welcome to post a link to it).</p> <p>My problem is displaying an image on the screen.</p> <p>Right now, I've got this in my drawFrame method.</p> <pre><code>[(EAGLView *)self.view setFramebuffer]; // Replace the implementation of this method to do your own custom drawing. static float transY = 0.0f; glClearColor(0.0f, 1.0f, 0.0f, 1.0f); glClear(GL_COLOR_BUFFER_BIT); [playerCube drawAtPoint:CGPointMake(160.0f, 240.0f)]; if ([context API] == kEAGLRenderingAPIOpenGLES2) { // Use shader program. glUseProgram(program); // Update uniform value. glUniform1f(uniforms[UNIFORM_TRANSLATE], (GLfloat)transY); transY += 0.075f; // Validate program before drawing. This is a good check, but only really necessary in a debug build. // DEBUG macro must be defined in your debug configurations if that's not already the case. if (![self validateProgram:program]) { NSLog(@"Failed to validate program: %d", program); return; } } else { glMatrixMode(GL_PROJECTION); glLoadIdentity(); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glTranslatef(0.0f, (GLfloat)(sinf(transY)/2.0f), 0.0f); transY += 0.075f; } glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); [(EAGLView *)self.view presentFramebuffer]; </code></pre> <p>Essentially the template without the square bouncing around. This is in my ViewController.m by the way. That works fine on it's own. I've not had much luck with the code for displaying the image however. I'm using the Texture2D file from Apple's crash landing example, but I haven't had much luck with that no matter where the image related code is put.</p> <p>I've used <code>playerCube = [[Texture2D alloc] initWithImage:[UIImage imageNamed:@"Cubix.png"]];</code> to allocate it, which is probably right even if I've not been putting it in the right location, and <code>[playerCube drawAtPoint:CGPointMake(160.0f, 240.0f)];</code>.</p> <p>Wait, that wouldn't show anything at the start cuz I've not set the height and width of the image right? I guess I sort of answered that part of my question. Would it work if I used something like <code>image.frame = CGRectMake ();</code> or would that not work with Texture 2D? Also where should I be putting this code for it to work as it would?</p> <p>Hope I made some sense in this. I've never posted a question on StackOverflow before.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload