Jump to content
  • Advertisement

Alio

Member
  • Content Count

    11
  • Joined

  • Last visited

Community Reputation

0 Neutral

About Alio

  • Rank
    Member

Personal Information

  • Interests
    Art
    Audio
    Business
    Design
    DevOps
    Education
    Production
    Programming
    QA

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

  1. Hi I tried to introduce some inheritance to my game engine from the book SDL Game Development but I am getting a lot of errors. I am a real noob at c++ so I would appreciate a bit of detail about each error and what I can do to fix it, as far as I can tell the code is exactly the same as in the book on chapter 3 “Working with game objects” Please tell me what I am doing wrong to produce these errors and how I can fix them. Thanks. g++ main.cpp -fpermissive -lSDL2 -lSDL2_image In file included from main.cpp:7:0: GameObject.h: In member function ‘void Player::draw()’: GameObject.h:30:18: error: no matching function for call to ‘Player::draw()’ GameObject::draw() ^ GameObject.h:8:6: note: candidate: void GameObject::draw(SDL_Renderer*) void draw(SDL_Renderer* pRenderer); ^~~~ GameObject.h:8:6: note: candidate expects 1 argument, 0 provided In file included from main.cpp:8:0: Player.h: At global scope: Player.h:4:7: error: redefinition of ‘class Player’ class Player : public GameObject ^~~~~~ In file included from main.cpp:7:0: GameObject.h:25:7: note: previous definition of ‘class Player’ class Player : public GameObject ^~~~~~ In file included from main.cpp:11:0: Game.cpp: In member function ‘void Game::render()’: Game.cpp:84:11: error: no matching function for call to ‘GameObject::draw()’ m_go.draw(); ^ In file included from main.cpp:7:0: GameObject.h:8:6: note: candidate: void GameObject::draw(SDL_Renderer*) void draw(SDL_Renderer* pRenderer); ^~~~ GameObject.h:8:6: note: candidate expects 1 argument, 0 provided In file included from main.cpp:11:0: Game.cpp:86:26: error: no matching function for call to ‘Player::draw(SDL_Renderer*&)’ m_player.draw(m_pRenderer); ^ In file included from main.cpp:7:0: GameObject.h:28:6: note: candidate: void Player::draw() void draw() ^~~~ GameObject.h:28:6: note: candidate expects 0 arguments, 1 provided In file included from main.cpp:13:0: Player.cpp: At global scope: Player.cpp:1:77: error: no ‘void Player::load(int, int, int, int, std::__cxx11::string)’ member function declared in class ‘Player’ void Player::load(int x, int y, int width, int height, std::string textureID) ^ Player.cpp:6:6: error: prototype for ‘void Player::draw(SDL_Renderer*)’ does not match any in class ‘Player’ void Player::draw(SDL_Renderer* pRenderer) ^~~~~~ In file included from main.cpp:7:0: GameObject.h:28:6: error: candidate is: void Player::draw() void draw() ^~~~ Game.cpp Game.h GameObject.cpp GameObject.h main.cpp Player.cpp Player.h TextureManager.cpp TextureManager.h
  2. thanks I did that and got it running. Thanks
  3. Hello I have bought the book SDL game development from amazon to learn SDL2 game programming on Ubuntu. I have my first game engine up and running but when I add code to draw a BMP in the top left of the screen I just get a black screen when I run it. Can anybody help me solve this I would really appreciate it. Also I am not sure if I have the texture creation code on lines 8-15 in the right place, I tried moving it around but it didn't make a difference. main.cpp <code> #include <SDL2/SDL.h> #include "Game.h" #include "Game.cpp" int main(int argc, char * args[]) { Game * g_game = new Game; g_game->init("Chapter 1", 100,100,640,480,false); while(g_game->running()) { g_game->handleEvents(); g_game->update(); g_game->renderer(); } g_game->clean(); return 0; } <code/> Game.cpp <code> #include "Game.h" #include <iostream> bool Game::init(const char* title, int xpos, int ypos, int width, int height, bool fullscreen) { SDL_Surface * pTempSurface = SDL_LoadBMP("assets/rider.bmp"); m_pTexture = SDL_CreateTextureFromSurface(m_pRenderer,pTempSurface); SDL_FreeSurface(pTempSurface); SDL_QueryTexture(m_pTexture, NULL,NULL,&m_sourceRectangle.w,&m_sourceRectangle.h); m_destinationRectangle.x = m_sourceRectangle.x =0; m_destinationRectangle.y = m_sourceRectangle.y =0; m_destinationRectangle.w = m_sourceRectangle.w; m_destinationRectangle.h = m_sourceRectangle.h; int flags = 0; if (fullscreen) { flags = SDL_WINDOW_FULLSCREEN; } // attempt to initialize SDL if(SDL_Init(SDL_INIT_EVERYTHING) == 0) { std::cout<<"SDL Init Success\n"; // init the window m_pWindow = SDL_CreateWindow(title, xpos, ypos, width, height, flags); if(m_pWindow != 0) //window init success { std::cout<<"Window Creation Success\n"; m_pRenderer = SDL_CreateRenderer(m_pWindow, -1, 0); if(m_pRenderer !=0) // render init success { std::cout<<"Renderer Creation Success\n"; SDL_SetRenderDrawColor(m_pRenderer, 0,0,0,0); } else { std::cout<<"Renderer Init Fail\n"; return false; // renderer init fail } } else { std::cout<<"Window Init Fail\n"; return false; //window init fail } } else { std::cout<<"SDL Init Fail\n"; return false; // SDL init fail } std::cout<<"Init success\n"; m_bRunning = true; // everything inited successfully // start the main loop return true; } void Game::renderer() { SDL_RenderClear(m_pRenderer); // clears the renderer // to the draw colour SDL_RenderCopy(m_pRenderer, m_pTexture, &m_sourceRectangle,&m_destinationRectangle); SDL_RenderPresent(m_pRenderer); // draw to the screen } void Game::update() { } void Game::clean() { std::cout<<"Cleaning game\n"; SDL_DestroyWindow(m_pWindow); SDL_DestroyRenderer(m_pRenderer); SDL_Quit(); } void Game::handleEvents() { SDL_Event event; if(SDL_PollEvent(&event)) { switch (event.type) { case SDL_QUIT: m_bRunning = false; break; } } } <code/> game.h <code> #ifndef __Game__ #define __Game__ class Game { public: Game() {} ~Game() {} bool init(const char* title, int xpos, int ypos, int width, int height, bool fullscreen); void renderer(); void update(); void handleEvents(); void clean(); // a function to access the private running variable bool running() {return m_bRunning;} private: SDL_Window * m_pWindow; SDL_Renderer * m_pRenderer; SDL_Texture * m_pTexture; //the new SDL Texture variable SDL_Rect m_sourceRectangle; // the first rectangle SDL_Rect m_destinationRectangle;// another rectangle bool m_bRunning; }; #endif /* defined(__Game_h__) */ <code/>
  4. Why isn't this opengl background and lighting working? #include<iostream> #include<stdlib.h> #ifdef __APPLE__ #include<OpenGL/OpenGL.h> #include<GLUT/glut.h> #else #include<GL/glut.h> #endif #include<math.h> // g++ rotateCube.cpp -lm -lglut -lGL -lGLU using namespace std; void handleResize(int w, int h); void drawCube(); void update(int value); void initRendering(); //The coordinates for vertices of the cube double x=0.6; double y=0.6; double z=0.6; float angle=0.0; void drawCube() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Reset transformations glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glTranslatef(0.0,0.0,-5.0); //Add ambient light GLfloat ambientColor[]={0.2,0.2,0.2,1.0}; glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambientColor); //Add a positioned light GLfloat lightColor0[]={0.5,0.5,0.5,1.0}; GLfloat lightPos0[]={4.0,0.0,8.0,1.0}; glLightfv(GL_LIGHT0,GL_DIFFUSE, lightColor0); glLightfv(GL_LIGHT0,GL_DIFFUSE, lightPos0); glTranslatef(0.5,1.0,0.0); glRotatef(angle,1.0,1.0,1.0); glRotatef(angle,1.0,0.0,1.0); glRotatef(angle,0.0,1.0,1.0); glTranslatef(-0.5,-1.0,0.0); //Create the 3d cube //BACK glBegin(GL_POLYGON); glColor3f(0.5,0.3,0.2); glVertex3f(x,-y,z); glVertex3f(x,y,z); glVertex3f(-x,y,z); glVertex3f(-x,-y,z); glEnd(); //FRONT glBegin(GL_POLYGON); glColor3f(0.0,0.5,0.0); glVertex3f(-x,y,-z); glVertex3f(-x,-y,-z); glVertex3f(x,-y,-z); glVertex3f(x,y,-z); glEnd(); //LEFT glBegin(GL_POLYGON); glColor3f(0.5,0.5,0.5); glVertex3f(-x,-y,-z); glVertex3f(-x,-y,z); glVertex3f(-x,y,z); glVertex3f(-x,y,-z); glEnd(); //RIGHT glBegin(GL_POLYGON); glColor3f(0.0,0.0,0.0); glVertex3f(x,-y,-z); glVertex3f(x,-y,z); glVertex3f(x,y,-z); glVertex3f(x,y,-z); glEnd(); //TOP glBegin(GL_POLYGON); glColor3f(0.6,0.0,0.0); glVertex3f(x,y,z); glVertex3f(-x,y,z); glVertex3f(-x,y,-z); glVertex3f(x,y,-z); glEnd(); //BOTTOM glBegin(GL_POLYGON); glColor3f(0.3,0.0,0.3); glVertex3f(-x,-y,-z); glVertex3f(-x,-y,z); glVertex3f(x,-y,z); glVertex3f(x,-y,-z); glEnd(); glFlush(); glutSwapBuffers(); } // Function for increasing the angle variable smoothly, // keeps it <=360 //It can also be implemented using the modulo operator void update(int value) { angle+=1.0f; if(angle>360) { angle-=360; } glutPostRedisplay(); glutTimerFunc(25, update, 0); } //Initializes 3D rendering void initRendering() { glEnable(GL_DEPTH_TEST); glEnable(GL_COLOR_MATERIAL); //Set the color of the background glClearColor(0.7f,0.8f,1.0f,1.0f); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glEnable(GL_NORMALIZE); } // Called when the window is resized void handleResize(int w, int h) { glViewport(0,0,w,h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(45.0,(double)w/(double)h,1.0,200.0); } int main(int argc, char **argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); glutInitWindowSize(700,700); glutInitWindowPosition(100,100); glutCreateWindow("OpenGL - Rotating a Cube"); glutDisplayFunc(drawCube); glutReshapeFunc(handleResize); // Add a timer for the update(...) function glutTimerFunc(25, update, 0); glutMainLoop(); return 0; } #include<iostream> #include<stdlib.h> #ifdef __APPLE__ #include<OpenGL/OpenGL.h> #include<GLUT/glut.h> #else #include<GL/glut.h> #endif #include<math.h> // g++ rotateCube.cpp -lm -lglut -lGL -lGLU using namespace std; void handleResize(int w, int h); void drawCube(); void update(int value); void initRendering(); //The coordinates for vertices of the cube double x=0.6; double y=0.6; double z=0.6; float angle=0.0; void drawCube() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Reset transformations glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glTranslatef(0.0,0.0,-5.0); //Add ambient light GLfloat ambientColor[]={0.2,0.2,0.2,1.0}; glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambientColor); //Add a positioned light GLfloat lightColor0[]={0.5,0.5,0.5,1.0}; GLfloat lightPos0[]={4.0,0.0,8.0,1.0}; glLightfv(GL_LIGHT0,GL_DIFFUSE, lightColor0); glLightfv(GL_LIGHT0,GL_DIFFUSE, lightPos0); glTranslatef(0.5,1.0,0.0); glRotatef(angle,1.0,1.0,1.0); glRotatef(angle,1.0,0.0,1.0); glRotatef(angle,0.0,1.0,1.0); glTranslatef(-0.5,-1.0,0.0); //Create the 3d cube //BACK glBegin(GL_POLYGON); glColor3f(0.5,0.3,0.2); glVertex3f(x,-y,z); glVertex3f(x,y,z); glVertex3f(-x,y,z); glVertex3f(-x,-y,z); glEnd(); //FRONT glBegin(GL_POLYGON); glColor3f(0.0,0.5,0.0); glVertex3f(-x,y,-z); glVertex3f(-x,-y,-z); glVertex3f(x,-y,-z); glVertex3f(x,y,-z); glEnd(); //LEFT glBegin(GL_POLYGON); glColor3f(0.5,0.5,0.5); glVertex3f(-x,-y,-z); glVertex3f(-x,-y,z); glVertex3f(-x,y,z); glVertex3f(-x,y,-z); glEnd(); //RIGHT glBegin(GL_POLYGON); glColor3f(0.0,0.0,0.0); glVertex3f(x,-y,-z); glVertex3f(x,-y,z); glVertex3f(x,y,-z); glVertex3f(x,y,-z); glEnd(); //TOP glBegin(GL_POLYGON); glColor3f(0.6,0.0,0.0); glVertex3f(x,y,z); glVertex3f(-x,y,z); glVertex3f(-x,y,-z); glVertex3f(x,y,-z); glEnd(); //BOTTOM glBegin(GL_POLYGON); glColor3f(0.3,0.0,0.3); glVertex3f(-x,-y,-z); glVertex3f(-x,-y,z); glVertex3f(x,-y,z); glVertex3f(x,-y,-z); glEnd(); glFlush(); glutSwapBuffers(); } // Function for increasing the angle variable smoothly, // keeps it <=360 //It can also be implemented using the modulo operator void update(int value) { angle+=1.0f; if(angle>360) { angle-=360; } glutPostRedisplay(); glutTimerFunc(25, update, 0); } //Initializes 3D rendering void initRendering() { glEnable(GL_DEPTH_TEST); glEnable(GL_COLOR_MATERIAL); //Set the color of the background glClearColor(0.7f,0.8f,1.0f,1.0f); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glEnable(GL_NORMALIZE); } // Called when the window is resized void handleResize(int w, int h) { glViewport(0,0,w,h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(45.0,(double)w/(double)h,1.0,200.0); } int main(int argc, char **argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); glutInitWindowSize(700,700); glutInitWindowPosition(100,100); glutCreateWindow("OpenGL - Rotating a Cube"); glutDisplayFunc(drawCube); glutReshapeFunc(handleResize); // Add a timer for the update(...) function glutTimerFunc(25, update, 0); glutMainLoop(); return 0; }
  5. Why isn't this opengl background and lighting working? #include<iostream> #include<stdlib.h> #ifdef __APPLE__ #include<OpenGL/OpenGL.h> #include<GLUT/glut.h> #else #include<GL/glut.h> #endif #include<math.h> // g++ rotateCube.cpp -lm -lglut -lGL -lGLU using namespace std; void handleResize(int w, int h); void drawCube(); void update(int value); void initRendering(); //The coordinates for vertices of the cube double x=0.6; double y=0.6; double z=0.6; float angle=0.0; void drawCube() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Reset transformations glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glTranslatef(0.0,0.0,-5.0); //Add ambient light GLfloat ambientColor[]={0.2,0.2,0.2,1.0}; glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambientColor); //Add a positioned light GLfloat lightColor0[]={0.5,0.5,0.5,1.0}; GLfloat lightPos0[]={4.0,0.0,8.0,1.0}; glLightfv(GL_LIGHT0,GL_DIFFUSE, lightColor0); glLightfv(GL_LIGHT0,GL_DIFFUSE, lightPos0); glTranslatef(0.5,1.0,0.0); glRotatef(angle,1.0,1.0,1.0); glRotatef(angle,1.0,0.0,1.0); glRotatef(angle,0.0,1.0,1.0); glTranslatef(-0.5,-1.0,0.0); //Create the 3d cube //BACK glBegin(GL_POLYGON); glColor3f(0.5,0.3,0.2); glVertex3f(x,-y,z); glVertex3f(x,y,z); glVertex3f(-x,y,z); glVertex3f(-x,-y,z); glEnd(); //FRONT glBegin(GL_POLYGON); glColor3f(0.0,0.5,0.0); glVertex3f(-x,y,-z); glVertex3f(-x,-y,-z); glVertex3f(x,-y,-z); glVertex3f(x,y,-z); glEnd(); //LEFT glBegin(GL_POLYGON); glColor3f(0.5,0.5,0.5); glVertex3f(-x,-y,-z); glVertex3f(-x,-y,z); glVertex3f(-x,y,z); glVertex3f(-x,y,-z); glEnd(); //RIGHT glBegin(GL_POLYGON); glColor3f(0.0,0.0,0.0); glVertex3f(x,-y,-z); glVertex3f(x,-y,z); glVertex3f(x,y,-z); glVertex3f(x,y,-z); glEnd(); //TOP glBegin(GL_POLYGON); glColor3f(0.6,0.0,0.0); glVertex3f(x,y,z); glVertex3f(-x,y,z); glVertex3f(-x,y,-z); glVertex3f(x,y,-z); glEnd(); //BOTTOM glBegin(GL_POLYGON); glColor3f(0.3,0.0,0.3); glVertex3f(-x,-y,-z); glVertex3f(-x,-y,z); glVertex3f(x,-y,z); glVertex3f(x,-y,-z); glEnd(); glFlush(); glutSwapBuffers(); } // Function for increasing the angle variable smoothly, // keeps it <=360 //It can also be implemented using the modulo operator void update(int value) { angle+=1.0f; if(angle>360) { angle-=360; } glutPostRedisplay(); glutTimerFunc(25, update, 0); } //Initializes 3D rendering void initRendering() { glEnable(GL_DEPTH_TEST); glEnable(GL_COLOR_MATERIAL); //Set the color of the background glClearColor(0.7f,0.8f,1.0f,1.0f); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glEnable(GL_NORMALIZE); } // Called when the window is resized void handleResize(int w, int h) { glViewport(0,0,w,h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(45.0,(double)w/(double)h,1.0,200.0); } int main(int argc, char **argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); glutInitWindowSize(700,700); glutInitWindowPosition(100,100); glutCreateWindow("OpenGL - Rotating a Cube"); glutDisplayFunc(drawCube); glutReshapeFunc(handleResize); // Add a timer for the update(...) function glutTimerFunc(25, update, 0); glutMainLoop(); return 0; }
  6. Thanks. I was missing glutPostRedisplay
  7. compiles fine with g++ colourfulrotatingcube.cpp -lglut -lGL -lGLU -o colourfulrotatingcube but the arrow keys are not moving the cube. Why? #define GL_GLEXT_PROTOTYPES #ifdef __APPLE__ #include<GLUT/glut.h> #else #include<GL/glut.h> #endif #include<math.h> void keyboard(int key, int x, int y); void drawCube(); // Rotate X double rX=0; // Rotate Y double rY=0; // The coordinates for the vertices of the cube double x = 0.6; double y = 0.6; double z = 0.6; void drawCube() { // Set background Colour glClearColor(0.4,0.4,0.4,1.0); // Clear screen glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Reset transformations glLoadIdentity(); // Rotate when user changes rX and rY glRotatef(rX,1.0,0.0,0.0); glRotatef(rY,0.0,1.0,0.0); // BACK glBegin(GL_TRIANGLES); glColor3f(0.4,0.3,0.5); glVertex3f(x,y,z); glVertex3f(x,-y,z); glVertex3f(-x,y,z); glEnd(); // FRONT // Using 4 triangles! glBegin(GL_TRIANGLES); glColor3f(0.1,0.5,0.3); glVertex3f(-x,y,z); glVertex3f(0,0,-z); glVertex3f(-x,-y,-z); glEnd(); glBegin(GL_TRIANGLES); glColor3f(0.0,0.5,0.0); glVertex3f(-x,-y,-z); glVertex3f(-0,0,-z); glVertex3f(-x,-y,-z); glEnd(); glBegin(GL_TRIANGLES); glColor3f(0.1,0.3,0.3); glVertex3f(-x,y,-z); glVertex3f(x,y,-z); glVertex3f(0,0,-z); glEnd(); glBegin(GL_TRIANGLES); glColor3f(0.2,0.2,0.2); glVertex3f(-x,-y,-z); glVertex3f(-x,-y,z); glVertex3f(-x,y,-z); glEnd(); // LEFT glBegin(GL_TRIANGLES); glColor3f(0.3,0.5,0.6); glVertex3f(-x,-y,-z); glVertex3f(-x,-y,z); glVertex3f(-x,y,-z); glEnd(); glBegin(GL_TRIANGLES); glColor3f(0.5,0.5,0.5); glVertex3f(-x,y,z); glVertex3f(-x,y,z); glVertex3f(-x,y,-z); glEnd(); //RIGHT glBegin(GL_TRIANGLES); glColor3f(0.2,0.2,0.2); glVertex3f(x,y,z); glVertex3f(x,y,-z); glVertex3f(x,-y,z); glEnd(); glBegin(GL_TRIANGLES); glColor3f(0.0,0.0,0.0); glVertex3f(x,y,z); glVertex3f(x,y,-z); glVertex3f(-x,y,-z); glEnd(); //TOP glBegin(GL_TRIANGLES); glColor3f(0.6,0.0,0.0); glVertex3f(x,y,z); glVertex3f(x,y,-z); glVertex3f(-x,y,-z); glEnd(); glBegin(GL_TRIANGLES); glColor3f(0.6,0.1,0.2); glVertex3f(-x,y,z); glVertex3f(x,y,z); glVertex3f(-x,y,-z); glEnd(); //BOTTOM glBegin(GL_TRIANGLES); glColor3f(0.4,0.0,0.4); glVertex3f(-x,-y,-z); glVertex3f(-x,-y,z); glVertex3f(x,-y,z); glEnd(); glBegin(GL_TRIANGLES); glColor3f(0.3,0.0,0.3); glVertex3f(x,-y,-z); glVertex3f(-x,-y,-z); glVertex3f(x,-y,z); glEnd(); glFlush(); glutSwapBuffers(); } void keyboard(int key, int x, int y) { if(key == GLUT_KEY_RIGHT) { rY +=15; } else if(key == GLUT_KEY_LEFT) { rY -=15; } else if(key ==GLUT_KEY_DOWN) { rX -=15; } else if(key ==GLUT_KEY_UP) { rX +=15; } } int main(int argc, char **argv) { // Initializr GLUT and process parameters glutInit(&argc, argv); // Request double buffered true colour window with Z-buffer glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); glutInitWindowSize(700,700); glutInitWindowPosition(100,100); // Create window glutCreateWindow("Linux Journal Open GL Cube"); //Enable Z-buffer depth test glEnable(GL_DEPTH_TEST); //Callback functions glutDisplayFunc(drawCube); glutSpecialFunc(keyboard); // Pass control to GLUT for events glutMainLoop(); return 0; }
  8. Its fixed with: int main(int argc, char *argv[]) { (void)(argc); (void)(argv);
  9. I'm trying to get into SDL1 and opengl, this compiles fine under gcc, -lSDL -lGL why do I get error: line 6: syntax error near unexpected token `('line 6: `int main()' #include<SDL/SDL.h> #include<GL/gl.h> #include<stdio.h> #include<stdlib.h> int main() { /*Inintialize SDL as usual */ if (SDL_Init(SDL_INIT_VIDEO) != 0) { printf("Error: %s\n", SDL_GetError()); return 1; } atexit(SDL_Quit); /* Enable OpenGL double buffering */ SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); /*Set the colour depth (16 bit 565). */ SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5); SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 6); SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5); /* Create a 640 x 480, 16 bit window with support for Open GL rendering. Unfortunately we won't know whether this is hardware accelerated. */ if (SDL_SetVideoMode(640, 480, 16, SDL_OPENGL) == NULL) { printf("Error: %s\n", SDL_GetError()); return 1; } SDL_WM_SetCaption("OpenGL with SDL!", "OpenGL"); /* We can now use any OpenGL rendering commands */ glClearColor(0.0,0.0,0.0,0.0); glClear(GL_COLOR_BUFFER_BIT); glColor3f(1.0,1.0,1.0); glOrtho(-1.0,1.0,-1.0,1.0,-1.0,1.0); glBegin(GL_POLYGON); glVertex2f(-0.5,-0.5); glVertex2f(-0.5,0.5); glVertex2f(0.5,0.5); glVertex2f(0.5,-0.5); glEnd(); glFlush(); /*Display the back buffer to the screen */ SDL_GL_SwapBuffers(); /*Wait a few seconds. */ SDL_Delay(5000); return 0; }
  10. Thanks Virion will check that out 🙂
  11. Hi I am trying to learn sdl 1 and open gl on linux, I have this c code. #include<SDL/SDL.h> #include<GL/gl.h> #include<stdio.h> #include<stdlib.h> int main() { /*Inintialize SDL as usual */ if (SDL_Init(SDL_INIT_VIDEO) != 0) { printf("Error: %s\n", SDL_GetError()); return 1; } atexit(SDL_Quit); /* Enable OpenGL double buffering */ SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); /*Set the colour depth (16 bit 565). */ SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5); SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 6); SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5); /* Create a 640 x 480, 16 bit window with support for Open GL rendering. Unfortunately we won't know whether this is hardware accelerated. */ if (SDL_SetVideoMode(640, 480, 16, SDL_OPENGL) == NULL) { printf("Error: %s\n", SDL_GetError()); return 1; } SDL_WM_SetCaption("OpenGL with SDL!", "OpenGL"); /* We can now use any OpenGL rendering commands */ glViewport(80, 0, 480, 480); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glClear(GL_COLOR_BUFFER_BIT); glBegin(GL_TRIANGLES); glColor3f(1.0, 0, 0); glVertex3f(0.0, 1.0, -2.0); glColor3f(0, 0, 1.0); glVertex3f(1.0, -1.0, -2.0); glColor3f(0, 0, 1.0); glVertex3f(-1.0, -1.0, -2.0); glEnd(); glFlush(); /*Display the back buffer to the screen */ SDL_GL_SwapBuffers(); /*Wait a few seconds. */ SDL_Delay(5000); return 0; } why is it producing just a blank screen, it compiled fine with gcc linking to -lSDL and -lGL, did I miss any, also I ran glxinfo | grep "version" to see which version of opengl I got. Output: server glx version string: 1.4 client glx version string: 1.4 GLX version: 1.4 Max core profile version: 3.3 Max compat profile version: 3.0 Max GLES1 profile version: 1.1 Max GLES[23] profile version: 3.0 OpenGL core profile version string: 3.3 (Core Profile) Mesa 18.2.2 OpenGL core profile shading language version string: 3.30 OpenGL version string: 3.0 Mesa 18.2.2 OpenGL shading language version string: 1.30 OpenGL ES profile version string: OpenGL ES 3.0 Mesa 18.2.2 OpenGL ES profile shading language version string: OpenGL ES GLSL ES 3.00 P Please help me get started and get some shapes on my screen. Thanks.
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!