//#include <proto/exec.h>
//#include <proto/powersdl.h>
//#include <proto/powersdl_gfx.h>
#include <SDL/SDL.h>
#include <GL/gl.h>
#include <iostream>
//struct Library *PowerSDLBase=nullptr;
//struct Library *PowerSDLGfxBase=nullptr;
using namespace std;
static void setupOpengl(int width, int height) {
float ratio = (float) width / (float) height;
glShadeModel(GL_SMOOTH);
glCullFace(GL_BACK);
glFrontFace(GL_CCW);
glEnable(GL_CULL_FACE);
glClearColor(0, 0, 0, 0);
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(60.0, ratio, 1.0, 1024.0);
}
static void drawScreen() {
/* Our angle of rotation. */
static float angle = 0.0f;
static GLfloat v0[] = {-1.0f, -1.0f, 1.0f};
static GLfloat v1[] = {1.0f, -1.0f, 1.0f};
static GLfloat v2[] = {1.0f, 1.0f, 1.0f};
static GLfloat v3[] = {-1.0f, 1.0f, 1.0f};
static GLfloat v4[] = {-1.0f, -1.0f, -1.0f};
static GLfloat v5[] = {1.0f, -1.0f, -1.0f};
static GLfloat v6[] = {1.0f, 1.0f, -1.0f};
static GLfloat v7[] = {-1.0f, 1.0f, -1.0f};
static GLubyte red[] = {255, 0, 0, 255};
static GLubyte green[] = {0, 255, 0, 255};
static GLubyte blue[] = {0, 0, 255, 255};
static GLubyte white[] = {255, 255, 255, 255};
static GLubyte yellow[] = {0, 255, 255, 255};
static GLubyte black[] = {0, 0, 0, 255};
static GLubyte orange[] = {255, 255, 0, 255};
static GLubyte purple[] = {255, 0, 255, 0};
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0.0, 0.0, -5.0);
glRotatef(angle, 0.0, 1.0, 0.0);
if (++angle > 360.0f) {
angle = 0.0f;
}
glBegin(GL_TRIANGLES);
glColor4ubv(red);
glVertex3fv(v0);
glColor4ubv(green);
glVertex3fv(v1);
glColor4ubv(blue);
glVertex3fv(v2);
glColor4ubv(red);
glVertex3fv(v0);
glColor4ubv(blue);
glVertex3fv(v2);
glColor4ubv(white);
glVertex3fv(v3);
glColor4ubv(green);
glVertex3fv(v1);
glColor4ubv(black);
glVertex3fv(v5);
glColor4ubv(orange);
glVertex3fv(v6);
glColor4ubv(green);
glVertex3fv(v1);
glColor4ubv(orange);
glVertex3fv(v6);
glColor4ubv(blue);
glVertex3fv(v2);
glColor4ubv(black);
glVertex3fv(v5);
glColor4ubv(yellow);
glVertex3fv(v4);
glColor4ubv(purple);
glVertex3fv(v7);
glColor4ubv(black);
glVertex3fv(v5);
glColor4ubv(purple);
glVertex3fv(v7);
glColor4ubv(orange);
glVertex3fv(v6);
glColor4ubv(yellow);
glVertex3fv(v4);
glColor4ubv(red);
glVertex3fv(v0);
glColor4ubv(white);
glVertex3fv(v3);
glColor4ubv(yellow);
glVertex3fv(v4);
glColor4ubv(white);
glVertex3fv(v3);
glColor4ubv(purple);
glVertex3fv(v7);
glColor4ubv(white);
glVertex3fv(v3);
glColor4ubv(blue);
glVertex3fv(v2);
glColor4ubv(orange);
glVertex3fv(v6);
glColor4ubv(white);
glVertex3fv(v3);
glColor4ubv(orange);
glVertex3fv(v6);
glColor4ubv(purple);
glVertex3fv(v7);
glColor4ubv(green);
glVertex3fv(v1);
glColor4ubv(red);
glVertex3fv(v0);
glColor4ubv(yellow);
glVertex3fv(v4);
glColor4ubv(green);
glVertex3fv(v1);
glColor4ubv(yellow);
glVertex3fv(v4);
glColor4ubv(black);
glVertex3fv(v5);
glEnd();
SDL_GL_SwapBuffers();
}
int main(int argc, char *argv[]) {
cout << "begin ..." << endl;
/* mos */
/*if ((PowerSDLBase = OpenLibrary((STRPTR)"powersdl.library", 16))==nullptr){
cout<<"could not open powersdl.library"<<endl;
return -1;
}*/
/*if ((PowerSDLGfxBase = OpenLibrary((STRPTR)"powersdl_gfx.library", 11))==nullptr){
cout<<"could not open powersdl_gfx.library"<<endl;
return -2;
} */
int res = SDL_Init(SDL_INIT_VIDEO);
if (res) {
cout << "could not init sdl, result=" << res << ", error=" << SDL_GetError() << endl;
}
SDL_Surface *screen = SDL_SetVideoMode(640, 480, 0, SDL_OPENGL);
if (screen == nullptr) {
cout << "could set display mode, error=" << SDL_GetError() << endl;
}
setupOpengl(640, 480);
SDL_Event event;
bool b = true;
while (b) {
res = SDL_PollEvent(&event);
if (res) {
switch (event.type) {
case SDL_KEYDOWN:
cout << "key down event" << endl;
break;
case SDL_KEYUP:
cout << "key up event" << endl;
break;
case SDL_MOUSEMOTION:
cout << "mouse motion event" << endl;
break;
case SDL_MOUSEBUTTONDOWN:
cout << "mouse button down event" << endl;
break;
case SDL_MOUSEBUTTONUP:
cout << "mouse button up event" << endl;
break;
case SDL_QUIT:
cout << "quit event" << endl;
b = false;
break;
}
}
drawScreen();
SDL_Delay(40);
}
SDL_Quit();
/* mos */
//CloseLibrary(PowerSDLBase);
//CloseLibrary(PowerSDLGfxBase);
cout << "end!" << endl;
return 0;
}