FAQ Database Discussion Community


C++ SDL texture Error Microsoft Visual Studio 2013

c++,image,textures,sdl,sdl-2
I'm trying to run this code but it keeps giving me an error. I copyed SDL2_image.lib in the debug folder but in vain. I'm at the beggining of programming so please be patient. Errors: Error 1 error C3861: 'IMG_LoadTexture': identifier not found Error 2 IntelliSense: identifier "IMG_LoadTexture" is undefined #include<SDL/SDL.h>...

Using SDL2 with CMake

c++,cmake,sdl-2
I'm trying to use CLion to create a SDL2 project. The problem is that the SDL headers can't be found when using #include's. My CMakeLists.txt file: cmake_minimum_required(VERSION 2.8.4) project(ChickenShooter) set(SDL2_INCLUDE_DIR C:/SDL/SDL2-2.0.3/include) set(SDL2_LIBRARY C:/SDL/SDL2-2.0.3/lib/x64) include_directories(${SDL2_INCLUDE_DIR}) set(SOURCE_FILES main.cpp) add_executable(ChickenShooter ${SOURCE_FILES}) target_link_libraries(ChickenShooter ${SDL2_LIBRARY}) My test main.cpp: #include <iostream> #include "SDL.h" /* This one...

Problems grabbing file names using SDL_strdup and similar

c,malloc,sdl-2,opendir,strdup
I'm trying to create a program with SDL2. In a certain part of the code, I'm writing functions to grab names of all present files in a given directory path (and keep them in memory) so that, in another function, I can check if a specified file was present the...

Receiving undefined references to various Windows libraries when compiling with SDL 2 and -static?

c++,sdl,sdl-2
I'm working on a modification of the Wolfenstein 3D engine in SDL2 (using Wolf4SDL as a base) and I've run into a problem - when using -static in the linker options, I get a large variety of undefined references to various things. Here's my build log to show what I...

8 Bit Surfaces in SDL 2

sdl,sdl-2,color-depth
Originally in SDL, the following code could be used to setup a surface: SDL_Surface *screen = SDL_SetVideoMode(800, 600, 8, 0); Now, in SDL2 the following code must be used: SDL_Window *window = SDL_CreateWindow("Title", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 800, 600, 0); SDL_Surface *surface = SDL_GetWindowSurface(window); My problem is that SDL_CreateWindow offers no way...

