Thank you for the response,
I was clicking them because I figured that if they are giving me a prompt to delete, then there was probably some kind of error.
I have tried codesigning as directed and not codesigning. Both times I tried linking it into the terminal with gcc typing
g++ -o tempBuild LearnSDL.cpp -F/Library/Frameworks -framework SDL2 -framework SDL2_image
I am fairly inexperienced with terminal compiling, but I have enjoyed the speed. So I could not definitively say whether this is correct or not.
However, I get compiling issues with SDL2_image in XCode as well.
With this being the recieved codevomit from it:
Undefined symbols for architecture x86_64:
“loadTexture(std::__1::basic_string<char, std::__1::char_traits, std::__1::allocator >)”, referenced from:
loadMedia() in 04_key_presses.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I’ll include my code as well,
Again thanks.
#include
#include <SDL2/SDL.h>
#include <SDL2_image/SDL_image.h>
#include
using std::cout;
using std::cin;
using std::endl;
using std::string;
//Starts up SDL and creats window
bool init();
//Loads media
bool loadMedia();
//Frees media and shuts down SDL
void close();
//Loads individual image as texture
SDL_Texture* loadTexture(string path);
//The window we’ll be rendering to
SDL_Window* gWindow = NULL;
//The surface contained by the window
SDL_Renderer* gRenderer = NULL;
//Current displayed texture
SDL_Texture* gTexture = NULL;
// Screen dimension constants
const int SCREEN_WIDTH = 640; // 933 / 640
const int SCREEN_HEIGHT = 480; // 700 / 480
int main(){
//Start up SDL and create window
if(!init()) {
cout << “Failed to initialize\n”;
} else {
// Load media
if(!loadMedia()) {
cout << “Failed to load media!\n”;
} else {
//Main loop flag
bool quit = false;
//Event handle
SDL_Event e;
//While application is running
while(!quit) {
//Handle events on queue
while( SDL_PollEvent(&e) != 0) {
//User requests quit
if(e.type == SDL_QUIT) {
quit = true;
//User presse a key
}
//Clear screen
SDL_RenderClear(gRenderer);
//Render texture to screen
SDL_RenderCopy(gRenderer, gTexture, NULL, NULL);
//Update screen
SDL_RenderPresent(gRenderer);
}
}
}
}
//Free resources and close SDL
close();
return 0;
}
//Lesson Three
SDL_Texture* loadSurface(string path) {
//The final texture
SDL_Texture* newTexture = NULL;
//Load image at specified path
SDL_Surface* loadedSurface = IMG_Load(path.c_str());
if(loadedSurface == NULL) {
cout << "Unable to load image " << path.c_str() << "SDL Error: " << SDL_GetError() << endl;
} else {
//Convert texture from surface pixels
newTexture = SDL_CreateTextureFromSurface(gRenderer, loadedSurface);
if(newTexture == NULL) {
cout << "Unable to create texture from " << path.c_str() << "SDL Error: " << SDL_GetError() << endl;
}
//Get rid of old loaded surface
SDL_FreeSurface(loadedSurface);
}
return newTexture;
}
bool init(){
//Initialization flag
bool success = true;
//Initialize SDL
if(SDL_Init(SDL_INIT_VIDEO) < 0) {
cout << "SDL could not initialize! SDL_Error: " << SDL_GetError() << endl;
success = false;
//Create window
} else {
//Set texture fultering to linear
if(!SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, “1”)) {
cout << “Warning: Linear texture filtering not enabled!”;
}
//Create Window
gWindow = SDL_CreateWindow(“SDL Tutorial”, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN);
if(gWindow == NULL) {
cout << "Window could not be created! SDL_Error: " << SDL_GetError() << endl;
} else {
//Create renderer for window
gRenderer = SDL_CreateRenderer(gWindow, -1, SDL_RENDERER_ACCELERATED);
if (gRenderer == NULL) {
cout << "Renderer could not be created! SDL Error: " << SDL_GetError() << endl;
success = false;
} else {
//Initialize renderer color
SDL_SetRenderDrawColor(gRenderer, 0xff, 0xff, 0xff, 0xff);
//Initialize PNG loading
int imgFlags = IMG_INIT_PNG;
if(!(IMG_Init(imgFlags) & imgFlags)) {
cout << "SDL_image could not initialize! SDL_image Error: " << IMG_GetError() << endl;
success = false;
}
}
}
}
return success;
}
bool loadMedia(){
//Loading success flag
bool success = true;
//Load PNG surface
gTexture = loadTexture(“texture.png”);
if(gTexture == NULL) {
cout << “Failed to load PNG image!\n”;
success = false;
}
return success;
}
void close() {
//Free loaded image
SDL_DestroyTexture(gTexture);
gTexture = NULL;
//Destroy windo
SDL_DestroyRenderer(gRenderer);
SDL_DestroyWindow(gWindow);
gWindow = NULL;
gRenderer = NULL;
//Quit SDL subsystems
SDL_Quit();
}