OpenGL 3.2 keine Bildausgabe

Diese Seite verwendet Cookies. Durch die Nutzung unserer Seite erklären Sie sich damit einverstanden, dass wir Cookies setzen. Weitere Informationen

  • OpenGL 3.2 keine Bildausgabe

    Hallo Entwickler,

    damit ich OpenGL 3.2 nutzen kann, habe das das Pixel Format verändert.
    Seitdem bekomme ich keine Bildschirmausgabe mehr (nur ein weißes Fenster).
    Das OpenGLView wurde im IB erstellt und platziert.

    Quellcode

    1. #import <Cocoa/Cocoa.h>
    2. #import <OpenGL/gl.h>
    3. #import <OpenGL/OpenGL.h>
    4. #import <QuartzCore/CVDisplayLink.h>
    5. @interface OpenGLView : NSOpenGLView
    6. {
    7. CVDisplayLinkRef dlDisplayLink;
    8. }


    Quellcode

    1. #import "OpenGLView.h"
    2. @interface OpenGLView()
    3. - (CVReturn)getFrameForTime:(const CVTimeStamp*)outputTime;
    4. @end
    5. @implementation OpenGLView
    6. - (void) awakeFromNib
    7. {
    8. NSOpenGLPixelFormatAttribute pfaAttributes[] = {NSOpenGLPFADoubleBuffer, NSOpenGLPFADepthSize, 24, NSOpenGLPFAOpenGLProfile, NSOpenGLProfileVersion3_2Core, 0};
    9. @autoreleasepool
    10. {
    11. NSOpenGLPixelFormat *pfPixelFormat = [[NSOpenGLPixelFormat alloc] initWithAttributes:pfaAttributes];
    12. NSOpenGLContext* glcContext = [[NSOpenGLContext alloc] initWithFormat:pfPixelFormat shareContext:nil];
    13. [self setPixelFormat:pfPixelFormat];
    14. [self setOpenGLContext:glcContext];
    15. }
    16. }
    17. - (void)prepareOpenGL
    18. {
    19. [super prepareOpenGL];
    20. [[self openGLContext] makeCurrentContext];
    21. GLint iSwap = 1;
    22. [[self openGLContext] setValues:&iSwap forParameter:NSOpenGLCPSwapInterval];
    23. glClearColor(0.0, 0.0, 1.0, 1.0); // Bild blau
    24. glViewport(0, 0, (GLsizei) self.bounds.size.width, (GLsizei) self.bounds.size.height);
    25. [[self openGLContext] setValues:&iSwap forParameter:NSOpenGLCPSwapInterval];
    26. CVDisplayLinkCreateWithActiveCGDisplays(&dlDisplayLink);
    27. CVDisplayLinkSetOutputCallback(dlDisplayLink, &DisplayLinkCallback, (__bridge void *) self);
    28. CGLContextObj cglContext = [[self openGLContext] CGLContextObj];
    29. CGLPixelFormatObj cglPixelFormat = [[self pixelFormat] CGLPixelFormatObj];
    30. CVDisplayLinkSetCurrentCGDisplayFromOpenGLContext(dlDisplayLink, cglContext, cglPixelFormat);
    31. CVDisplayLinkStart(dlDisplayLink);
    32. }
    33. - (void)reshape
    34. {
    35. [super reshape];
    36. CGLLockContext([[self openGLContext] CGLContextObj]);
    37. glViewport(0, 0, (GLsizei) self.bounds.size.width, (GLsizei) self.bounds.size.height);
    38. CGLUnlockContext([[self openGLContext] CGLContextObj]);
    39. }
    40. - (void)renderScene
    41. {
    42. [[self openGLContext] makeCurrentContext];
    43. CGLLockContext((CGLContextObj)[[self openGLContext] CGLContextObj]);
    44. // Render - Start
    45. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    46. glFlush();
    47. // Render - Ende
    48. CGLUnlockContext((CGLContextObj)[[self openGLContext] CGLContextObj]);
    49. }
    50. static CVReturn DisplayLinkCallback(CVDisplayLinkRef displayLink, const CVTimeStamp* now, const CVTimeStamp* outputTime, CVOptionFlags flagsIn, CVOptionFlags* flagsOut, void *displayLinkContext)
    51. {
    52. return [(__bridge OpenGLView *)displayLinkContext getFrameForTime:outputTime];
    53. }
    54. - (CVReturn)getFrameForTime:(const CVTimeStamp*)outputTime
    55. {
    56. @autoreleasepool
    57. {
    58. [self renderScene];
    59. }
    60. return kCVReturnSuccess;
    61. }
    62. @end
    Alles anzeigen

    Das Fenster sollte doch wenigstens blau sein (wegen glClearColor(0.0, 0.0, 0.0, 1.0, 1.0)).
  • Wie schon in dem anderen Thread geschrieben, der Aufruf des Displaylink erfolgt in einem anderen thread, Du musst den context nicht nur locken, sondern auch setzen ( mit -makeCurrent). Hast Du Dir mal das GLEssentials-Demo angeschaut? Den OpenGL Programming Guide der Apple-Doku gelesen? Verstehst Du überhaupt, was Du da an Code stehen hast, also wie die Reihenfolge der Aufrufe etc ist (soll kein Flame sein, aber die Doku und die Samples beschrieben das erschöpfend...)?
  • glClearColor(0.5, 0.5, 0.5, 1.0);

    Also bei mir funktioniert das mit diesem Code
    (MainView):

    Quellcode

    1. - (void) drawRect: (CGRect) rect
    2. {
    3. glViewport(0, 0, viewportWidth, viewportHeight);
    4. glClearColor(0.5, 0.5, 0.5, 1.0);
    5. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    6. //.... Render methods
    7. [eaglContext presentRenderbuffer: GL_RENDERBUFFER_OES];
    8. }



    Und der Bildschirm ist grau. Ich weiß auch nicht wirklich, woran bei dir der Fehler liegt....
    :(
  • Jetzt hab ich es!

    Es lag nicht am Context, [[self openGLContext] makeCurrentContext]; steht in der prepareOpenGL Methode

    Mein Fehler war, dass ich glFlush(); statt CGLFlushDrawable([[self openGLContext] CGLContextObj]); verwendet habe.
  • Ich möchte nicht wieder nerven, aber bei mir kommt bei folgendem Code kein Dreieck.
    Ja, ich habe auch schon gegoogelt, habe aber keine Lösung gefunden.

    Quellcode

    1. // InitGL
    2. static const GLfloat fVertexBufferData[] =
    3. {
    4. -0.5, -0.5, 0.0,
    5. 0.5, -0.5, 0.0,
    6. 0.0, 0.5, 0.0
    7. };
    8. glGenVertexArraysAPPLE(1, &uiVertexArray);
    9. glBindVertexArrayAPPLE(uiVertexArray);
    10. glGenBuffers(1, &uiVertexBuffer);
    11. glBindBuffer(GL_ARRAY_BUFFER, uiVertexBuffer);
    12. glBufferData(GL_ARRAY_BUFFER, sizeof(fVertexBufferData), fVertexBufferData, GL_STATIC_DRAW);
    13. glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);
    14. glEnableVertexAttribArray(0);
    Alles anzeigen


    Quellcode

    1. // Render
    2. [[self openGLContext] makeCurrentContext];
    3. CGLLockContext((CGLContextObj)[[self openGLContext] CGLContextObj]);
    4. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    5. [Manager useShader:@"MyShader"];
    6. glEnableVertexAttribArray(0);
    7. glBindBuffer(GL_ARRAY_BUFFER, uiVertexBuffer);
    8. glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);
    9. glDrawArrays(GL_TRIANGLES, 0, 3);
    10. glDisableVertexAttribArray(0);
    11. CGLFlushDrawable([[self openGLContext] CGLContextObj]);
    12. CGLUnlockContext([[self openGLContext] CGLContextObj]);
    Alles anzeigen

    Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von Vyax ()

  • Wenn mich nicht alles taeuscht ist

    Quellcode

    1. glBufferData(GL_ARRAY_BUFFER, sizeof(fVertexBufferData), fVertexBufferData, GL_STATIC_DRAW);

    falsch, richtig waere:

    Quellcode

    1. glBufferData(GL_ARRAY_BUFFER, sizeof(fVertexBufferData)*sizeof(GLfloat), fVertexBufferData, GL_STATIC_DRAW);


    Im Handbuch steht auch, dass man size in Bytes angeben muss.
    C++