# Imports
from sdl2.ext import *
from sdl2.events import *
from sdl2.timer import *
from sdl2.sdlgfx import *
from sdl2 import *
from ctypes import *
from OpenGL import GL, GLU
from sdl2.ext import gl_line
# Initialize
init()
# Open a window
size = (400, 300)
SDL_Init(SDL_INIT_VIDEO)
window = SDL_CreateWindow(b"OpenGL demo", SDL_WINDOWPOS_UNDEFINED,
SDL_WINDOWPOS_UNDEFINED, 800, 600,
SDL_WINDOW_OPENGL)
#window.show()
context = SDL_GL_CreateContext(window)
GL.glMatrixMode(GL.GL_PROJECTION | GL.GL_MODELVIEW)
GL.glLoadIdentity()
GL.glOrtho(-400, 400, 300, -300, 0, 1)
# Initialize variables
done = False
black = 0xFF000000
white = 0xFFFFFFFF
blue = 0xFFFF0000
green = 0xFF00FF00
red = 0xFF0000FF
pi=3.141592653
# Main program loop
while not done:
# Process events
for my_event in get_events():
if my_event.type == SDL_QUIT:
done = True
# Clear screen
#context.clear(white)
gl_line()
x=10
y=10
GL.glClearColor(0, 0, 0, 1)
GL.glClear(GL.GL_COLOR_BUFFER_BIT)
GL.glRotatef(10.0, 0.0, 0.0, 1.0)
GL.glBegin(GL.GL_TRIANGLES)
GL.glColor3f(1.0, 0.0, 0.0)
GL.glVertex2f(x, y + 90.0)
GL.glColor3f(0.0, 1.0, 0.0)
GL.glVertex2f(x + 90.0, y - 90.0)
GL.glColor3f(0.0, 0.0, 1.0)
GL.glVertex2f(x - 90.0, y - 90.0)
GL.glEnd()
# Draw on the screen a green line from (0,0) to (50,75)
# 5 pixels wide.
#thickLineColor(context.renderer, 0, 0, 50, 75, 5, green)
# Draw a rectangle outline (No idea how to set line width)
#rectangleColor(context.renderer, 75, 10, 125, 30, black)
# Draw a solid rectangle
#draw.rect(screen,black,[150,10,50,20])
#boxColor(context.renderer, 150, 10, 200, 30, black)
# Draw an ellipse outline, using a rectangle as the outside boundaries
#ellipseColor(context.renderer, 250,20,25,10, red)
# Draw an solid ellipse, using a rectangle as the outside boundaries
#filledEllipseColor(context.renderer, 325,20,25,10, red)
# This draws a triangle using the polygon command
#number_points = 3
#xlist = (Sint16 * number_points)(100,0,200)
#ylist = (Sint16 * number_points)(100,200,200)
#xptr = cast(xlist, POINTER(Sint16))
#yptr = cast(ylist, POINTER(Sint16))
#polygonColor(context.renderer, xptr, yptr, number_points, black)
# Draw an arc as part of an ellipse.
# Use radians to determine what angle to draw.
#arcColor(context.renderer,260,125,50, 0, 90, black)
#arcColor(context.renderer,260,125,50, 90, 180, green)
#arcColor(context.renderer,260,125,50, 180, 270, blue)
#arcColor(context.renderer,260,125,50, 270, 360, red)
# Go ahead and update the screen with what we've drawn.
#context.present()
SDL_GL_SwapWindow(window)
# This limits the while loop to a max of 10 times per second.
# Leave this out and we will use all CPU we can.
SDL_Delay(60)
# Be IDLE friendly
quit()