Jump to content
  • Advertisement

Search the Community

Showing results for tags 'SDL'.



More search options

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Categories

  • Audio
    • Music and Sound FX
  • Business
    • Business and Law
    • Career Development
    • Production and Management
  • Game Design
    • Game Design and Theory
    • Writing for Games
    • UX for Games
  • Industry
    • Interviews
    • Event Coverage
  • Programming
    • Artificial Intelligence
    • General and Gameplay Programming
    • Graphics and GPU Programming
    • Engines and Middleware
    • Math and Physics
    • Networking and Multiplayer
  • Visual Arts
  • Archive

Categories

  • Audio
  • Visual Arts
  • Programming
  • Writing

Categories

  • Game Dev Loadout
  • Game Dev Unchained

Categories

  • Game Developers Conference
    • GDC 2017
    • GDC 2018
  • Power-Up Digital Games Conference
    • PDGC I: Words of Wisdom
    • PDGC II: The Devs Strike Back
    • PDGC III: Syntax Error

Forums

  • Audio
    • Music and Sound FX
  • Business
    • Games Career Development
    • Production and Management
    • Games Business and Law
  • Game Design
    • Game Design and Theory
    • Writing for Games
  • Programming
    • Artificial Intelligence
    • Engines and Middleware
    • General and Gameplay Programming
    • Graphics and GPU Programming
    • Math and Physics
    • Networking and Multiplayer
  • Visual Arts
    • 2D and 3D Art
    • Critique and Feedback
  • Community
    • GameDev Challenges
    • GDNet+ Member Forum
    • GDNet Lounge
    • GDNet Comments, Suggestions, and Ideas
    • Coding Horrors
    • Your Announcements
    • Hobby Project Classifieds
    • Indie Showcase
    • Article Writing
  • Affiliates
    • NeHe Productions
    • AngelCode
  • Topical
    • Virtual and Augmented Reality
    • News
  • Workshops
    • C# Workshop
    • CPP Workshop
    • Freehand Drawing Workshop
    • Hands-On Interactive Game Development
    • SICP Workshop
    • XNA 4.0 Workshop
  • Archive
    • Topical
    • Affiliates
    • Contests
    • Technical
  • GameDev Challenges's Topics
  • For Beginners's Forum

Calendars

  • Community Calendar
  • Games Industry Events
  • Game Jams
  • GameDev Challenges's Schedule

Blogs

There are no results to display.

There are no results to display.

Product Groups

  • Advertisements
  • GameDev Gear

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


About Me


Website


Role


Twitter


Github


Twitch


Steam

