Skip to content

Instantly share code, notes, and snippets.

@filevich
Last active April 16, 2020 10:16
Show Gist options
  • Save filevich/86cc0dd8a104f541dfa8289cb7ed46a6 to your computer and use it in GitHub Desktop.
Save filevich/86cc0dd8a104f541dfa8289cb7ed46a6 to your computer and use it in GitHub Desktop.
got sdl 1.25 working on fucking linux, compiling from x64 to x86
`sudo dpkg --add-architecture i386`
`sudo apt-get update`
`sudo apt-get install libsdl1.2-dev:i386`
`sudo apt-get install gcc-multilib g++-multilib`
`g++ main.cpp -w -lSDL -lSDLmain -m32 -lGL -lGLU -I/usr/include/SDL -L/usr/lib/i386-linux-gnu -o main.o`
`./main.o`
main.cpp
````
#include "SDL.h"
#include "SDL_opengl.h"
#include <iostream>
using namespace std;
int main(int argc, char *argv[]) {
if(SDL_Init(SDL_INIT_VIDEO)<0) {
cerr << "No se pudo iniciar SDL: " << SDL_GetError() << endl;
exit(1);
}
atexit(SDL_Quit);
Uint32 flags = SDL_DOUBLEBUF | SDL_HWSURFACE | SDL_OPENGL;
if(SDL_SetVideoMode(640, 480, 32, flags)==NULL) {
cerr << "No se pudo establecer el modo de video: " << SDL_GetError() << endl;
exit(1);
}
if(SDL_EnableKeyRepeat(10, 10)<0) {
cerr << "No se pudo establecer el modo key-repeat: " << SDL_GetError() << endl;
exit(1);
}
glMatrixMode(GL_PROJECTION);
float color = 0;
glClearColor(color, color, color, 1);
gluPerspective(45, 640/480.f, 0.1, 100);
glEnable(GL_DEPTH_TEST);
glMatrixMode(GL_MODELVIEW);
bool fin=false;
bool rotate=false;
SDL_Event evento;
float aspecto = 212/452.f;
float x,y,z;
x=0;
y=0;
z=5;
float degrees = 0;
do{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
gluLookAt(x,y,z,0,0,0,0,1,0);
if (rotate){
degrees = degrees + 1;
}
glRotatef(degrees, 0.0, 1.0, 0.0);
glBegin(GL_TRIANGLES);
glColor3f(1.0,1.0,1.0);
glVertex3f( 1.,-1.,0.);
glColor3f(1.0, 0.0, 0.0);
glVertex3f(-1.,-1.,0.);
glColor3f(0.0, 0.0, 1.0);
glVertex3f( 0., 1.,0.);
glEnd();
while(SDL_PollEvent(&evento)){
switch(evento.type){
case SDL_MOUSEBUTTONDOWN:
rotate=true;
cout << "ROT\n";
break;
case SDL_MOUSEBUTTONUP:
rotate=false;
break;
case SDL_QUIT:
fin = true;
break;
case SDL_KEYDOWN:
switch(evento.key.keysym.sym){
case SDLK_ESCAPE:
fin = true;
break;
case SDLK_LEFT:
break;
case SDLK_RIGHT:
break;
case SDLK_F11:
flags ^= SDL_FULLSCREEN;
if(SDL_SetVideoMode(640, 480, 32, flags)==NULL) {
fprintf(stderr, "No se pudo establecer el modo de video: %s\n", SDL_GetError());
exit(1);
}
glMatrixMode(GL_PROJECTION);
float color = 0;
glClearColor(color, color, color, 1);
gluPerspective(45, 640/480.f, 0.1, 100);
glMatrixMode(GL_MODELVIEW);
break;
}
break;
}
}
SDL_GL_SwapBuffers();
}while(!fin);
return 0;
}
````
with freeimage
`g++ main.cpp -omain -w -lSDL -lSDLmain -m32 -lGL -lGLU -lfreeimage -I/usr/include/SDL`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment