A
azrax
Neues Mitglied
Thread Starter
- Dabei seit
- 07.01.2011
- Beiträge
- 18
- Reaktionspunkte
- 0
Hey Leute,
ich habe mir ein neues OpenGL Iphone Projekt erstellt. Ich fülle meinen Hintergrund mit Dreiecken und gebe diesen eine Textur.
Ausschnitt:
Zwei Fragen, da ich mich mit OpenGL nicht sooo sehr auskenne.
Ich möchte nun eine Methode in meiner Klasse, der ich zwei Punkte übergebe und die mir dann auf meinem Screen eine Linie zeichnet (ohne dass die Textur die ich im Setup erzeugt habe beeinflusst wird).
also sowas:
Naja, sowas in die Richtung eben.
Zweitens, eine Methode, die mir genau diesen Strich wieder entfernt.
Vielleicht könnt ihr mir da ja Helfen.
Viele Grüße
ich habe mir ein neues OpenGL Iphone Projekt erstellt. Ich fülle meinen Hintergrund mit Dreiecken und gebe diesen eine Textur.
Ausschnitt:
Code:
CGImageRef spriteImage;
CGContextRef spriteContext;
GLubyte *spriteData;
size_t width, height;
// Sets up matrices and transforms for OpenGL ES
glViewport(0, 0, backingWidth, backingHeight);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
//glRotatef(-90,0,0,1);
glOrthof(-1.0f, 1.0f, -1.5f, 1.5f, -1.0f, 1.0f);
glMatrixMode(GL_MODELVIEW);
// Clears the view with black
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
// Sets up pointers and enables states needed for using vertex arrays and textures
glVertexPointer(2, GL_FLOAT, 0, vertices);
glEnableClientState(GL_VERTEX_ARRAY);
//glColorPointer(4, GL_FLOAT, 0, triangleColors);
//glColor4f(0.0f,1.0f,0.0f,1.0f);
//glEnableClientState(GL_COLOR_ARRAY);
glTexCoordPointer(2, GL_FLOAT, 0, spriteTexcoords);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
// Creates a Core Graphics image from an image file
spriteImage = [UIImage imageNamed:@"Bild.png"].CGImage;
// Get the width and height of the image
width = CGImageGetWidth(spriteImage);
height = CGImageGetHeight(spriteImage);
// Texture dimensions must be a power of 2. If you write an application that allows users to supply an image,
// you'll want to add code that checks the dimensions and takes appropriate action if they are not a power of 2.
if(spriteImage) {
// Allocated memory needed for the bitmap context
spriteData = (GLubyte *) calloc(width * height * 4, sizeof(GLubyte));
// Uses the bitmap creation function provided by the Core Graphics framework.
spriteContext = CGBitmapContextCreate(spriteData, width, height, 8, width * 4, CGImageGetColorSpace(spriteImage), kCGImageAlphaPremultipliedLast);
// After you create the context, you can draw the sprite image to the context.
CGContextDrawImage(spriteContext, CGRectMake(0.0, 0.0, (CGFloat)width, (CGFloat)height), spriteImage);
// You don't need the context at this point, so you need to release it to avoid memory leaks.
CGContextRelease(spriteContext);
// Use OpenGL ES to generate a name for the texture.
glGenTextures(1, &spriteTexture);
// Bind the texture name.
glBindTexture(GL_TEXTURE_2D, spriteTexture);
// Set the texture parameters to use a minifying filter and a linear filer (weighted average)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
// Specify a 2D texture image, providing the a pointer to the image data in memory
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, spriteData);
// Release the image data
free(spriteData);
// Enable use of the texture
glEnable(GL_TEXTURE_2D);
// Set a blending function to use
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
// Enable blending
glEnable(GL_BLEND);
Zwei Fragen, da ich mich mit OpenGL nicht sooo sehr auskenne.
Ich möchte nun eine Methode in meiner Klasse, der ich zwei Punkte übergebe und die mir dann auf meinem Screen eine Linie zeichnet (ohne dass die Textur die ich im Setup erzeugt habe beeinflusst wird).
also sowas:
Code:
- (void) drawLineFromPoint1:(CGPoint)point1 toPoint2:(CGPoint)point2 {
GLfloat triangle[] = { //Hier eben Punkte 1 und 2
0.0f, 0.0f,
0.1f, 0.0f,
0.1f, 0.0f,
0.1f, 0.1f
};
GLfloat triangleColors[] = {
0.5f, 0.5f, 0.5f, 1.0f
};
glDisable(GL_TEXTURE_2D);
glVertexPointer(2, GL_FLOAT, 0, triangle);
glEnableClientState(GL_VERTEX_ARRAY);
glColorPointer(4, GL_FLOAT, 0, triangleColors);
//glEnableClientState(GL_COLOR_ARRAY);
[EAGLContext setCurrentContext:context];
glBindFramebufferOES(GL_FRAMEBUFFER_OES, viewFramebuffer);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
glBindRenderbufferOES(GL_RENDERBUFFER_OES, viewRenderbuffer);
[context presentRenderbuffer:GL_RENDERBUFFER_OES];
}
Naja, sowas in die Richtung eben.
Zweitens, eine Methode, die mir genau diesen Strich wieder entfernt.
Vielleicht könnt ihr mir da ja Helfen.
Viele Grüße