Harshil.Chokshi
Harshil.Chokshi

Reputation: 681

How to change where rendered object is placed on the screen, OpenGL Es 2.0 iOS

I downloaded a project that displays a square with some texture. The square is currently located near the bottom of the screen, and I want to move it to the middle. Here is the code.

Geometry.h

#import "GLKit/GLKit.h"

#ifndef Geometry_h
#define Geometry_h

typedef struct {
   float Position[3];
   float Color[4];
   float TexCoord[2];
   float Normal[3];
} Vertex

typedef struct{
   int x;
   int y;
   int z;
} Position;

extern const Vertex VerticesCube[24];

extern const GLubyte IndicesTrianglesCube[36];

#endif

Here is the code in geometry.m

const Vertex VerticesCube[] = {
// Front
{{1, -1, 1},    {1, 0, 0, 1}, {0, 1},               {0, 0, 1}},
{{1, 1, 1},     {0, 1, 0, 1}, {0, 2.0/3.0},         {0, 0, 1}},
{{-1, 1, 1},    {0, 0, 1, 1}, {1.0/3.0, 2.0/3.0},   {0, 0, 1}},
{{-1, -1, 1},   {0, 0, 0, 1}, {1.0/3.0, 1},         {0, 0, 1}},
};

const GLubyte IndicesTrianglesCube[] = 
{
   // Front
   0, 1, 2,
   2, 3, 0,
}

What part of this code determines the position of the rendered object on the screen?

Upvotes: 0

Views: 52

Answers (1)

rickster
rickster

Reputation: 126157

None of the code you posted has to do with screen position.

VerticesCube specifies the cube corners in an arbitrary 3D space. Somewhere in code you haven't posted, a projection transform (and probably also view and model transforms) map each vertex to clip space, and a glViewport call (which is probably implicitly done for you if you're using GLKView) maps clip space to screen/view coordinates.

Rearranging things on screen could involve any one of those transforms, and which one to use is a choice that depends on understanding each one and how it fits into the larger context of your app design.

This is the sort of thing you'd get from the early stages of any OpenGL tutorial. Here's a decent one.

Upvotes: 1

Related Questions