Exemplo n.º 1
0
		int LOBJECT_METHOD(drawPoints, SDL_Renderer * renderer){
			if (state.is_table(1)){
				int count = state.obj_len(1);
				if (count>0){
					SDL_Point* points = new SDL_Point[count];
					int final_count = 0;
					
					for (int i=0; i< count; i++){
						state.push_integer(i+1);
						state.get_table(1); // 1 T
						if (state.is_table(-1)){
							state.get_field(-1, "x"); // 1 T x
							state.get_field(-2, "y"); // 1 T x y
							points[final_count].x = state.to_integer(-2);
							points[final_count].y = state.to_integer(-1);
							final_count++;
							state.pop(3);
						}else{
							state.pop(1);
						}
					}

					state.push_boolean(SDL_RenderDrawPoints(renderer, points, final_count) == 0);
					
					delete[] points;
					return 1;
				}
			}
			return 0;
		}
bool j1Render::DrawCircle(int x, int y, int radius, Uint8 r, Uint8 g, Uint8 b, Uint8 a, bool use_camera) const
{
	bool ret = true;
	uint scale = App->win->GetScale();

	SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_BLEND);
	SDL_SetRenderDrawColor(renderer, r, g, b, a);

	int result = -1;
	SDL_Point points[360];

	float factor = (float)M_PI / 180.0f;

	for(uint i = 0; i < 360; ++i)
	{
		points[i].x = (int)(x + radius * cos(i * factor));
		points[i].y = (int)(y + radius * sin(i * factor));
	}

	result = SDL_RenderDrawPoints(renderer, points, 360);

	if(result != 0)
	{
		LOG("Cannot draw quad to screen. SDL_RenderFillRect error: %s", SDL_GetError());
		ret = false;
	}

	return ret;
}
Exemplo n.º 3
0
void renderCircle(struct renderstate *render, int centerX, int centerY,
		  double radius)
{
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAX(a, b) ((a) > (b) ? (a) : (b))

	int left, right, top, bottom;
	int x, y;
	int point_count = 0;
	double radius_squared = pow(radius, 2);

	top = MAX(0, centerY - radius);
	bottom = MIN(render->height, centerY + radius);

	left = MAX(0, centerX - radius);
	right = MIN(render->width, centerX + radius);

	for (x = left; x < right; x++) {
		for (y = top; y < bottom; y++) {
			if ((pow(centerX - x, 2) + pow(centerY - y, 2)) <=
			    radius_squared) {
				render->points[point_count].x = x;
				render->points[point_count].y = y;
				point_count++;
				// SDL_RenderDrawPoint(render->renderer, x, y);
			}
		}
	}

	SDL_RenderDrawPoints(render->renderer, render->points, point_count);
}
Exemplo n.º 4
0
void Circle::draw()
{
	int window_w, window_h;
	SDL_GetWindowSize(window, &window_w, &window_h);

	std::vector<SDL_Point> draw_points;

	// get drawing area of circle and don't draw outside the window
	int tlx = position.x - radius;
	tlx = tlx >= 0? tlx : 0;
	int tly = position.y - radius;
	tly = tly >= 0? tly : 0;
	int brx = position.x + radius;
	brx = brx <= window_w? brx : window_w;
	int bry = position.y + radius;
	bry = bry <= window_h? bry : window_h;

	// for each pixel in this area
	for(int x = tlx; x <= brx; x++)
	{
		for(int y = tly; y <= bry; y++)
		{
			// get distance between this pixel and the center of the circle
			int x_length = abs(position.x - x);
			int y_length = abs(position.y - y);
			double r = sqrt(x_length*x_length + y_length*y_length);

			// if this circle is in range (ceilinged)
			if(ceil(r) <= radius+1)
			{
				// draw it, with anti aliasing if i'm at the very edge of the circle and the radius doesn't fully reach this pixel
				int anti_alias = 0;
				if(r > radius)
				{
					anti_alias = floor(double(255) * (r - double(radius)));
				}

				// draw each anti-aliased pixel separately
				if(anti_alias > 0)
				{
					SDL_SetRenderDrawColor(renderer, color.r, color.g, color.b, color.a - anti_alias > 0? color.a - anti_alias : 0);
					SDL_RenderDrawPoint(renderer, x, y);
				}
				// non anti-aliased pixels will be drawn all at once using RenderDrawPoints
				else
				{
					SDL_Point p;
					p.x = x;
					p.y = y;
					draw_points.push_back(p);
				}
			}
		}
	}

	SDL_SetRenderDrawColor(renderer, color.r, color.g, color.b, color.a);
	SDL_RenderDrawPoints(renderer, &draw_points[0], draw_points.size());
}
Exemplo n.º 5
0
//	Circle_Texture::Circle_Texture
Circle_Texture::Circle_Texture (unsigned radius, Color color) {
	c.calculate_points(Point(radius, radius), radius);

	create_blank(radius * 2 + 1, radius * 2 + 1, SDL_TEXTUREACCESS_TARGET);
	Renderer::set_render_target(this->texture());
	Renderer::set_draw_color(color);

	if (SDL_RenderDrawPoints(Renderer::renderer(), (SDL_Point*)c.data(), c.size()) != 0)
		cerr<<"ERROR: "<<__func__<<" SDL_RenderDrawPoints failed!\nSDL Error: "<<SDL_GetError()<<'\n';

	Renderer::reset_render_target();
}
Exemplo n.º 6
0
CAMLprim value
caml_SDL_RenderDrawPoints(value renderer, value ml_points)
{
    unsigned int i;
    unsigned int count = Wosize_val(ml_points);
    SDL_Point * points = malloc(count * sizeof(SDL_Point));
    for (i = 0; i < count; i++) {
        value p = Field(ml_points, i);
        points[i].x = Int_val(Field(p, 0));
        points[i].y = Int_val(Field(p, 1));
    }
    int r = SDL_RenderDrawPoints(
                SDL_Renderer_val(renderer),
                points, count);
    free(points);
    if (r) caml_failwith("Sdlrender.draw_points");
    return Val_unit;
}
Exemplo n.º 7
0
void Level::render(GameEngine* ge)
{
  Timer rendertime;
  //rendertime.start();
  
  SDL_SetRenderDrawColor(ge->renderer, 0xff, 0xff, 0xff, 0);
  SDL_RenderClear(ge->renderer);

  if (is_a_player_dead && (respawn_timer.getTime() > 3.0f))
  {
    spawnLevel();
    score.battleMessage = 0;
    if (score.warMessage != 0)
    {
      score.resetScores();
      score.warMessage = 0;
    }
  }

  for (int i = 0; i < gObstacleTotal; i++)
  {
    obstacles[i].render(ge->renderer);
  }
  
  // draw terrain
  SDL_SetRenderDrawColor(ge->renderer, 0x00, 0x00, 0x00, 1);
  SDL_RenderDrawPoints(ge->renderer, points, point_count);

  cannonL.render(ge->renderer);
  cannonR.render(ge->renderer);

  ball.render(ge->renderer);

  if (shooting)
    SDL_RenderCopy(ge->renderer, force_texture, NULL, &force_rect);

  score.render(ge->renderer);

  SDL_RenderPresent(ge->renderer);

  //std::cout << rendertime.getTime() << std::endl;
}
Exemplo n.º 8
0
//Draws points at the specified positions
//param:pointsArray->The array to draw from
//param:numberOfPoints->The size of the array. No bounds checking performed
//param:color->The color to set the points to
//Returns 0 for success, -1 for errors
int SpriteBatch::DrawPoints(SDL_Point* pointsArray, int numberOfPoints, SDL_Color color)
{
	//Check if spritebatch.begin has been called
	if(!begun)
	{
		std::cout<<"Begin must be called before attempting to draw"<<std::endl;
		return -1;
	}

	//Check the size
	if(numberOfPoints<= 0)
	{
		std::cout<<"DrawPoints error: Number of points must be greater than 0" <<std::endl;
		return -1;
	}

	int result = 0;
	//set the color
	result = SDL_SetRenderDrawColor(renderer, color.r, color.g, color.b, color.a);

	//check for color setting problems
	if(result != 0)
	{
		std::cout<<"DrawPoints error: Problem setting points color"<<std::endl;
		return result;
	}	

	//Draw the points
	result = SDL_RenderDrawPoints(renderer, pointsArray, numberOfPoints);

	//Check for draw problems
	if(result != 0)
	{
		std::cout<<"DrawPoints error: Problem drawing points"<<std::endl;
		return result;
	}

	//return success
	return result;
}
bool j1Render::DrawCone(int x, int y, int radius, int angle, float up_rad, float down_rad, Uint8 r, Uint8 g, Uint8 b, Uint8 a, bool use_camera) 
{
	bool ret = true;
	uint scale = App->win->GetScale();

	SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_BLEND);
	SDL_SetRenderDrawColor(renderer, r, g, b, a);

	int op = angle;
	int result = -1;
	SDL_Point points[30];

	float factor = (float)M_PI / 180.0f;

	if (use_camera)
	{
		x *= scale;
		y *= scale;
		x += camera.x;
		y += camera.y;
	}

	for (uint i = 0; i < 360; ++i)
	{
		points[i].x = (int)(x + radius * cos(i * factor) * scale);
		points[i].y = (int)(y + radius * sin(i * factor) * scale);
	}


	result = SDL_RenderDrawPoints(renderer, points, 50);

	if (result != 0)
	{
		LOG("Cannot draw cone to screen. SDL_RenderFillRect error: %s", SDL_GetError());
		ret = false;
	}

	return ret;
}
Exemplo n.º 10
0
void drawCircle(int cx, int cy, int radius, int r, int g, int b, int a)
{
	int x = radius;
	int y = 0;
	int radiusError = 1 - x;
	SDL_Point p[8];

	SDL_SetRenderDrawColor(app.renderer, r, g, b, a);
	SDL_SetRenderDrawBlendMode(app.renderer, SDL_BLENDMODE_BLEND);

	while (x >= y)
	{
		p[0].x =  x + cx; p[0].y = y + cy;
		p[1].x =  y + cx; p[1].y =  x + cy;
		p[2].x = -x + cx; p[2].y =  y + cy;
		p[3].x = -y + cx; p[3].y =  x + cy;
		p[4].x = -x + cx; p[4].y = -y + cy;
		p[5].x = -y + cx; p[5].y = -x + cy;
		p[6].x =  x + cx; p[6].y = -y + cy;
		p[7].x =  y + cx; p[7].y = -x + cy;
		SDL_RenderDrawPoints(app.renderer, p, 8);

		y++;

		if (radiusError < 0)
		{
			radiusError += 2 * y + 1;
		}
		else
		{
			x--;
			radiusError += 2 * (y - x) + 1;
		}
	}

	SDL_SetRenderDrawBlendMode(app.renderer, SDL_BLENDMODE_NONE);
}
Exemplo n.º 11
0
	void points(int p[][2], int n)
	{
		//Grapic& g = Grapic::singleton();
		SDL_RenderDrawPoints(renderer(), ((const SDL_Point*)(p)), n);
	}