undefined reference to `WinMain' : When using Cygwin, SDL2 and Netbeans

c++,netbeans,linker,cygwin,sdl-2
any help here would be appreciated. Ive really racked my brains at this, sooo. I have installed cygwin, and Netbeans and have been successfully deving, compiling and running a small SDL-1.2 windows game with no problems. The problem has come now that I have installed SDL2 and am trying to...

OpenGL only renders the first frame then blackness

c++,opengl,rendering,sdl,sdl-2
I have created a deferred renderer using OpenGL that seems to be working great for exactly one frame. Then it renders just blackness. For the code below I have flattened the architecture of the render quite a lot, but I think everything relevant is included. If more context is needed...

Drawing a circle in SDL 2, but each circle uses CPU a lot

c++,visual-c++,sdl,sdl-2
i wrote a code that draw filled circle, but it uses CPU a lot. The thing is i draw pixel by pixel, first outter circle with radius n the second circle with radius n-1 and so on while n is not equal to 0. I'm drawing 4 pixel in e...

SDL2 + OpenGL + SDL2_TTF: Displaying text

c++,opengl,rendering,sdl-2,sdl-ttf
I'm having trouble getting a TTF font to draw in OpenGL plus SDL2.0. I remember that before SDL version 2 I had no problems, but there seems to be a lack of documentation on the subject, perhaps due to the new standard. I have included the code below to show...

How to get OpenGL-ES working on Raspberry Pi with SDL2?

raspberry-pi,opengl-es-2.0,sdl-2
I am trying to get OpenGL-ES working on a Raspberry Pi, but so far no luck. I compiled SDL 2.0.3 from source with this, as the version in Rasbian is missing Raspberry Pi support: ./configure --prefix=/home/pi/run/SDL2-2.0.3/ \ --disable-video-x11 \ --disable-pulseaudio \ --disable-esd \ --disable-video-opengl The code below should create a...

SDL2 rendering text issues

c++,sdl-2
I have a menu where there is a lot of text being rendered that can change in size/color/position, so I made two functions in my menu class...: void drawText(string text,int text_size,int x,int y, Uint8 r,Uint8 g,Uint8 b); void updateTexts(); The updateTexts() function sits in the game loop and contains many...

CMAKE, SDL2 and OPENGL: Program binary is too big

c++,cmake,shared-libraries,static-libraries,sdl-2
I use CMAKE to link a program to SDL2, OpenGL and I compile tinyxml2 as a shared library. The resulting program binary is 1.4 mb but there's barely 1k lines of code in the program. I suspect some library is statically linked. I'd prefer they are linked as shared libraries....

SDL2 - Adding a surface to a surface, texture to texture or something in between

c++,sdl,sdl-2
Basically, I want to have one texture which contains both text and an image. How would I go about doing that? I've been Google-ing around, but I can't seem to find a way to combine surfaces with other surfaces, textures with other textures, nor surfaces with textures. EDIT: So, I'm...

Debug Assertion Failed! Expression: __BLOCK_TYPE_IS_VALID(pHead->nBlockUse) when deleting

c++,debugging,runtime-error,sdl,sdl-2
My friend and I were updating our Tetris like project to be more dynamic (allow any size shapes instead of only 4 tiled shapes), upgrading from arrays to vectors. Everything worked fine before but now we get the error from the title whenever a shape reaches the floor. This is...

SDL UpdateWindowSurface() returns -1 if called from a class (in separate file)

c++,class,window,header-files,sdl-2
Today I started a C++/SDL2 Snake clone, and I've been looking for ways to make my code neater, -particularly with classes. I tried to put all the SDL code used for the window/display in a class. When I run the code, the window closes instantly. From the error tests I...

SDL2 OpenGL 4.2 context with 0 color bits and 0 depth bits

c++,opengl,graphics,sdl-2,glew
I've been trying to start a new SDL + GLEW + OpenGL project, and the setup has been difficult (MinGW-w64-32 on Windows 8 64-bit with an Intel i7-4700MQ CPU and NVidia GTX 745M GPU). If I set the GL attributes to be used for context creation to use OpenGL version...

Mysterious “multiple definition” error [closed]

c++,sdl,sdl-2
https://gist.github.com/protectivetoast83/25301772cbc6f13e6e07 I moved #include "time.h" from line 2 of objColPhys.cpp (which is inherited from objects.h) to line 3 of objects.h time.h is not included anywhere else in the project, but now I am getting a multiple definition error on line 9 of time.h In function `Z7runTimev': multiple definition of `runTime()'...

Loading images with C++/SDL2 - “unhandled exception”, “access violation reading location”

c++,exception,visual-studio-2013,access-violation,sdl-2
I was studying someone else's Pong code for an earlier version of SDL, and I'm trying to get it running with SDL2. Below is an excerpt from my code, which only loads the images. When this code is run, I get a window popping up telling me this: Unhandled exception...

SDL code should greyscale but just loads the image normally

image-processing,sdl-2,grayscale
The code below should load an image, then grey scale the image in a window. Instead it just loads the image. I've used printf("hello") in the loop starting with "for (int y = 0; y < image->h; y++)" however the console doesn't show "hello", unless I removed SDL_Delay(20000) which makes...

SDL: how to get the mouse motion while the left mouse button is down using case statement

c++,switch-statement,mouseevent,sdl-2
I am currently working with SDL2 and am fairly new to it. I am trying to use case statments to get the mouse motion coordinates only while the left mouse button is pressed down. In the end, I need to be able to click on a object and find how...

Error setting attribute of an sdl2 Entity

python,sdl-2,pysdl2
I am using the pysdl2 library. self.velocity will print, but self.forward_tick with throw a key error. What is causing only part of the self attributes from being assigned. I am thinking it has something to do with the inheritance. class Robot(sdl2.ext.Entity): def __init__(self, world, sprite, posx=0, posy=0): self.sprite = sprite...

SDL won't display image in window when called from class

c++,image,class,header-files,sdl-2
I'm trying to organize my code a bit more, so I tried putting the SDL2 code used for displaying windows/images into a class. The window opens, the code runs successfully, and the image seems to be loading fine, -but the image will not appear when the code is arranged in...