Found 47 results

  1. Hi, sorry for my English. My comp specs are: Win 8.1, DirectX 11.2, Geforce GTX750 Ti with latest drivers. In my project I must use color blend mode max via SDL_ComposeCustomBlendMode which is supported in SDL 2.0.9 by direct3d11 renderer only. Changing defines in SDL_config.h or SDL_config_windows.h (SDL_VIDEO_RENDER_D3D11 to 1 and SDL_VIDEO_RENDER_D3D to 0) doesn't help. SDL says my system supports direct3d, opengl, opengles2 and software renderers. What should I do to activate direct3d11 renderer so I can use blend mode max?
  2. Hello, I'm new here, I'm currently taking a 2 and a half year college course on programming. We're going through C algorithms, C# basics because we just began with C# and some Unix/Linux stuff. We're at the 2nd year of college, previously to that we mostly studied Linear Algebra, Boolean Algebra, and Statistics for the mathematical foundation of programming and we learned some C. At the end of the year, I'll have to have the final class project ready. I've decided to build my own 2d platform game from scratch, using only the C language and SDL2 to make the job easier. I'm a bit of a Mario fanatic, I have all of the Mario games available on the Nintendo 3DS I own so I'll want to make it similar to Mario. I'll be building it on Visual Studio community but I want the code to be portable enough to be easy to compile it on Linux and MacOS so as to expand on the project in the future. Can I get some advice on this, please? How do I start? I already know some C but I haven't done any 2d programming, closest I came was making lines and squares with an opengl library called glut.h at in a recent college course on graphics programming. It didn't involve SDL. Thank you,
  3. Hey, everyone, I've been teaching myself C++ for the past week, although I've been coding and tinkering with games for almost 16 years. I'm comfortable with the C++ syntax already and have been chugging along fine, but I've hit a bit of a snag. I'm using CodeBlocks 17.12, SDL 2.0.8, and SDL Image 2.0.3, and I am trying to load a PNG file in for use as a sprite. I have SDL linked perfectly fine, and have been messing around with it's commands for a couple of days with no problems. Loading BMPs, editing pixel matrices, getting user input, basic loop timing and flow, etc. Yesterday, I tried to install SDL Image, and I have the library installed to the point that CodeBlocks can pick up it's syntax and I can use auto finish on it's commands, and there are no compilation errors. The problem comes when I run my code. Through process of elimination(thanks to my in-built error checking), I have narrowed it down to this code: /*** -INITIALIZE PNG LOADING- ***/ int flags=IMG_INIT_PNG; int initted=IMG_Init(flags); if((initted&&flags) != flags) { SDL_Log("Unable to initialize image load: %s", IMG_GetError()); return EXIT_FAILURE; } /*** -LOAD IMAGES- ***/ SDL_Surface *image; SDL_RWops *rwop; rwop=SDL_RWFromFile("\media\die.png", "rb"); image=IMG_LoadPNG_RW(rwop); if(!image) { SDL_Log("Unable to initialize load image: %s", IMG_GetError()); return EXIT_FAILURE; } If I comment block all the Load Images part it runs(even with the PNG Loading part still in), but if I dont, it exits due to the error. After digging around to see what could be wrong I went to the SDL Image website to read that PNG files may need libPNG and zlib. I tried for hours to install those two libraries, but it looks like no matter which archive I download it's just full of UNIX garbage that I can't use on Windows. This, however, doesn't seem to be the path I needed to take, as through testing BMPs do the same thing(Which SDL Image says should load natively). I don't know if there is an error in my code, or if I need libPNG and zlib. I'm lost here. Help would be greatly appreciated, thanks, -Omerta
  4. Hey guys, what's up? I've been building a 2D game with SDL, and I'd really like it to have that retro console/arcade look and feel. This mostly because those are the kinds of games I play, and have since I was a kid, but also partly because 8-bit sprites or (S)NES sprite sheets are about as good as I get in terms of graphic design (lol). But those old games had really small sprites, 8x8 at the least or 64x64 at the most. And of course, those old consoles had a surprisingly small resolution of 256x240. Another important note here: I'm really only targeting PCs for now; I know SDL can be ported to pretty much anything, but I only have my PC to test it on. I'm also using Windows 10 x64 and Visual Studio 2017, if that helps. So I started out by using "fake" fullscreen (passing SDL_WINDOW_FULLSCREEN_DESKTOP into the window creation functions). But this turned out to be a problem because SDL's drawing functions are pixel based. This is good IMOt, because it makes the math simpler and keeps the images crisper. But you can't get half-a-pixel, so scaling to fit the player's desktop is literally impossible in some cases. The end result is I had to draw black bars across the top and bottom, not just on the left and right. If possible I would like to avoid that, so I switched to "real" fullscreen (SDL_WINDOW_FULLSCREE). The lowest I could get it to go is 640x480, which is perfect (all image widths and heights can be multiplied by two to fill in the space). But is 640x480 still supported on modern monitors? The fact that it worked on my laptop is all well and good, but I'm afraid it would be a problem for others. I remember using Game Maker (before it was a "studio") back in the early 2000s and that resolution was not an issue back then. But is it still supported in 2018? My laptop is relatively new (about 2 years old), a Dell running at 1366x768 normally. If the answer is "no", what resolution(s) should I be using for this type of game? Thanks & happy Labor Day weekend!
  5. Hi guys, I've been learning to make my SDL reusable framework from the book SDL game development (image below). And now I'm trying to understand the ScrollingBackground (page 206 - creating Alien attack) but I still haven't figured out the meaning of the code. If someone finished this book please show me a more specific meaning, idea of the code (sorry for my bad english)
  6. So, I am currently redesigning my input system to more easily allow for input mapping. In terms of mouse and keyboard, no issues there. However, I seem to be having a bit of trouble wrapping my head around what to do for controllers. I use SDL2 to read input events. SDL2 has 2 similar yet different APIs for controller input; the Joystick API and the GameController API. The Joystick API is very generic; it basically tells you how many buttons and axes the controller has, and leaves the rest for you to figure out. The GameController API is built on top of this system, but tries to map everything in a fashion similar to an XBox 360 controller, meaning that axes and buttons are fairly standardized, but this is only if the controller exists in SDL's database of known game controllers. I want to support as many control options as possible, while maximizing convenience for the players (and myself). Keeping that in mind, here are the questions I have regarding the design of the system: Should I actually bother using the Joystick API, or should I only accept GameControllers? The GameController API being standardized is certainly a strong positive, but this fundamentally limits the player's control options. As far as I understand the GameController API, it is strictly limited to mimicking a 360 controller. Meaning that if a controller is registered but has additional buttons or axes, I'm not sure how the API would handle it, or even if I would be allowed to use those. If I were to use the Joystick API, how would I handle things such as menu navigation? Joysticks are not in any way standardized, so I literally cannot tell up from right or what button should be the confirm button. I could have some sort of popup window forcing players to map those controls immediately, but that strikes me as intrusive and inelegant. This is not specifically SDL related necessarily, but should controllers that look similar have the same mappings? For example if a player has both a 360 controller and a DualShock, and he remaps controls on his 360 controller, should those carry over to the DualShock, or should they be treated separately? If so, this would seem to be a boon for using only the GameController API, but things like arcade sticks also can be considered GameControllers, it depends on if SDL2 recognizes it. In that case, would I try to treat the arcade stick GameController different than the first two, or just roll with the same mapping for all GameControllers? A lot of these questions come from my relative inexperience with PC gaming with a controller; I'm not entirely sure what players expect and demand from controller-related options. Any help you could provide would be greatly appreciated.
  7. Hi there, I'm currently working with SDL2 and have been able to successfully render textures to the screen. I've also been experimenting with the sound and event mechanisms in SDL2. I've recently been thinking about other aspects of game design, specifically UI design. As I've stared envisioning my game, I see there is need to handle text input, button clicking, dropdown menus, and more. I've done some UI programming in other languages (Java, C# winforms, etc.) and have even done some in Qt. These libraries often feature all the standard UI elements. As of currently, I'm trying to figure out what SDL2's role should be in the end application. Should SDL2 only be used for game rendering, sound handling, and game inputs? And then would it make sense to use an external GUI library to handle all of the other standard UI features? For those of you familiar with SDL2, what purpose do you believe it serves?
  8. I am at the first year of diploma and I am planing to make a nice small 2D or 3D First Person Shooter game . As I mentioned I am just at first year in IT ,I Dont know much about game developing but I do know lots of more things that normal 1st and even 3rd year students . I Know Java,C,C++ and little bit of python and GTK+ framework . I am currently trying to learn SDL and Qt with C++. I will also happily learn new technology if required to make games. Now my main Question's are:- How much time will it take to make SMALL 2D game as a single person in SDL while LEARNING SDL ? How much time will it take to make SMALL 3D game as a single person in SDL while LEARNING SDL ? Will learning Qt help me make games faster or with High performance ? My main platform is Linux and Android.I don't care if It runs on windows or Mac but it should run fine on Linux . Thanks in advance
  9. Hi, first post here! Been reading png files in SDL and using them as textures... Now, would like to include in my game 2 short videos made in Blender, in dvi and mp4 formats. Went over NeHe lesson 35 but when I try to read the dvi file, it gives null pointer for lpbi, see below. Is it possible to include video files in OpenGL and how, please? ;-))) void GrabAVIFrame(int frame) // Grabs A Frame From The Stream { LPBITMAPINFOHEADER lpbi; // Holds The Bitmap Header Information lpbi = (LPBITMAPINFOHEADER)AVIStreamGetFrame(pgf, frame); // Grab Data From The AVI Stream pdata=(char *)lpbi+lpbi->biSize+lpbi->biClrUsed * sizeof(RGBQUAD); // Pointer To Data Returned By AVIStreamGetFrame // Convert Data To Requested Bitmap Format DrawDibDraw (hdd, hdc, 0, 0, 256, 256, lpbi, pdata, 0, 0, width, height, 0); flipIt(data); // Swap The Red And Blue Bytes (GL Compatability) // Update The Texture glTexSubImage2D (GL_TEXTURE_2D, 0, 0, 0, 256, 256, GL_RGB, GL_UNSIGNED_BYTE, data); }
  10. sneaky_squirrel

    Researching my Animation Pipeline

    This is my first blog post. I am making a videogame as a learning exercise, using SDL 2.0 as my framework (I can't call it an engine, but I'm using it as my game engine). I opted to attempt a 2D Turn Based game. Animation I have followed SDL tutorials and am now familiar with [Textures] and [Rectangles] in SDL, necessary for animating characters in the game. I wrote wrapper code to turn my sprite sheets into living characters. Now that I have achieved animation implementation, I focused on getting a practical art asset pipeline (drawing the sprite sheets). 1) I first tried Medibang. I had to manually position the sprites in my sprite sheet, and the Surface Pro 4 (tablet) didn't work. 2) I then tried using Graphics Gale. I found out I'm a terrible pixel artist. 3) I checked out Krita again. It turns my tablet into an electric oven. But I can draw without lag, it has animation support, exports a series of png files, and I can use texture Packer to create the sprite sheet. Gif with 1 Boar was made with Medibang. The 3 sprite men were made with Graphics Gale, and the three boars were made with [ Krita + Texture Packer ]. What did I learn? Animation is expensive, took me way longer to draw 16 frames of animation than I would have liked. I want to focus more on programming more features, and less on animating. Although I do want to see how "pretty" I can push a game. For now, I'll try to stick to easier character designs and shorter idle animations.
  11. Hello everyone! First time posting in the forum. I've just completed my first game ever ( C++ / SDL ), and I am feeling utterly proud. It is a small game resembling Missile Command. The code is a mess, but it is my mess! In the process of making the game, I developed my own little game engine. My question is, where would be a good place to spread the news to at least get some people to try the game?
  12. I can't get SDL to make any rectangles on my Mac. The program I wrote worked completely fine on a Windows computer, but whenever I call the SDL_FillRect function on my Mac, nothing appears on the screen. I suspect this may be caused by a compilation issue. I tried to install SDL Unix-style using Homebrew. Inserted below is what I write into the terminal and my code. g++ -o main test.cpp -L/usr/local/Cellar/sdl2/2.0.6/lib -lSDL2 -lSDL2main -I/usr/local/Cellar/sdl2/2.0.6/include/SDL2 #include <SDL.h> #include <iostream> #include <stdio.h> const int SCREEN_WIDTH = 640; const int SCREEN_HEIGHT = 480; const int PLAYER_WIDTH = 20; const int PLAYER_HEIGHT = 20; SDL_Window* w = NULL; SDL_Surface* s = NULL; SDL_Renderer* r = NULL; SDL_Rect BG = {0,0,SCREEN_WIDTH,SCREEN_HEIGHT}; bool init() { if (SDL_Init(SDL_INIT_VIDEO) < 0) { printf("Couldn't initialize. error: %s\n", SDL_GetError() ); return false; } else { w = SDL_CreateWindow("test", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN); if(w == NULL) { printf("Couldn't make window. error:%s\n", SDL_GetError() ); return false; } else { s = SDL_GetWindowSurface(w); r = SDL_CreateRenderer(w,-1,SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC); SDL_SetRenderDrawColor(r,0,0,0,0); return true; } } } void close() { SDL_FreeSurface(s); SDL_DestroyWindow(w); SDL_DestroyRenderer(r); SDL_Quit(); } class Player { private: int x; int y; int xvel; int yvel; int acceleration; SDL_Rect collider; public: bool landed; Player() { x = 0; y = SCREEN_HEIGHT - PLAYER_HEIGHT; xvel = 0; yvel = 0; acceleration = -1; collider.x = x; collider.y = y; collider.w = PLAYER_WIDTH; collider.h = PLAYER_HEIGHT; landed = true; } int getx() { return x; } int gety() { return y; } void setx(int num) { x = num; } void sety(int num) { y = num; } void setyvel(int num) { yvel += num; } void setxvel(int num) { xvel += num; } void move() { x += xvel; if( (y + PLAYER_HEIGHT) > SCREEN_HEIGHT) { y = SCREEN_HEIGHT - PLAYER_HEIGHT; yvel = 0; landed = true; } else { if(landed != true) { y += yvel; yvel = yvel - acceleration; } } collider.x = x; collider.y = y; } void render() { SDL_SetRenderDrawColor(r,255,255,255,255); SDL_RenderFillRect(r,&collider); SDL_SetRenderDrawColor(r,0,0,0,255); } }; int main(int argc, char *argv[]) { bool quit = false; SDL_Event e; //event for event polling Player p; int count = 0; if(init() == false) { printf("Init failed: %s\n", SDL_GetError()); } else { while(quit == false ) { while( SDL_PollEvent(&e) != 0) { if(e.type == SDL_QUIT) { quit = true; } if(e.type == SDL_KEYDOWN) { switch(e.key.keysym.sym) { case SDLK_LEFT: if(e.key.repeat == 0) { p.setxvel(-10); } break; case SDLK_RIGHT: if(e.key.repeat == 0) { p.setxvel(10); } break; case SDLK_UP: if(count < 5) { p.setyvel(-3); ++count; } p.landed = false; break; } } if(e.type == SDL_KEYUP && e.key.repeat == 0) { switch(e.key.keysym.sym) { case SDLK_LEFT: p.setxvel(10); break; case SDLK_RIGHT: p.setxvel(-10); break; case SDLK_UP: count = 0; break; } } } SDL_RenderClear(r); SDL_RenderFillRect(r,&BG); p.move(); p.render(); SDL_RenderPresent(r); } } close(); }
  13. Hey everybody, A little over a month ago, I made a post asking for help with my Missile Command game that I was making with regards to getting the Cannon to angle properly, and I was very pleased with all of the support. It really lit a fire under me (even moreso before I worked up the courage to ask the first time). Well, the game is not finished yet, but I have made a lot of progress since then ( it's very motivating ) and I've been able to work through the code and logic for shooting missiles from the cannon. The missile logic is almost ready, but there is one small bug that I discovered last week that has been wracking my brain non-stop, so I'm posting a new topic here. Here is an animated GIF of the missile behavior so far, in this shot, it's working as expected when you click the Left mouse button to fire one missile at a time: https://i.imgur.com/WyM2oxi.gifv But what I didn't expect to happen, was here, when you click the Left button to fire a new missile when the other missile is still in transit: https://i.imgur.com/PFJTDV1.gifv When the next missile is fired, the original missile changes course, re-angles itself and flies towards the next clicked spot, abandoning it's first clicked target, which is not what I wanted lol. It's like the missiles turn into smart missiles all of a sudden. The good news is that they're being destroyed when they hit the spot anyways, so that's something. So, for anyone reading this post, how can I make the previous missiles stay on their original target, even if I click the mouse to summon a new missile? Each missile's path should be independent of each other. This will also play into the logic for the upcoming falling Asteroid class I'll be adding, so solving this one for me will also allow me to make independent asteroids and I'm almost done the game! lol Here's the code: Game.h #ifndef GAME_H_ #define GAME_H_ // Preprocessors #include "SDL.h" #include "SDL_image.h" #include "SDL_ttf.h" #include "SDL_mixer.h" #include <iostream> #include <sstream> #include <stdio.h> #include <math.h> #include <cmath> #include <vector> // Inclusions for game objects #include "Cannon.h" #include "Missile.h" #include "Ground.h" #include "Silo.h" #define FPS_DELAY 500 #define SCREEN_WIDTH 800 #define SCREEN_HEIGHT 600 #define MAX_ROTATION 0 #define MIN_ROTATION 180 #define DEG_TO_RAD(deg) degrees * ( 3.141592653589793238 / 180) #define RAD_TO_DEG(rad) radians * ( 180 / 3.141592653589793238 ) #define OVER_PI ( 180 / 3.141592653589793238 ) class Game { public: Game(); ~Game(); bool Init(); void Run(); private: SDL_Window* window; SDL_Renderer* renderer; SDL_Texture* texture; // Timing unsigned int lastTick, fpsTick, fps, frameCount; // Test float testX, testY; /* Fonts for testing */ TTF_Font* fontMouseX; TTF_Font* fontMouseY; TTF_Font* fontCannonAngle; TTF_Font* fontFire; TTF_Font* fontAmmo; std::stringstream xValue; std::stringstream yValue; std::stringstream angleValue; std::stringstream fireValue; std::stringstream ammoValue; SDL_Texture* xTexture; SDL_Texture* yTexture; SDL_Texture* aTexture; SDL_Texture* fTexture; SDL_Texture* ammoTexture; int xWidth, xHeight, yWidth, yHeight, aWidth, aHeight; int fWidth, fHeight, ammoWidth, ammoHeight; /* END */ // Game objects Cannon* cannon; // The cannon, both the pipe and the base std::vector<Missile*> missileVec; // A vector of missiles Silo* silo; Ground* ground; // The ground SDL_Cursor* cursor; // The crosshair cursor // Flag to check if the cannon // is currently firing a missile bool isFiring; int clickedX; int clickedY; void Clean(); // Cleanup function void Update(float delta); // Update game elements void Render(float delta); // Render game elements void NewGame(); // Start a new game void SetCannonAngle( float vecX, float vecY); // Set the angle of cannon pipe double SetMissileAngle( float vecX, float vecY); // Set the angle of missile double ConvertDegrees(double radians); // Convert radians to degrees double ConvertRadians(double degrees); // Convert degrees to radians void ExplodeMissile(); // Explode the missile once it // has reached the target void CheckAsteroidCollisions(); // See if missile hits asteroid void CheckSiloCollisions(); // See if asteroid hits silo int GetSiloCount(); // Check if there are silos remaining }; #endif // GAME_H_ Game.cpp #include "Game.h" Game::Game() { window = 0; renderer = 0; } Game::~Game() { } bool Game::Init() { // Initialize the SDL video and audio subsystems SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO); // Create window window = SDL_CreateWindow("Missile Command v1.0", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 800, 600, SDL_WINDOW_SHOWN | SDL_WINDOW_OPENGL); if(!window) { std::cout << "Error creating window: " << SDL_GetError() << std::endl; return false; } // Create renderer renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED); if(!renderer) { std::cout << "Error creating renderer: " << SDL_GetError() << std::endl; return false; } // Enable TTF loading TTF_Init(); // Load the fonts fontMouseX = TTF_OpenFont("lato.ttf", 14); fontMouseY = TTF_OpenFont("lato.ttf", 14); fontCannonAngle = TTF_OpenFont("lato.ttf", 14); fontFire = TTF_OpenFont("lato.ttf", 14); fontAmmo = TTF_OpenFont("lato.ttf", 14); // Initialize resources SDL_Surface* surface = IMG_Load("test.png"); texture = SDL_CreateTextureFromSurface(renderer,surface); SDL_FreeSurface(surface); // Set mouse cursor to crosshair cursor = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_CROSSHAIR); SDL_SetCursor(cursor); // Initialize timing lastTick = SDL_GetTicks(); fpsTick = lastTick; fps = 0; // Set starting FPS value frameCount = 0; // Set starting frame count testX = 0; testY = 0; return true; } void Game::Clean() { // Clean resources SDL_DestroyTexture(texture); SDL_FreeCursor(cursor); SDL_DestroyRenderer(renderer); SDL_DestroyWindow(window); // Clean test data SDL_DestroyTexture(xTexture); SDL_DestroyTexture(yTexture); SDL_DestroyTexture(aTexture); SDL_DestroyTexture(fTexture); SDL_DestroyTexture(ammoTexture); } void Game::Run() { // Create game objects cannon = new Cannon(renderer); ground = new Ground(renderer); silo = new Silo(renderer); // Start a new game NewGame(); // Main loop while(1) { // Event handler SDL_Event e; // If event is a QUIT event, stop the program if(SDL_PollEvent(&e)) { if(e.type == SDL_QUIT) { break; } // If a mouse button was pressed... else if(e.type == SDL_MOUSEBUTTONDOWN) { // If the left mouse button was pressed, // set the "fire" flag to TRUE and // record x,y position of click if(e.button.button == SDL_BUTTON_LEFT) { clickedX = e.button.x; clickedY = e.button.y; isFiring = true; } } } // Calculate delta and fps unsigned int curTick = SDL_GetTicks(); float delta = (curTick - lastTick) / 1000.0f; // Cap FPS delay to specific amount if(curTick - fpsTick >= FPS_DELAY) { fps = frameCount * (1000.0f / (curTick - fpsTick)); fpsTick = curTick; frameCount = 0; //std::cout << "FPS: " << fps << std::endl; char buf[100]; snprintf(buf,100,"Missile Command v1.0 (fps: %u)", fps); SDL_SetWindowTitle(window,buf); } else { frameCount++; } lastTick = curTick; // Update and render the game Update(delta); Render(delta); } delete cannon; //missileVec.clear(); delete ground; delete silo; Clean(); // Close the fonts TTF_CloseFont(fontMouseX); TTF_CloseFont(fontMouseY); TTF_CloseFont(fontCannonAngle); TTF_CloseFont(fontFire); TTF_CloseFont(fontAmmo); TTF_Quit(); SDL_Quit(); } void Game::NewGame() { } void Game::Update(float delta) { // Game logic // Input, get mouse position to determine // the cannon pipe's angle for rendering int mX, mY; SDL_GetMouseState(&mX,&mY); // Assign the vector to variables float vectorX = mX - cannon->x; float vectorY = mY - cannon->y; // "Snap" the cannon angle to the angle between // cannon and mouse SetCannonAngle( vectorX, vectorY ); // If cannon is firing, create a missile and add // it to the missile vector container, and set // "isFiring" to false again if( isFiring == true ) { Missile* newMissile = new Missile(renderer, cannon->x, cannon->y); missileVec.push_back(newMissile); isFiring = false; } // If there are missiles in the vector container, set their direction // angle, fire them and update the missile positions for( int i = 0; i < missileVec.size(); i++ ) { // Update the missile's trajectory upon travel missileVec[i]->endX = clickedX; missileVec[i]->endY = clickedY; // Set a vector between the clicked location // and the missile float targetX = clickedX - missileVec[i]->x; float targetY = clickedY - missileVec[i]->y; // Set facing angle for missile missileVec[i]->angle = SetMissileAngle(targetX,targetY); // Update the missile's position missileVec[i]->Update(delta); // If the missile is triggered to be destroyed, // destroy it if( missileVec[i]->destroyNow == true ) { // Remove the destroyed missile // from the vector missileVec.pop_back(); } } /*// If there are no more silos, // start a new game if(GetSiloCount() == 0) { NewGame(); }*/ // Check if the cannon has fired a missile //cannon->missile->Update(delta, mX - cannon->x, mY - cannon->y); /* Test Data */ // Stream the X, Y, Angle and isFired values xValue.str(""); // Clear the stream before piping the xValue xValue << "X: " << mX; yValue.str(""); // Clear the stream before piping the yValue yValue << "Y: " << mY; angleValue.str(""); // Clear the stream before piping the angleValue angleValue << "Angle: " << cannon->angle; fireValue.str(""); // Clear the stream before piping the fireValue fireValue << "isFiring: " << std::boolalpha << isFiring; ammoValue.str(""); // Clear the stream before piping the ammoValue ammoValue << "Missiles in Vector: " << missileVec.size(); // Set font color to WHITE SDL_Color textColor = {255,255,255}; //*************************************** // DEBUG - Prepare the fonts for testing //*************************************** // Render the X-coordinate text SDL_Surface* temp = TTF_RenderText_Solid( fontMouseX, xValue.str().c_str(), textColor ); xTexture = SDL_CreateTextureFromSurface( renderer, temp ); xWidth = temp->w; xHeight = temp->h; SDL_FreeSurface(temp); // Render the Y-coordinate text temp = TTF_RenderText_Solid( fontMouseY, yValue.str().c_str(), textColor ); yTexture = SDL_CreateTextureFromSurface( renderer, temp ); yWidth = temp->w; yHeight = temp->h; SDL_FreeSurface(temp); // Render the angle text temp = TTF_RenderText_Solid( fontCannonAngle, angleValue.str().c_str(), textColor ); aTexture = SDL_CreateTextureFromSurface( renderer, temp ); aWidth = temp->w; aHeight = temp->h; SDL_FreeSurface(temp); // Render the isFiring text temp = TTF_RenderText_Solid( fontFire, fireValue.str().c_str(), textColor ); fTexture = SDL_CreateTextureFromSurface( renderer, temp ); fWidth = temp->w; fHeight = temp->h; SDL_FreeSurface(temp); // Render the missileVec.size() text temp = TTF_RenderText_Solid( fontAmmo, ammoValue.str().c_str(), textColor ); ammoTexture = SDL_CreateTextureFromSurface( renderer, temp ); ammoWidth = temp->w; ammoHeight = temp->h; SDL_FreeSurface(temp); } void Game::SetCannonAngle(float vecX, float vecY) { // "Snap" cannon angle to angle where mouse // cursor is located in order to track it double theAngle = atan2(vecY, vecX); // Pass radian angle to convert to degrees theAngle = ConvertDegrees(theAngle); // Convert degrees format from -180 to 180 // to 0 to 360 if( theAngle < 0 ) { theAngle = 360 - (-theAngle); } if(theAngle > MAX_ROTATION && theAngle < 90) { cannon->angle = MAX_ROTATION; } else if(theAngle < MIN_ROTATION && theAngle > 90) { cannon->angle = MIN_ROTATION; } else { cannon->angle = theAngle; } } double Game::SetMissileAngle(float vecX, float vecY) { // "Snap" missile angle to angle where mouse // cursor is located in order to track it double theAngle = atan2(vecY,vecX); // Pass radian angle to convert to degrees theAngle = ConvertDegrees(theAngle); // Convert degrees format from -180 to 180 // to 0 to 360 if( theAngle < 0 ) { theAngle = 360 - (-theAngle); } return theAngle; } double Game::ConvertDegrees(double radians) { // Convert the angle from radians to // degrees and return the value return RAD_TO_DEG(rad); } double Game::ConvertRadians(double degrees) { // Convert the angle from degrees to // radians and return the value return DEG_TO_RAD(deg); } int Game::GetSiloCount() { int siloCount = 0; // If the current silo is still alive, // the game is not over if(silo->state) { siloCount = 1; } return siloCount; } void Game::Render(float delta) { // Clear the renderer SDL_RenderClear(renderer); // Render the game objects cannon->Render(delta); ground->Render(delta); silo->Render(delta); // If there is a missile in the vector, // render it for( int i = 0; i < missileVec.size(); i++ ) { missileVec[i]->Render(delta); } /* Setting source rectangles and then rendering the x, y and angle fonts */ // For x SDL_Rect rect; rect.x = 20; rect.y = 20; rect.w = xWidth; rect.h = xHeight; SDL_RenderCopy(renderer, xTexture, 0, &rect); // For y rect.x = 20; rect.y = 40; rect.w = yWidth; rect.h = yHeight; SDL_RenderCopy(renderer, yTexture, 0, &rect); // For angle rect.x = 20; rect.y = 60; rect.w = aWidth; rect.h = aHeight; SDL_RenderCopy(renderer, aTexture, 0, &rect); // For isFired rect.x = 20; rect.y = 80; rect.w = fWidth; rect.h = fHeight; SDL_RenderCopy(renderer, fTexture, 0, &rect); // For isFired rect.x = 20; rect.y = 100; rect.w = ammoWidth; rect.h = ammoHeight; SDL_RenderCopy(renderer, ammoTexture, 0, &rect); // Present the renderer to display SDL_RenderPresent(renderer); } Missile.h #ifndef MISSILE_H_INCLUDED #define MISSILE_H_INCLUDED #include "Entity.h" #include <math.h> class Missile : public Entity { public: Missile(SDL_Renderer* renderer, float cX, float cY); ~Missile(); void Update(float delta); void Render(float delta); void Fire(); void Move(); // Starting and ending positions for missile float startX, startY, endX, endY; float directionX, directionY; float distance, speed; // The missile's angle double angle; // Flag to have missile destroyed // when certain conditions are met bool destroyNow; private: SDL_Texture* texture; // Texture for missile SDL_Point center; }; #endif // MISSILE_H_INCLUDED Missile.cpp #include "Missile.h" Missile::Missile(SDL_Renderer* renderer, float cX, float cY) : Entity(renderer) { // Create missile texture SDL_Surface* surface = IMG_Load("images/missile.png"); texture = SDL_CreateTextureFromSurface(renderer,surface); SDL_FreeSurface(surface); // Set angle variable default, // width, height angle = 0.0f; width = 34; height = 13; // Set missile offset for positioning relative to cannon float xOffset = 8; // Set starting x,y position x = cX + xOffset; y = cY; // Set the missile's starting x and y position // and speed startX = x; startY = y; speed = 150; // Set the missile's center for rotation center.x = ( width / 2 ); center.y = ( height / 2 ); // Set destruction flag to false destroyNow = false; } Missile::~Missile() { // Clean resources SDL_DestroyTexture(texture); } void Missile::Move() { // Determine the distance from the starting // position to the ending position distance = sqrt( pow(endX - startX, 2) + pow(endY - startY, 2)); // Determine direction of movement directionX = (endX - startX) / distance; directionY = (endY - startY) / distance; } void Missile::Update(float delta) { // Call move function Move(); // If the missile is moving, // update its position this->x += directionX * speed * delta; this->y += directionY * speed * delta; // If the missile goes BEYOND the // destination x and y (endX and endY), // set the missile's position to endX // and endY and stop movement if( sqrt( pow( this->x - startX, 2) + pow( this->y - startY, 2) ) >= distance ) { this->x = endX; this->y = endY; this->destroyNow = true; } } void Missile::Render(float delta) { // Render the missile SDL_Rect rect; rect.x = (int)(x + 0.5f); rect.y = (int)(y + 0.5f); rect.w = width; rect.h = height; // Render the missile at given angle SDL_RenderCopyEx(renderer,texture,0,&rect,angle,&center,SDL_FLIP_NONE); } I appreciate any feedback, guys. Thanks in advance. Also, let me know if you need more information about this post and I can provide it when I can.
  14. Dzuvan

    Wierd bug

    Hello, I'm having a rather strange bug. I'm making puzzle game. When the game starts(PlayState) for the first time pieces are indeed correctly placed, but after that sometimes they appear fine and most of the time only half of each piece is present ( I'm composing them out of 2 rectangles). The other parts appear at coordinates like this : Part2: X[1] : 842150923, Y[1]: 842150691. It happens even if I don' t use rand(). I'm using a state machine: PlayState can go to: - pause state PauseState can go to: - Resume - Main Menu stateMain MenuState can go to: - PlayState - Exit I'm following a book "SDL Game Development" by Shaun Mitchell (btw It's full of bugs). bool PlayState::onEnter() { int left_x = 600 + (rand() % static_cast<int>(750 - 600 + 1)); int left_y = 500 + (rand() % static_cast<int>(500 - 100 + 1)); Vec2 dimension = Vec2(100, 200); int right_x = left_x + 100; int right_y = left_y; Vec2 dimension_2 = Vec2(100, 200); SDL_Color color1 = { 255, 0, 0, 0 }; Piece* piece = new Piece(Vec2(left_x, left_y), Vec2(right_x, right_y), dimension, dimension_2, color1); // Piece 2 int i_left_x = 600 + (rand() % static_cast<int>(750 - 600 + 1)); int i_left_y = 500 + (rand() % static_cast<int>(500 - 100 + 1)); Vec2 dimension_i1 = Vec2(100, 100); int i_right_x = i_left_x; int i_right_y = i_left_y + 100; Vec2 dimension_i2 = Vec2(100, 100); SDL_Color color3 = { 0, 0, 255, 0 }; Piece* piece3 = new Piece(Vec2(i_left_x, i_left_y), Vec2(i_right_x, i_right_y), dimension_i1, dimension_i2, color3); // and so on until I have 7 pieces. } // ... void PlayState::update() { if (InputHandler::Instance()->isKeyDown(SDL_SCANCODE_ESCAPE)) { Game::Instance()->getStateMachine()->pushState(new PauseState()); } for (unsigned int i = 0; i < m_pieces.size(); i++){ m_pieces[i]->update(); } The issue occurs when I go from MainMenuState to PlayState after PauseState. I'll provide additional info if needed. Thanks in advance.
  15. Hi, I am writing a Windows multithreaded SDL 1.2 application, and am trying to fix a performance bug by process of elimination (graphics thread only wakes up once every 5 seconds for now). The bug is that when I move the mouse in circles, everything is fine for the first 50 seconds (smooth mouse movement and low CPU usage), and then the CPU usage spikes and the mouse starts to lag and skip rather than move smoothly. I am taking mouse input in the input thread as follows: while (SDL_WaitEvent(g_pEventData)) { ... SDL_Delay(10);//this was the recommendation i saw when researching perf issues } Windows Performance Analyzer tells me theres a large amount of CPU usage taken by KernelBase.dll!SleepEx which I THINK is called internally from SDL_WaitEvent in the loop above. Does anyone have an idea why the CPU usage suddenly spikes and performance lags after 50 seconds although I'm making the same circular mouse movements the whole time? Thanks.
  16. I have a simple openGL engine using SDL working. I'm not using any SDL_Image stuff, its all just openGL. I've made 2d tilemap levels with a .txt file before by reading in the characters and using a switch statement to assign them to various textures and using their position in the file to render them. This method works fine and produces no graphical glitches. Then I made a .tmx map in Tiled and used TmxParser to read the file into my program, and I'm able to render the map properly to the screen, but when I move up and down these black lines start to appear between the tiles. The map loads in fine at first, its only once I start moving the camera around that it happens, and its only when the camera moves up or down. I made a video to show exactly what I'm seeing, I see a lot of these type of issues when searching google but nothing that matches whats happening to me. I'm not even sure if this is a problem with the code or what it could be so I don't know of any code to include. This problem also happened to me when I was using Unity and importing a Tiled map with Tiled2Unity. In unity there were long horizontal line glitches on the tilemap, and now its happening to me again in c++, is this something to do with Tiled? Has anyone encountered this before or know a solution? Any help would be greatly appreciated, I feel stuck on this issue.
  17. I can't get SDL to make any rectangles on my Mac. The program I wrote worked completely fine on a Windows computer, but whenever I call the SDL_FillRect function on my Mac, nothing appears on the screen. I suspect this may be caused by a compilation issue. I'm using SDL through Frameworks. Inserted below is my terminal command and my code: g++ example.cpp -I/Library/Frameworks/SDL2.framework/Headers -F/Library/Frameworks -framework SDL2 #include <SDL2/SDL.h> #include <iostream> #include <stdio.h> const int SCREEN_WIDTH = 640; const int SCREEN_HEIGHT = 480; const int PLAYER_WIDTH = 20; const int PLAYER_HEIGHT = 20; SDL_Window* w = NULL; SDL_Surface* s = NULL; SDL_Renderer* r = NULL; SDL_Rect BG = {0,0,SCREEN_WIDTH,SCREEN_HEIGHT}; bool init() { if (SDL_Init(SDL_INIT_VIDEO) < 0) { printf("Couldn't initialize. error: %s\n", SDL_GetError() ); return false; } else { w = SDL_CreateWindow("test", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN); if(w == NULL) { printf("Couldn't make window. error:%s\n", SDL_GetError() ); return false; } else { s = SDL_GetWindowSurface(w); r = SDL_CreateRenderer(w,-1,SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC); SDL_SetRenderDrawColor(r,0,0,0,0); return true; } } } void close() { SDL_FreeSurface(s); SDL_DestroyWindow(w); SDL_DestroyRenderer(r); SDL_Quit(); } class Player { private: int x; int y; int xvel; int yvel; int acceleration; SDL_Rect collider; public: bool landed; Player() { x = 0; y = SCREEN_HEIGHT - PLAYER_HEIGHT; xvel = 0; yvel = 0; acceleration = -1; collider.x = x; collider.y = y; collider.w = PLAYER_WIDTH; collider.h = PLAYER_HEIGHT; landed = true; } int getx() { return x; } int gety() { return y; } void setx(int num) { x = num; } void sety(int num) { y = num; } void setyvel(int num) { yvel += num; } void setxvel(int num) { xvel += num; } void move() { x += xvel; if( (y + PLAYER_HEIGHT) > SCREEN_HEIGHT) { y = SCREEN_HEIGHT - PLAYER_HEIGHT; yvel = 0; landed = true; } else { if(landed != true) { //so sorry for the bad code, this was the only idea i had to debug "bouncing" of the player y += yvel; yvel = yvel - acceleration; } } collider.x = x; collider.y = y; } void render() { SDL_SetRenderDrawColor(r,255,255,255,255); SDL_RenderFillRect(r,&collider); SDL_SetRenderDrawColor(r,0,0,0,255); } }; int main(int argc, char *argv[]) { bool quit = false; SDL_Event e; //event for event polling Player p; int count = 0; if(init() == false) { printf("Init failed: %s\n", SDL_GetError()); } else { while(quit == false ) { while( SDL_PollEvent(&e) != 0) { if(e.type == SDL_QUIT) { quit = true; } if(e.type == SDL_KEYDOWN) { switch(e.key.keysym.sym) { case SDLK_LEFT: if(e.key.repeat == 0) { p.setxvel(-10); } break; case SDLK_RIGHT: if(e.key.repeat == 0) { p.setxvel(10); } break; case SDLK_UP: if(count < 5) { p.setyvel(-3); ++count; } p.landed = false; break; } } if(e.type == SDL_KEYUP && e.key.repeat == 0) { switch(e.key.keysym.sym) { case SDLK_LEFT: p.setxvel(10); break; case SDLK_RIGHT: p.setxvel(-10); break; case SDLK_UP: count = 0; break; } } } SDL_RenderClear(r); SDL_RenderFillRect(r,&BG); p.move(); p.render(); SDL_RenderPresent(r); } } close(); Please help me to get it working, I have no idea what's going on. I have SDL 2.0.7 and my Mac is OS X 10.10.3.
  18. Hello everyone, For learning purposes, I want to try to make a small graphical snake game in assembly. I've thought about where to start and which tools to use and personally I thought about using SDL and C to handle the keyboard input and the graphical output, but I would really like to know from other if there are better/easier ways to do this. Thanks
  19. I am trying to implement sprite clips, or rendering a portion of a sprite sheet onto the screen. For now, I am least trying to get one sprite to display on the screen. Controller support and adding the other sprites when changing the character direction will come later. Here is what I have so far. First, the class declaration: class World1 { public: //other stuff //screen resolution int window_width = 0; int window_height = 0; //handles player void renderPlayer(SDL_Renderer*&); //other stuff private: //player graphic and rectangle structs/variables/etc. SDL_Texture* pSpriteSheet = nullptr; SDL_Rect pSpriteClips[3]; SDL_Rect* pSprite; SDL_Rect pBase; SDL_RendererFlip sFlip = SDL_FLIP_NONE; //other stuff }; Then, the constructor: World1::World1(int SCREEN_WIDTH, int SCREEN_HEIGHT, SDL_Renderer*& renderer) { window_width = SCREEN_WIDTH; window_height = SCREEN_HEIGHT; *pSpriteSheet = IMG_LoadTexture(renderer, "male_base-test-anim.gif"); if (pSpriteSheet == nullptr) { cout << "Unable to load player Sprite sheet."; } //facing down sprite pSpriteClips[0].x = 14; pSpriteClips[0].y = 12; pSpriteClips[0].w = 145; pSpriteClips[0].h = 320; //more code... //player sprite pBase.x = 0; pBase.y = 0; pBase.w = pSpriteClips[0].w; pBase.h = pSpriteClips[0].h; } Then, the rendering void World1::renderPlayer(SDL_Renderer*& renderer) { //render SDL_RenderClear(renderer); //clears screen SDL_RenderCopyEx(renderer, pSpriteSheet, pSprite, &pBase, 0.0, NULL, sFlip); SDL_RenderPresent(renderer); //puts image on screen } So far, the program does not build and I obtain the following error: C:\Users\Kevin\Documents\Codeblocks\KnightQuest\worlds.cpp|12|error: invalid use of incomplete type 'SDL_Texture {aka struct SDL_Texture}'| Am I mistaken to assume that C++ will automatically assign a memory address to SDL_Rect* when I assign a value to it via the dereference operator? Or, perhaps there is another issue?
  20. Hi everyone, I'm Michele (not Michelle, I'm a guy ok? Just call me Mike), italian computer engineer with a strong passion about video game development. I decided to start a blog about making games from scratch using SDL and C. Why am I doing this? First of all, because I strongly believe that you don't need an engine to realize a MVP of your game. I will make games starting from a very basic idea to the first release, discussing the code and the choices. Name of the blog is "Making Games The Wrong Way", which provocatively means that we don't want to over-think the code structure and, above all, we don't want to do premature optimizations. Code will be plain, not beautiful for sure, but it will get our job done. I hope to see many followers from here. It is going to be a nice learning experience both for me and for you Here's the link: https://michelerullo.wordpress.com/ See you there!
  21. Does anyone have any experience (good or bad) using Docker for developing a game with SDL and/or C++? I can see it being useful for sharing the build environment, though games typically being compiled, GUI applications makes Docker seem like a bit more of a foreign concept.
  22. https://github.com/ingframin/CPongC/tree/master I have a bug that make my game crash outside of code::blcoks but run just fine in it. My guess is that I have an uninitialized pointer somewhere that is initialized by codeblocks when I run the code inside it. Can someone please try and let me know? I use codeblocks + GCC under Windows.
  23. Hi there, I posted this to be resolved in SDL forums so Im gonna left here the link to original discussion https://discourse.libsdl.org/t/sdl-gl-swapwindow-is-not-working-for-me/22863 I don't want duplicate posts but I want reach the most people I be able to. Tell me If you think this is bad habits so I won't do again in advance. Thanks!
  24. ¡ Aloha ! Summary A project ? 2 actually ! The main one is a real time simulation/strategy 2D game coded in C/C++/SDL where for the moment you control settlers on an island. The other project is a text based browser game and its features will be ported. Goals Have fun : Experiment, wild my creativity… Rapid prototyping : Gameplay first (Graphics credit : openclipart) Satisfy my needs as a player and make others happy Contribute to an open source game like Unknown Horizons or launch my own Features Hybrid gameplay : Automatic (God game) or manual (RTS) actions RPG-like attributes : HP, sex… Survival elements : Gather or fish renewable resources to eat and drink or… die !! Basic interaction : Minimal interface and keyboard shortcuts Rudimentary engine : Tile-based, path finding and super ultra turbo procedural generation Multilingual : English and French Screenshots In the first one, on Day 3, the camp has some water but no food yet. There's an explorer, 2 gatherers and one fishman. On Day 1314 the remaining settlers are fishing and gathering from spots that aren't depleted. Todo Gameplay, gameplay, gameplay GUI improvements Bigger maps Scrolling and zooming … Plenty of cool and interesting stuff !! References Series : Anno, The Settlers, City Building (Caesar, Pharaoh & Zeus) and Age of Empires Classics : SimCity, Civilization… and Populous of course !! Robinsonades
  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!