[SDL] OpenGL 3.2 / SDL 1.3 with OS X Lion

Boouh bidbe at live.fr
Fri Jul 29 01:39:18 PDT 2011


I have resolved a part of the problem. In the file SDL_cocoaopengl.m, the SDL creates the
OpenGL context with Objective-C code. Apple said that to enable the 3.2 Core Profile we must add two parameters in the attribs array :

NSOpenGLPFAOpenGLProfile, NSOpenGLProfileVersion3_2Core

So I added them to the code and now I can compile 1.5 Shader. :D The right driver is loaded : "OpenGL Version: 3.2 ATI-7.2.9".

But now, I have another problem : when I want to display something (triangle, 
) I don’t have anything in the window. Even if I don’t use shaders I just have a black screen. For example,

I tried to compile this code but the triangle is not displayed, I have only a black
screen. :s

What is the problem now ?


Code:
#include <SDL/SDL.h>
#include <OpenGL/gl3.h>

int main(int argc, char **argv)
{
   // Variables

   SDL_WindowID window;
   SDL_GLContext OpenGLContext;
   SDL_Event events;
   char end = 0;


   // Initialization

   if(SDL_Init(SDL_INIT_VIDEO) < 0)
   {
       printf("Error with SDL initialization: %s", SDL_GetError());
       SDL_Quit();
       return -1;
   }


   // OpenGL version

   SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
   SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2);
   

    // Double Buffer
   
    SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
    SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
   

    // Window creation

   window = SDL_CreateWindow("SDL 1.3 / OpenGL 3.2", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 800, 600, SDL_WINDOW_SHOWN | SDL_WINDOW_OPENGL);
   OpenGLContext = SDL_GL_CreateContext(window);
   

    // Vertices

   float vertices[] = {-0.5, -0.5,   0.0, 0.5,   0.5, -0.5};
   

    // Main Loop

   while(!end)
   {
       // Events

       SDL_WaitEvent(&events);
       if(events.window.event == SDL_WINDOWEVENT_CLOSE)
           end = 1;
 
       
        // OpenGL 3.2 Code

       glClear(GL_COLOR_BUFFER_BIT);
 
       glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, vertices);
       glEnableVertexAttribArray(0);
 
       glDrawArrays(GL_TRIANGLES, 0, 3);
 
       glDisableVertexAttribArray(0);
       

        // Refresh of window

       SDL_GL_SwapWindow(window);
   }


   // End of the program

   SDL_GL_DeleteContext(OpenGLContext);
   SDL_DestroyWindow(window);
   SDL_Quit();

   return 0;
}







-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20110729/e4657788/attachment-0008.htm>


More information about the SDL mailing list