Getting a EXC_BAD_ACCESS on glGenTextures

c++,opengl,sdl,sdl-2
Trying out a bit of C++ and OpenGL with SDL2 & SDL2_image, based off of http://open.gl I'm getting the subject error once it reaches the glGenTextures call. Most of my searches have mentioned not creating a gl context yet. I have, and use multiple gl calls prior to this one...

SDL_Image IMG_Load() says the file format is not supported

linux,image,ubuntu,sdl,sdl-2
I am following a tutorial and I think I have done everything right, but it continues saying "Unsupported image format". The code: SDL_Texture *LoadTexture(string filePath, SDL_Renderer *renderTarget) { SDL_Texture *texture = nullptr; SDL_Surface *surface = IMG_Load(filePath.c_str()); if (surface == NULL) { cout << "Error: " << IMG_GetError() << endl; }...

Set the pixel format AND create texture from surface in SDL

c++,pixel,sdl-2,surface,pixelformat
I am currently trying some things using pixel manipulation and I would like to set the pixel format of a SDL_Surface. The problem here is that I am loading up an image with the SDL_image.h. So I have to create a texture from a surface like this: surface = IMG_Load(filePath);...

How do I use an indexed PNG image as a texture for SDL2/OpenGL

c++,opengl,sdl,sdl-2,libpng
My code for loading images seems to work for 24 and 32bit images. I load an image in using SDL2_image: // Snip cruft above if((surface = IMG_Load(filename.c_str())) == NULL) { error = "Unable to load file: " + filename; throw error.c_str(); } // get the number of channels in the...

SDL 2.0 TextInputEvent UTF8 data storage

c++,unicode,utf-8,sdl,sdl-2
I want to render text. My problem is that I don't know how to use the char[32] field text of SDL's SDL_TextInputEvent. According to the docs it's a "null-terminated input text in UTF-8 encoding". As far as I understand UTF8 takes 8 bits and a char has more or less...

Is it possible to run a game written in Haskell in the browser? (Through GHCJS maybe?)

haskell,sdl-2,helm,ghcjs
I wonder if it is currently possible to write games in Haskell with Helm or any other engine that run on the browser through GHCJS?

How create Surface from memory? [SDL]

sdl-2
I found interesting function https://wiki.libsdl.org/SDL_RWFromMem How I can using it? I need simple program. Read image from disc, creating in memory Surface, and storing it in file. Next I can read it from file and create Texture....

SDL2 and C++11, main not entered

c++11,sdl-2
The gist of the problem is that I've got a main function that initializes SDL, sets up OpenGL attributes (for the context creation) gets a context up (a class that represents an OpenGL rendering context (with window and context together)), reports some info on the OpenGL version and other basic...

SDL2 resize buggy in Fedora 21 but fine in windows

c++,linux,resize,fedora,sdl-2
I'm building a cross platform C++ OpenGL game using SDL2 as the window manager, and I recently discovered that resizing the window has some strange issues in linux. Other windows like Terminal work fine for resizing. It may also be worth noting that Fedora is in a VMware Virtual Machine....

Cannot find SDL.h when

c++,linux,sdl-2,sdl-ttf
I'm trying to use TTF for the games I want to develop, I'm fairly new to this so I would thank you a lot if you could answer a question for me: After I followed the installation instructions correctly (at least I hope i did) I tried to compile my...

Rendering fonts and text with SDL2 efficiently

fonts,sdl,sdl-2,true-type-fonts,sdl-ttf
Saw this post here about using SDL_ttf to render text in a game. However that approach requires calling SDL_CreateTextureFromSurface(), along with the SDL_FreeSurface() and SDL_DestroyTexture() every single frame. Is creating textures (and probably subsequently having to send them to the GPU) every frame something that can significally impact my performance?...

How do I check for SDL2_ttf in CMakeLists.txt?

cmake,sdl-2,sdl-ttf
I am currently writing an SDL2 program with the SDL2-ttf library and wanted to add a check for it in CMakeLists.txt. How do I do that? I am using CMake 3.1....

How to use CMake's pkg_search_module() when compiling under Windows?

c++,windows,visual-studio-2013,cmake,sdl-2
I'm programming a game which uses SDL2 and CMake. In order to link and include SDL2 I use the following CMake code: include(FindPkgConfig) pkg_search_module(SDL2 REQUIRED sdl2) target_link_libraries(MYLIB SDL2) When compiling under Linux (Fedora) this works perfectly. But what about Windows? There I don't have standard system locations for DLL/a files...

Integer index in SDL_JoystickName in C++

c++,sdl-2
Look at the simple code below: int main() { int a; a = SDL_Init(SDL_INIT_JOYSTICK); a = SDL_NumJoysticks(); for (int i=0; i<a; i++) cout << SDL_JoystickName(i); return 0; } I'm using SDL library, It seems there is nothing wrong with the code, I'm trying to get names of connected joysticks but...

Weird segfaults when calling TTF_OpenFont

c++,linux,segmentation-fault,codeblocks,sdl-2
I ported a game I am making from SDL 1.2 to SDL2. After porting the game and getting it to compile properly I get a segfault when I call TTF_OpenFont here: bool cargararchivos(SDL_Texture* &background,SDL_Texture* &player,TTF_Font* &font,SDL_Texture* &bullet,Config* placlips,SDL_Renderer* renderer) { string playerss; //Open the font font = TTF_OpenFont( "lazy.ttf", 28...

SDL2: How to properly toggle fullscreen?

sdl,fullscreen,sdl-2
I have problems deactivating fullscreen mode with my program. Entering fullscreen happens correctly, but trying to go back to windowed mode doesn't work, the only effect is that the cursor gets shown again. Here's the MCVE/SSCCE that reproduces the issue for me: void ToggleFullscreen(SDL_Window* Window) { Uint32 FullscreenFlag = SDL_WINDOW_FULLSCREEN;...

SDL2 errors what am I doing Wrong

c++,sdl-2
It was working before I tried to load my image. This is the error I get: Error 1 error LNK2005: "struct SDL_Window * m_pWindow" ([email protected]@[email protected]@A) already defined in Game.obj C:\Users\Joseph\Desktop\DuckGotti\DuckGotti\maine.obj Error 2 error LNK2005: "struct SDL_Renderer * m_pRenderer" ([email protected]@[email protected]@A) already defined in Game.obj C:\Users\Joseph\Desktop\DuckGotti\DuckGotti\maine.obj Error 3 error LNK2005: "struct SDL_Texture...

Problems displaying image in C++ with SDL

c++,sdl,sdl-2
Code here: https://gist.github.com/protectivetoast83/25301772cbc6f13e6e07 images of problem The program should be displaying a single gray rectangle at coordinates 32, 32 on the window however it was also displaying a second one at coordinates 0,0. I added a cout statement on line 60 of gameWorld.cpp and the program started working correctly. The...

Drawing 2D stuff with SDL_Renderer and OpenGL stuff with SDL_GLContext

c++,opengl,rendering,sdl,sdl-2
I have been learning about SDL 2D programming for a while and now I wanted to create a program using SDL and OpenGL combined. I set it up like this: SDL_Init(SDL_INIT_VIDEO); window = SDL_CreateWindow("SDL and OpenGL", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, width, height, SDL_WINDOW_OPENGL); context = SDL_GL_CreateContext(window); The program is for now just...

How do I get a “list” of ALL the events in real time in SDL 2.0?

c++,pygame,sdl,sdl-2
I come from Pygame, and there I had pygame.event.get(), which returned a list of all events (So, once I had that list of events inside the mainloop, I could check for multiple keypresses or whatever in real-time, since ALL possible events were available). Now here's my code: #include "init.h" #include...

SDL_Keycodes are too big for storage

c++,segmentation-fault,sdl-2,signed-integer
While searching up methods of detecting multiple keys at once in SDL 2, I came across this piece of code for SDL 1.x: //author: Rob Loach // Global key buffer bool keys[256]; while(SDL_PollEvent(&mainEvent)) { if(mainEvent.type == SDL_KEYDOWN) { keys[mainEvent.key.keysym.sym] = true; } else if(mainEvent.type == SDL_KEYUP) { keys[mainEvent.key.keysym.sym] = false;...

Skip fragment of code C++ SDL2

c++,sdl-2
I'm writing a function in C++ with the SDL2 library, and I'm stuck with a small problem. The function deals with everything related to the graphics. I want to use it once to create the window, surface and so on ( graphics(0,0) ), and that everytime I use it after...