#include "SDL.h"
#include <SDL.h>
#include <EGL/egl.h>
#include<vector>
#include "SDL/SDL.h"
#include "SDL/SDL_image.h"
#include "SDL/SDL_ttf.h"
#include <string>
#include <sstream>
#include <GLES/gl.h>
#include<string>
#include "SDL/SDL_image.h"
#include <SDL2/SDL.h>
struct kulka
{
int a;
int b;
} ball={0, 0} , wall= {1 , 1} , speed= {3, 4}, quad;
TTF_Font *font = NULL;
SDL_Window *win = NULL;
SDL_Renderer *renderer = NULL;
SDL_Color textColor = { 0xF0, 0xFF, 0xF0 };
SDL_Texture *bitmapTex = NULL;
SDL_Surface *startStop = NULL;
SDL_Surface *surface;
SDL_Surface *surface2;
SDL_Surface * kursor = NULL;
SDL_Surface * przycisk = NULL;
SDL_Rect przyciskDane;
SDL_Rect przyciskCel;
SDL_Rect rect, darea;
SDL_Rect kursorDane;
SDL_Surface *bitmapSurface = NULL;
SDL_Event event;
//int a=100, b=100;
/* -----------
|
|
*/
void drawtriangle (SDL_Renderer *renderer)
{
int a;
przyciskDane.w = 200;
przyciskDane.h = 50;
przyciskCel.x = 300;
przyciskCel.y = 240;
SDL_SetRenderDrawColor(renderer, 255, 255, 0, SDL_ALPHA_OPAQUE);
SDL_RenderDrawLine(renderer, 600, 200, 300, 240);
SDL_RenderDrawLine(renderer, 300, 240, 340, 240);
SDL_RenderDrawLine(renderer, 340, 240, 320, 200);
}
void line (SDL_Renderer *renderer)
{
// kursorDane.y ;
SDL_SetRenderDrawColor(renderer, 255, 0, 0, SDL_ALPHA_OPAQUE);
SDL_RenderDrawLine(renderer, kursorDane.x, kursorDane.y , kursorDane.x +100, kursorDane.y +100);
}
void point (SDL_Renderer *renderer)
{
// SDL_Rect rect, darea;
// kursorDane.y ;
SDL_SetRenderDrawColor(renderer, 255, 0, 0, SDL_ALPHA_OPAQUE);
SDL_RenderDrawLine(renderer, ball.a, ball.b, ball.a+50, ball.b+50);
SDL_RenderDrawLine(renderer, ball.a+50, ball.b, ball.a+50, ball.b+50);
// SDL_RenderDrawLine(renderer, a, b, a+50, b+50);
SDL_RenderDrawLine(renderer, ball.a+50, ball.b , ball.a, ball.b);
ball.a+=speed.a;
ball.b+=speed.b;
if (ball.a>600) {--speed.a;}
if (ball.b>600) {--speed.b;}
if(ball.b<0) {++speed.b;}
if(ball.a<0) {++speed.a;}
startStop= TTF_RenderText_Solid( font, "Press S to start or stop the timer", textColor );
// SDL_RenderFillRect(renderer, &rect);
SDL_BlitSurface( startStop,NULL, surface, 0 );
// apply_surface( 0, 0, startStop, surface );
}
void
DrawChessBoard(SDL_Renderer * renderer)
{
drawtriangle (renderer);
int row = 0,column = 0,x = 0;
SDL_Rect rect, darea;
/* Get the Size of drawing surface */
SDL_RenderGetViewport(renderer, &darea);
for ( ; row < 8; row++) {
column = row%2;
x = column;
for ( ; column < 4+(row%2); column++) {
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0xFF);
rect.w = darea.w/8;
rect.h = darea.h/8;
rect.x = x * rect.w;
rect.y = row * rect.h;
x = x + 2;
SDL_RenderFillRect(renderer, &rect);
}
}
}
int main(int argc, char *argv[]) {
SDL_Init( SDL_INIT_EVERYTHING );
int posX = 100, posY = 100, width = 320, height = 240;
// SDL_RenderFillRect(renderer, &rect);
// SDL_Init(SDL_INIT_VIDEO);
win = SDL_CreateWindow("Hello World", posX, posY, width, height, SDL_WINDOW_OPENGL);
surface = SDL_GetWindowSurface(win);
renderer = SDL_CreateSoftwareRenderer(surface);
SDL_RenderGetViewport(renderer, &darea);
SDL_SetRenderDrawColor(renderer, 1, 0, 0, 0xFF);
//bitmapSurface = load_image( "background.png" );
bitmapSurface = SDL_LoadBMP("hello.bmp");
font = TTF_OpenFont( "lazy.ttf", 36 );
bitmapTex = SDL_CreateTextureFromSurface(renderer, bitmapSurface);
SDL_FreeSurface(bitmapSurface);
// SDL_WM_SetCaption( "Zdarzenia", NULL );
// SDL_Flip( ekran );
while (1) {
SDL_ShowCursor( SDL_DISABLE );
SDL_Event e;
if( e.type == SDL_KEYDOWN )
{
//Set the velocity
switch( e.key.keysym.sym )
{
// case SDLK_RIGHT: a+=1; break;
// case SDLK_LEFT: a-=1; break;
}
}
if( e.type == SDL_MOUSEMOTION )
{
kursorDane.x = e.motion.x;
kursorDane.y = e.motion.y;
if(kursorDane.x>ball.a&&kursorDane.y>ball.b&&kursorDane.x<ball.a+50&&kursorDane.y<ball.b+50)
{
--speed.a;
// a=kursorDane.x;
// b=kursorDane.y;
}
}
//If a key was released
else if( e.type == SDL_KEYUP )
{
//Set the velocity
switch( e.key.keysym.sym )
{
// case SDLK_RIGHT: a+=10; break;
// case SDLK_LEFT: a-=10; break;
}
}
if( e.type == SDL_MOUSEBUTTONDOWN )
{
if( e.button.button == SDL_BUTTON_LEFT &&
( kursorDane.x >= przyciskCel.x && kursorDane.x <=
przyciskCel.x + przyciskDane.w ) &&( kursorDane.y >=
przyciskCel.y && kursorDane.y <= przyciskCel.y +
przyciskDane.h ) )
{
e.type==SDL_QUIT;
break;
}
}
if (SDL_PollEvent(&e)) {
if (e.type == SDL_QUIT) {
break;
}
}
// DrawChessBoard(renderer);
drawtriangle (renderer);
line(renderer);
point(renderer);
/* Got everything on rendering surface,
now Update the drawing image on window screen */
SDL_UpdateWindowSurface(win);
SDL_RenderFillRect(renderer, &rect);
SDL_RenderClear(renderer);
SDL_RenderCopy(renderer, bitmapTex, NULL, NULL);
// SDL_RenderPresent(renderer);
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
// turn on animate
// glClear(GL_COLOR_BUFFER_BIT);
SDL_GL_SwapWindow(win);
}
SDL_DestroyTexture(bitmapTex);
SDL_DestroyRenderer(renderer);
SDL_DestroyWindow(win);
SDL_Quit();
return 0;
}
No comments:
Post a Comment