Compare commits
No commits in common. "9d725d0b2f6f889a4f26af96a9b830bf9fef125a" and "868922c68eb7d2dab6e412879517893ed5da7a2e" have entirely different histories.
9d725d0b2f
...
868922c68e
2
Makefile
2
Makefile
@ -6,7 +6,7 @@ CC = g++
|
|||||||
|
|
||||||
#COMPILER_FLAGS specifies the additional compilation options we're using
|
#COMPILER_FLAGS specifies the additional compilation options we're using
|
||||||
# -w suppresses all warnings
|
# -w suppresses all warnings
|
||||||
COMPILER_FLAGS = -Wall -Wpedantic
|
COMPILER_FLAGS = -w
|
||||||
|
|
||||||
#LINKER_FLAGS specifies the libraries we're linking against
|
#LINKER_FLAGS specifies the libraries we're linking against
|
||||||
LINKER_FLAGS = -lSDL2 -lSDL2_image
|
LINKER_FLAGS = -lSDL2 -lSDL2_image
|
||||||
|
99
main.cpp
99
main.cpp
@ -21,60 +21,6 @@ enum KeyPressSurfaces
|
|||||||
KEY_PRESS_SURFACE_TOTAL
|
KEY_PRESS_SURFACE_TOTAL
|
||||||
};
|
};
|
||||||
|
|
||||||
SDL_Rect get_srcrect(char key) {
|
|
||||||
SDL_Rect srcrect;
|
|
||||||
srcrect.x = (key % 16) * 70;
|
|
||||||
srcrect.y = (key / 16) * 80;
|
|
||||||
|
|
||||||
srcrect.w = 80;
|
|
||||||
srcrect.h = 80;
|
|
||||||
|
|
||||||
return srcrect;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void render_char(char key, int row, int col, SDL_Renderer* renderer, SDL_Texture* font) {
|
|
||||||
SDL_Rect dstrect;
|
|
||||||
|
|
||||||
dstrect.x = col;
|
|
||||||
dstrect.y = row;
|
|
||||||
dstrect.w = 80;
|
|
||||||
dstrect.h = 80;
|
|
||||||
|
|
||||||
SDL_Rect srcrect = get_srcrect(key);
|
|
||||||
SDL_RenderCopy(renderer, font, &srcrect, &dstrect);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Draw(char keyPressed, SDL_Renderer* renderer, SDL_Texture* fontTexture) {
|
|
||||||
SDL_Rect srcrect;
|
|
||||||
SDL_Rect dstrect;
|
|
||||||
|
|
||||||
if (keyPressed > 0) {
|
|
||||||
srcrect.x = (keyPressed % 16) * 70;
|
|
||||||
srcrect.y = (keyPressed / 16) * 80;
|
|
||||||
} else {
|
|
||||||
srcrect.x = 0;
|
|
||||||
srcrect.y = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
srcrect.w = 80;
|
|
||||||
srcrect.h = 80;
|
|
||||||
|
|
||||||
dstrect.x = SCREEN_WIDTH/2 - 40;
|
|
||||||
dstrect.y = SCREEN_HEIGHT/2 - 40;
|
|
||||||
dstrect.w = 100;
|
|
||||||
dstrect.h = 100;
|
|
||||||
|
|
||||||
// SDL_BlitSurface(imageSurface, &srcrect, screenSurface, &dstrect);
|
|
||||||
|
|
||||||
//Update the surface
|
|
||||||
// SDL_UpdateWindowSurface( window );
|
|
||||||
|
|
||||||
|
|
||||||
SDL_RenderCopy(renderer, fontTexture, &srcrect, &dstrect);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
SDL_Window* window = NULL;
|
SDL_Window* window = NULL;
|
||||||
|
|
||||||
@ -94,11 +40,12 @@ int main(int argc, char *argv[]) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_Renderer* renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
|
SDL_Renderer* renderer =
|
||||||
|
SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
|
||||||
SDL_SetRenderDrawColor(renderer, 130, 163, 255, 1);
|
SDL_SetRenderDrawColor(renderer, 130, 163, 255, 1);
|
||||||
|
|
||||||
|
|
||||||
SDL_Surface* fontSurface = IMG_Load("output.png");
|
SDL_Surface* fontSurface = IMG_Load("font.png");
|
||||||
if (fontSurface == NULL) {
|
if (fontSurface == NULL) {
|
||||||
cout << "Could not find spritesheet" << endl;
|
cout << "Could not find spritesheet" << endl;
|
||||||
return 1;
|
return 1;
|
||||||
@ -111,12 +58,10 @@ int main(int argc, char *argv[]) {
|
|||||||
//Fill the surface white
|
//Fill the surface white
|
||||||
// auto rgbMap = SDL_MapRGB( screenSurface->format, 0x82, 0xA3, 0xFF);
|
// auto rgbMap = SDL_MapRGB( screenSurface->format, 0x82, 0xA3, 0xFF);
|
||||||
|
|
||||||
|
int test = 0;
|
||||||
SDL_Event e;
|
SDL_Event e;
|
||||||
bool quit = false;
|
bool quit = false;
|
||||||
int keyPressed = -1;
|
int keyPressed = -1;
|
||||||
int rowCurr = 0;
|
|
||||||
int colCurr = 0;
|
|
||||||
string text = "Some text";
|
|
||||||
while (quit == false) {
|
while (quit == false) {
|
||||||
while (SDL_PollEvent( &e)) {
|
while (SDL_PollEvent( &e)) {
|
||||||
if (e.type == SDL_QUIT) {
|
if (e.type == SDL_QUIT) {
|
||||||
@ -132,14 +77,38 @@ int main(int argc, char *argv[]) {
|
|||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// SDL_FillRect( screenSurface, NULL, rgbMap);
|
// SDL_FillRect( screenSurface, NULL, rgbMap);
|
||||||
SDL_RenderClear(renderer);
|
|
||||||
SDL_SetTextureColorMod(fontTexture, 0xFF, 0, 0);
|
SDL_Rect srcrect;
|
||||||
for (int i = 0; i < 10; i++) {
|
SDL_Rect dstrect;
|
||||||
render_char(text[i], rowCurr, colCurr++ * 50, renderer, fontTexture);
|
|
||||||
|
|
||||||
|
if (keyPressed > 0) {
|
||||||
|
srcrect.x = (keyPressed % 16) * 70;
|
||||||
|
srcrect.y = (keyPressed / 16) * 80;
|
||||||
|
} else {
|
||||||
|
srcrect.x = 0;
|
||||||
|
srcrect.y = 0;
|
||||||
}
|
}
|
||||||
colCurr = 0;
|
|
||||||
// Draw(keyPressed, renderer, fontTexture);
|
srcrect.w = 80;
|
||||||
|
srcrect.h = 80;
|
||||||
|
|
||||||
|
dstrect.x = SCREEN_WIDTH/2 - 40;
|
||||||
|
dstrect.y = SCREEN_HEIGHT/2 - 40;
|
||||||
|
dstrect.w = 100;
|
||||||
|
dstrect.h = 100;
|
||||||
|
|
||||||
|
// SDL_BlitSurface(imageSurface, &srcrect, screenSurface, &dstrect);
|
||||||
|
|
||||||
|
//Update the surface
|
||||||
|
// SDL_UpdateWindowSurface( window );
|
||||||
|
|
||||||
|
SDL_RenderClear(renderer);
|
||||||
|
|
||||||
|
SDL_RenderCopy(renderer, fontTexture, &srcrect, &dstrect);
|
||||||
|
|
||||||
SDL_RenderPresent(renderer);
|
SDL_RenderPresent(renderer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BIN
output.png
BIN
output.png
Binary file not shown.
Before Width: | Height: | Size: 4.2 KiB |
Loading…
x
Reference in New Issue
Block a user