diff --git a/OpenGL1.pro b/OpenGL1.pro index 7b17dcb..7715231 100644 --- a/OpenGL1.pro +++ b/OpenGL1.pro @@ -3,3 +3,4 @@ TARGET=OpenGL1 SOURCES += main.cpp QMAKE_CXXFLAGS += $$system(sdl2-config --cflags) LIBS+= $$system(sdl2-config --libs) +LIBS+= -lGLU diff --git a/main.cpp b/main.cpp index 0c473a9..4c05d93 100644 --- a/main.cpp +++ b/main.cpp @@ -1,6 +1,11 @@ #include #include +#include +#include #include + +void drawTriangle(); + int main() { if(SDL_Init(SDL_INIT_VIDEO)) @@ -23,6 +28,48 @@ int main() ); + SDL_GLContext glContext; + // set OpenGL attributes + SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION,2); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION,0); + SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE,16); + SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER,1); + glContext=SDL_GL_CreateContext(window); + // now make this the active context + SDL_GL_MakeCurrent(window,glContext); + glClearColor(1.0,1.0,1.0,1.0); + glClear(GL_COLOR_BUFFER_BIT); + glMatrixMode(GL_PROJECTION); + gluPerspective(45.0f,(float)screenSize.w/screenSize.h, + 0.5,100 + ); + + glMatrixMode(GL_MODELVIEW); + gluLookAt(2,2,2,0,0,0,0,1,0); + + drawTriangle(); + SDL_GL_SwapWindow(window); SDL_Delay(10000); } + +void drawTriangle() +{ + glPushMatrix(); + glBegin(GL_TRIANGLES); + glColor3f(1.0f,0.0,0.0f); + glVertex3f(0.0f,1.0f,0.0f); + glColor3f(0.0f,1.0f,0.0f); + glVertex3f(1.0f,-1.0f,0.0f); + glColor3f(0.0f,0.0f,1.0f); + glVertex3f(-1.0f,-1.0f,0.0f); + glEnd(); + glPopMatrix(); +} + + + + + + +