Skip to content

Commit

Permalink
added triangle
Browse files Browse the repository at this point in the history
  • Loading branch information
jmacey committed Jan 13, 2015
1 parent a4ba19a commit 54938b8
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
1 change: 1 addition & 0 deletions OpenGL1.pro
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ TARGET=OpenGL1
SOURCES += main.cpp
QMAKE_CXXFLAGS += $$system(sdl2-config --cflags)
LIBS+= $$system(sdl2-config --libs)
LIBS+= -lGLU
47 changes: 47 additions & 0 deletions main.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
#include <iostream>
#include <SDL.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include <cstdlib>

void drawTriangle();

int main()
{
if(SDL_Init(SDL_INIT_VIDEO))
Expand All @@ -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();
}







0 comments on commit 54938b8

Please sign in to comment.