Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SDL.h>
- #include <stdio.h>
- #include<iostream>
- #include<windows.h>
- #include<string>
- #include<SDL_image.h>
- #define SCREEN_WIDTH 1280
- #define SCREEN_HEIGHT 720
- // SDL_Window* g_windows = NULL;
- // SDL_Surface* g_screenSurface=NULL;
- // SDL_Surface* g_background= NULL;
- // load anh len man hinh window
- int main(int argc, char * agrv[]){
- // variable declare
- SDL_Renderer * renderer =NULL;
- SDL_Surface * tmp_surface= NULL;
- SDL_Texture * texture=NULL;
- bool is_running = true;
- SDL_Window * window =NULL;
- if ( SDL_Init(SDL_INIT_EVERYTHING)<0){
- std::cout<<"Could not intialize SDL2"<<std::endl;
- return 1;
- }
- else {
- window =SDL_CreateWindow("Tungggg", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 400, 400, SDL_WINDOW_SHOWN);
- }
- renderer=SDL_CreateRenderer(window, -1,0);
- tmp_surface= IMG_Load("test.png");
- if (tmp_surface!=NULL){
- // get the information of the picture which was load into the surface
- std::cout<<"width and height is "<<tmp_surface->w<<" "<<tmp_surface->h<<std::endl;
- }
- texture= SDL_CreateTextureFromSurface(renderer,tmp_surface);
- SDL_FreeSurface ( tmp_surface);
- SDL_SetRenderDrawColor(renderer,212,175,55,255);
- SDL_RenderClear(renderer);
- SDL_RenderCopy(renderer, texture, NULL,NULL);
- SDL_RenderPresent(renderer);
- while ( is_running ){
- // SDL_RenderClear(renderer);
- SDL_Event event;
- while ( SDL_PollEvent(&event)){
- switch (event.type){
- case SDL_QUIT:{
- is_running=false;
- break;
- }
- }
- if (event.button.button== SDL_BUTTON_RIGHT){
- std::cout<<"right mouse is pressed"<<std::endl;
- }
- const Uint8* state = SDL_GetKeyboardState(NULL);
- if (state[SDL_SCANCODE_0]){
- std::cout<<"0 is pressed"<<std::endl;
- }
- if ( state[SDL_SCANCODE_0] && state[SDL_SCANCODE_1] && state[SDL_SCANCODE_2]){
- std::cout<<"1 and 2 is pressed"<<std::endl;
- }
- }
- // SDL_RenderCopy(renderer,texture,NULL,NULL);
- // SDL_RenderPresent(renderer);
- }
- SDL_DestroyWindow(window);
- SDL_Quit();
- return 0;
- }
Add Comment
Please, Sign In to add comment