SDL not loading texture

Can someone plz tell me whats wrong with this code. its running just fine, there are no errors. but the thing is its not loading textures. thanks.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#include <iostream>
#include <string>
#include <SDL.h>
#include <SDL_image.h>
#include <vector>
#include <stdio.h>
using namespace std;
SDL_Window *window = NULL;
SDL_Surface* screen = NULL;
SDL_Texture* loadtexture = NULL;
SDL_Texture* texture = NULL;
SDL_Renderer* render = NULL;

bool init() {
	bool success = true;
	if (SDL_Init(SDL_INIT_VIDEO < 0)) {
		cout << "erro sdl init" << SDL_GetError() << endl;
		success = false;
	}
	else {
		window = SDL_CreateWindow("image.jpg tutorial", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 1500,800, SDL_WINDOW_RESIZABLE);
		if (window == NULL) { cerr << "error creating window" << SDL_GetError() << endl; success = false; }

		else {
			render = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
			if (render == NULL) { cerr << "error in rendering" << endl; }
			else {
				SDL_SetRenderDrawColor(render, 0xFF, 0xFF, 0xFF, 0xFF);
				int imgFlags = IMG_INIT_JPG;
				if (!(IMG_Init(imgFlags) & imgFlags)){
					printf("SDL_image could not initialize! SDL_image Error: %s\n", IMG_GetError());
					success = false;
				}
			}
		}
	}
	return success;
}
SDL_Texture *load_texture(string path) {
	SDL_Texture *newtexture = NULL;
	SDL_Surface* image = NULL;
	image = IMG_Load(path.c_str());
	if (image == NULL) {
		cerr << "error" << endl;
	}
	newtexture = SDL_CreateTextureFromSurface(render, image);
	if (newtexture == NULL) {
		cerr << "error" << endl;
	}
	return newtexture;
}
SDL_Surface *loadimage(string path) {
	SDL_Surface* optimizedsurface = NULL;
	SDL_Surface* loadedsurface = NULL;
	loadedsurface= IMG_Load(path.c_str());
	if (loadedsurface == NULL) { cerr << "error loading image" << endl; }
	else {
		optimizedsurface = SDL_ConvertSurface(loadedsurface, screen->format, 0);
		if (optimizedsurface == NULL) { cerr << "error" << endl; }
		SDL_FreeSurface(loadedsurface);
	}
	return optimizedsurface;
}
bool loadMedia(){
	bool success = true;
	texture = load_texture("22.jpg");
	if (texture == NULL){
		printf("Failed to load texture image!\n");
		success = false;
	}
	return success;
}
void close()
{
	//Free loaded image
	SDL_DestroyTexture(texture);
	texture = NULL;

	//Destroy window    
	SDL_DestroyRenderer(render);
	SDL_DestroyWindow(window);
	window = NULL;
	window = NULL;

	//Quit SDL subsystems
	IMG_Quit();
	SDL_Quit();
}

int main(int argc, char** argv) {
	init();
	
	SDL_Event event;
	bool isrunning = true;
	while (isrunning){
		while (SDL_PollEvent(&event)){
			if (event.type == SDL_QUIT) {
				isrunning = false;
				break;
			}
			else if (event.type == SDL_KEYDOWN) {
				if (event.key.keysym.sym == SDLK_UP) {
				}
			}
		}
		SDL_RenderClear(render);
		SDL_RenderCopy(render, texture, NULL, NULL);
		SDL_RenderPresent(render);
		SDL_SetRenderTarget(render, NULL);
	}
	SDL_Quit();
	return 0;
}
what path in main takes you to code that loads the textures?
You never call loadMedia().
Yup, just like Helios said, you just declared load media but never actually called it within main
Topic archived. No new replies allowed.