Schließlich half mir Mr. Chris, eine Linie mit GLKview und drawInRect: method zu zeichnen. Es funktioniert gut. Aber ich brauche einige Klarstellungen,Wie wir GLFloat Werte zuweisen, um eine Linie in der iPhone App zu zeichnen?
Wie wir GLFloat Werte zuweisen?
const GLfloat line[] = { -1.0f, -1.5f, //point A : What is -1.0f and -1.5f ? These are x and y or something. 1.5f, -1.0f, //point B : What is 1.5f and -1.0f ? These are x and y or something. };
Weil ich hier einen Wert setzen bin verwirrend. Wie dauert es x, y oder Länge? Wenn es eine dumme Frage ist, bitte ich um Entschuldigung. Bitte klären Sie meine Zweifel daran.
- Wie Hintergrundbild für GLKViewController festlegen? Ich habe ein Bild, um Hintergrund zu setzen, aber ich weiß nicht, wo ich das einstellen muss?
Probe viewDidLoad Code
- (void)viewDidLoad
{
[super viewDidLoad];
self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"GameDesign03.png"]];
self.context = [[[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2] autorelease];
if (!self.context) {
NSLog(@"Failed to create ES context");
}
GLKView *view = (GLKView *)self.view;
view.context = self.context;
view.drawableDepthFormat = GLKViewDrawableDepthFormat24;
[self setupGL];
}
- (void)glkView:(GLKView *)view drawInRect:(CGRect)rect
{
glClearColor(0.65f, 0.65f, 0.65f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
[self.effect prepareToDraw]; // Prepare the effect for rendering
const GLfloat line[]=
{
-1.0f, -1.5f,
1.5f, -1.0f
};
GLuint bufferObjectNameArray; //Create an handle for a buffer object array
glGenBuffers(1, &bufferObjectNameArray); //Have OpenGL generate a buffer name and store it in the buffer object array
glBindBuffer(GL_ARRAY_BUFFER, bufferObjectNameArray); //Bind the buffer object array to the GL_ARRAY_BUFFER target buffer
//Send the line data over to the target buffer in GPU RAM
glBufferData(GL_ARRAY_BUFFER, sizeof(line), line, GL_STATIC_DRAW);
glEnableVertexAttribArray(GLKVertexAttribPosition); //Enable vertex data to be fed down the graphics pipeline to be drawn
glVertexAttribPointer(GLKVertexAttribPosition, 2, GL_FLOAT, GL_FALSE, 2, NULL); //Specify how the GPU looks up the data
glDrawArrays(GL_LINES, 0, 2); // render
}
Bitte auf diese Hilfe. Danke im Voraus.
Sie müssen den Code, wo Sie tatsächlich die Linien zeichnen, veröffentlichen. Normalerweise senden Sie OpenGL eine Liste von Vertices. Sie sagen ihm, ob die Koordinaten 2D oder 3D sind, und bestimmt, ob es sich um (x, y) Paare oder (x, y, z) Tripel handelt. Wie für das Hintergrundbild - Controller zeichnen nichts. Sie müssten es zu Ihrer GLKView zeichnen, bevor Sie Ihre andere Zeichnung ausführen. Sie könnten zum Beispiel ein strukturiertes Quad zeichnen, das die gesamte Fläche abdeckt, und dann Ihre Linien zeichnen. – user1118321
Ich habe den Code hinzugefügt, wo ich die Linie zeichne. Vielen Dank. – Gopinath