// Circle centred at (cx,cy) of radius r, see :
// http://content.gpwiki.org/index.php/SDL:Tutorials:Drawing_and_Filling_Circles
void Shorthand_SDL_RenderDrawCircle(SDL_Renderer *rend, int cx, int cy, int r)
{

   double dx, dy;
   dx = floor(sqrt((2.0 * r ) ));
   SDL_RenderDrawLine(rend, cx-dx, cy+r, cx+dx, cy+r);
   SDL_RenderDrawLine(rend, cx-dx, cy-r, cx+dx, cy-r);
   for (dy = 1; dy <= r; dy += 1.0) {
        dx = floor(sqrt((2.0 * r * dy) - (dy * dy)));
        SDL_RenderDrawPoint(rend, cx+dx, cy+r-dy);
        SDL_RenderDrawPoint(rend, cx+dx, cy-r+dy);
        SDL_RenderDrawPoint(rend, cx-dx, cy+r-dy);
        SDL_RenderDrawPoint(rend, cx-dx, cy-r+dy);
   }

}
Beispiel #2
0
void Renderer::drawPixel(const Color &color, int x, int y)
{
    SDL_SetRenderTarget(this->renderer, this->nativeTexture);
    SDL_SetRenderDrawColor(this->renderer, color.getR(), color.getG(),
                           color.getB(), color.getA());
    SDL_RenderDrawPoint(this->renderer, x, y);
}
void S013010C_Aaron_Smith_Tank::DrawDebugCircle(Vector2D centrePoint, float radius)
{
	Vector2D polarVec;
	polarVec.x = 0.0f;
	polarVec.y = radius;

	float stepSize = 0.05f;

	float _360DegAsRads = DegsToRads(360.0);

	while (polarVec.x < _360DegAsRads)
	{
		Vector2D polarAsCart;
		polarAsCart.x = polarVec.y * cosf(polarVec.x);
		polarAsCart.y = polarVec.y * sinf(polarVec.x);

		Vector2D drawPoint;
		drawPoint.x = centrePoint.x + polarAsCart.x;
		drawPoint.y = centrePoint.y + polarAsCart.y;

		SDL_SetRenderDrawColor(mRenderer, 0, 0, 0, 255);
		SDL_RenderDrawPoint(mRenderer, drawPoint.x, drawPoint.y);

		polarVec.x += stepSize;
	}

}
//Draws a point at the specified coordinates
//param:x->X coordinate of the point
//param:y->Y coordinate of the point
//param:color->Color to draw the point
//returns 0 for success, -1 for errors
int SpriteBatch::DrawPoint(int x, int y, 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;
	}

	int result = 0;

	//Set the point color
	result = SDL_SetRenderDrawColor(renderer, color.r, color.g, color.b, color.a);

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

	//Draw the point
	result = SDL_RenderDrawPoint(renderer, x, y);

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

	//return success
	return result;
}
   GraphicsManager& GraphicsManager::DrawPixel (int x, int y, const Color& color)
   {
      SDL_SetRenderDrawColor(device, color.Red(), color.Green(), color.Blue(), color.Alpha());
      SDL_RenderDrawPoint(device, x, y);

      return *this;
   }
Beispiel #6
0
void Range::generateTexture(SDL_Renderer * renderer)
{
    if(texture != nullptr)
    {
        SDL_DestroyTexture(texture);
        texture = nullptr;
    }

    setWidth(value * 2);
    setHeight(value * 2);

    SDL_Texture * prevRenderTarget = SDL_GetRenderTarget(renderer);
    texture = SDL_CreateTexture(renderer,SDL_PIXELFORMAT_UNKNOWN,SDL_TEXTUREACCESS_TARGET,getWidth(),getHeight());
    SDL_SetTextureBlendMode(texture,SDL_BLENDMODE_BLEND);

    SDL_SetRenderTarget(renderer,texture);
    SDL_SetRenderDrawColor(renderer,0,0,0,0);
    SDL_RenderClear(renderer);
    SDL_SetRenderDrawColor(renderer,255,0,0,255);



    for(double i = 0; i<=360; i+=0.01)
    {
        int x = value + value * cos(i);
        int y = value + value * sin(i);

        SDL_RenderDrawPoint(renderer,x,y);
    }




    SDL_SetRenderTarget(renderer,prevRenderTarget);
}
Beispiel #7
0
//Affiche un point aux coordonnées de la souris
void afficherPoint()
{
	static int x, y;
	SDL_GetMouseState(&x, &y);
	SDL_RenderDrawPoint(globalRenderer, x, y);
	SDL_RenderPresent(globalRenderer);
}
Beispiel #8
0
void render_point(renderer *renderer, world *world, int id) {
	position pos = world->positions[id];
	color color = world->colors[id];
	(void)printf("Rendering point %d at %d, %d\n", id, pos.x, pos.y);

	SDL_SetRenderDrawColor(renderer->sdl_renderer, color.r, color.g, color.b, color.a);
	SDL_RenderDrawPoint(renderer->sdl_renderer, pos.x, pos.y);
}
Beispiel #9
0
void renderRadius(GraphicsData *graphicsData, SDL_Point *point, double radius, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
{
	double currOffsetX, currOffsetY;
	point->x += graphicsData->navigationOffset.x;
	point->y += graphicsData->navigationOffset.y;

	SDL_SetRenderDrawColor(graphicsData->renderer, r,g,b, a);

    for (currOffsetY = 1; currOffsetY <= radius; currOffsetY ++) {
         currOffsetX = floor(sqrt((2.0 * radius * currOffsetY) - (pow(currOffsetY, 2))));
         SDL_RenderDrawPoint(graphicsData->renderer, point->x - currOffsetX, point->y + radius - currOffsetY);
         SDL_RenderDrawPoint(graphicsData->renderer, point->x - currOffsetX, point->y - radius + currOffsetY);
         SDL_RenderDrawPoint(graphicsData->renderer, point->x + currOffsetX, point->y + radius - currOffsetY);
         SDL_RenderDrawPoint(graphicsData->renderer, point->x + currOffsetX, point->y - radius + currOffsetY);
    }

}
Beispiel #10
0
/* this is as low as it gets. slams pixels onto surface */
static void drawBetweenPoints(SDL_Point* p1, SDL_Point* p2, SDL_Color c, int w) {
	double divDiff;
	bool yLonger = false;
	int incrementVal;
	int shortLen;
	int longLen;
	int i;

	if (!p1 || !p2) {
		return;
	}

	shortLen = p2->y - p1->y;
	longLen = p2->x - p1->x;

	//determine long
	if (abs(shortLen)>abs(longLen)) {
		int swap = shortLen;
		shortLen = longLen;
		longLen = swap;
		yLonger = true;
	}

	if (longLen<0) incrementVal = -1;
	else incrementVal = 1;

	if (shortLen == 0) divDiff = longLen;
	else divDiff = (double)longLen / (double)shortLen;

	//ok time to draw
	SDL_SetRenderDrawColor(global_renderer, c.r, c.g, c.b, 255);
	if (yLonger) {
		for (i = 0; i != longLen; i += incrementVal) {
			int x = p1->x + (int)((double)i / divDiff) + gDrawOffset_x;
			int y = p1->y + i + gDrawOffset_y;
			SDL_RenderDrawPoint(global_renderer, x, y);
		}
	}
	else {
		for (i = 0; i != longLen; i += incrementVal) {
			int x = p1->x + i + gDrawOffset_x;
			int y = p1->y + (int)((double)i / divDiff) + gDrawOffset_y;
			SDL_RenderDrawPoint(global_renderer, x, y);
		}
	}
}
Beispiel #11
0
		int LOBJECT_METHOD(drawPoint, SDL_Renderer * renderer){
			if (state.is_number(1) && state.is_number(2)){
				state.push_boolean(SDL_RenderDrawPoint(renderer, state.to_integer(1), state.to_integer(2)) == 0);
				return 1;
			}else{
				return 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());
}
/*
 * Set the pixel at (x, y) to the given value
 */
void SDLHardwareImage::drawPixel(int x, int y, const Color& color) {
	if (!surface) return;

	SDL_SetRenderTarget(renderer, surface);
	SDL_SetTextureBlendMode(surface, SDL_BLENDMODE_BLEND);
	SDL_SetRenderDrawColor(renderer, color.r, color.g, color.b, color.a);
	SDL_RenderDrawPoint(renderer, x, y);
	SDL_SetRenderTarget(renderer, NULL);
}
Beispiel #14
0
CAMLprim value
caml_SDL_RenderDrawPoint2(value renderer, value x, value y)
{
    int r = SDL_RenderDrawPoint(
                SDL_Renderer_val(renderer),
                Int_val(x), Int_val(y));
    if (r) caml_failwith("Sdlrender.draw_point2");
    return Val_unit;
}
Beispiel #15
0
void Bullet::Render()
{
    if(alive)
    {
        //  Render and color
        SDL_SetRenderDrawColor(m_renderer, 255, 255, 255, 255);
        SDL_RenderDrawPoint(m_renderer,points[0].x,points[0].y);
    }
}
void buffer_plot_pixel(int x, int y, u8 r, u8 g, u8 b, u8 a)
{
    if(rendering_world)
    {
        if(x > SCREEN_WIDTH+SCREEN_SHIFT_X || x < SCREEN_SHIFT_X || y < SCREEN_SHIFT_Y || y > SCREEN_HEIGHT+SCREEN_SHIFT_Y)
            return;
    }
    SDL_SetRenderDrawColor(displayRenderer, r, g, b, a);
    SDL_RenderDrawPoint(displayRenderer, x, y);
}
Beispiel #17
0
CAMLprim value
caml_SDL_RenderDrawPoint(value renderer, value p)
{
    int r = SDL_RenderDrawPoint(
                SDL_Renderer_val(renderer),
                Int_val(Field(p, 0)),
                Int_val(Field(p, 1)));
    if (r) caml_failwith("Sdlrender.draw_point");
    return Val_unit;
}
Beispiel #18
0
void draw_point( int x, int y, Uint32 color )
{
    Uint8 r, g, b, a;

    SDL_GetRenderDrawColor( render, &r, &g, &b, &a );
    SDL_SetRenderDrawColor( render, color >> 16, ( color >> 8 ) & 0xFF, 
                            ( color & 0xFF ), 255 );
    SDL_RenderDrawPoint( render, x, y );
    SDL_SetRenderDrawColor( render, r, g, b, a );
} 
Beispiel #19
0
void
SDLRenderer::renderPoint(const vec2& position, const Color& color) {
    SDL_SetRenderDrawColor(_renderer,
                           color.red * 255,
                           color.green * 255,
                           color.blue * 255,
                           color.alpha * 255);
    auto p = AffineTransform::applyTransform(_origin, position);
    SDL_RenderDrawPoint(_renderer, p.x, p.y);
}
Beispiel #20
0
void zSDL_RenderDrawPoint( SDL_Renderer * renderer, Uint16 x, Uint16 y) {
Uint16 xz;
Uint16 yz;
//return;tf
for (yz=0;yz<zoom;yz++){
  for (xz=0;xz<zoom;xz++){
    SDL_RenderDrawPoint(renderer, x*zoom+xz, y *zoom +yz);
  }
}
}
Beispiel #21
0
void drawStars(void)
{
	int i;
	int c;
	
	for (i = 0 ; i < MAX_STARS ; i++)
	{
		c = 64 * stars[i].speed;
		
		SDL_SetRenderDrawColor(app.renderer, c, c, c, 255);
		
		SDL_RenderDrawPoint(app.renderer, stars[i].x, stars[i].y);
		
		if (c >= 240)
		{
			SDL_RenderDrawPoint(app.renderer, stars[i].x + 1, stars[i].y + 1);
		}
	}
}
Beispiel #22
0
void PRJ_render_point(SDL_Renderer* renderer,
                     double vertex[],
                     int res[]) {
    int point_2d[2];
    PRJ_transform_point(point_2d,
                       vertex,
                       PRJ_position,
                       res);
    SDL_RenderDrawPoint(renderer, point_2d[0], point_2d[1]);
}
// Called by Rocket when it wants to render geometry that it does not wish to optimise.
void RocketSDL2Renderer::RenderGeometry(Rocket::Core::Vertex* vertices, int num_vertices, int* indices, int num_indices, const Rocket::Core::TextureHandle texture, const Rocket::Core::Vector2f& translation)
{
    // SDL uses shaders that we need to disable here  
    glUseProgramObjectARB(0);
    glPushMatrix();
    glTranslatef(translation.x, translation.y, 0);
 
    std::vector<Rocket::Core::Vector2f> Positions(num_vertices);
    std::vector<Rocket::Core::Colourb> Colors(num_vertices);
    std::vector<Rocket::Core::Vector2f> TexCoords(num_vertices);
    float texw, texh;
 
    SDL_Texture* sdl_texture = NULL;
    if(texture)
    {
        glEnableClientState(GL_TEXTURE_COORD_ARRAY);
        sdl_texture = (SDL_Texture *) texture;
        SDL_GL_BindTexture(sdl_texture, &texw, &texh);
    }
 
    for(int  i = 0; i < num_vertices; i++) {
        Positions[i] = vertices[i].position;
        Colors[i] = vertices[i].colour;
        if (sdl_texture) {
            TexCoords[i].x = vertices[i].tex_coord.x * texw;
            TexCoords[i].y = vertices[i].tex_coord.y * texh;
        }
        else TexCoords[i] = vertices[i].tex_coord;
    };
 
    glEnableClientState(GL_VERTEX_ARRAY);
    glEnableClientState(GL_COLOR_ARRAY);
    glVertexPointer(2, GL_FLOAT, 0, &Positions[0]);
    glColorPointer(4, GL_UNSIGNED_BYTE, 0, &Colors[0]);
    glTexCoordPointer(2, GL_FLOAT, 0, &TexCoords[0]);
 
    glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    glDrawElements(GL_TRIANGLES, num_indices, GL_UNSIGNED_INT, indices);
    glDisableClientState(GL_VERTEX_ARRAY);
    glDisableClientState(GL_COLOR_ARRAY);
 
    if (sdl_texture) {
        SDL_GL_UnbindTexture(sdl_texture);
        glDisableClientState(GL_TEXTURE_COORD_ARRAY);
    }
 
    glColor4f(1.0, 1.0, 1.0, 1.0);
    glPopMatrix();
    /* Reset blending and draw a fake point just outside the screen to let SDL know that it needs to reset its state in case it wants to render a texture */
    glDisable(GL_BLEND);
    SDL_SetRenderDrawBlendMode(mRenderer, SDL_BLENDMODE_NONE);
    SDL_RenderDrawPoint(mRenderer, -1, -1);
}
Beispiel #24
0
	//Draw Points
	void CSprite::DrawPoint(Type2<slong> pos, _COLOR<uchar> color)
	{
		if (color.a == 0)
			return;

		if (this->m_eCoordinateSystem == CARTESIAN)
			pos.y = SCREEN_HEIGHT - pos.y;

		SDL_SetRenderDrawColor(this->m_pRen, color.r, color.g, color.b, color.a);
		SDL_RenderDrawPoint(this->m_pRen, pos.x, pos.y);
	}
void cGraphicsSDL2::DrawFillCircle(int &x, int &y, 
                                   uint32_t &radius, 
                                   sColor *color /*= nullptr*/) {
    SetDrawColor(color);
    int tmpX = 0;
    int tmpY = 0;
    for (int i = 0; i < 360; i++) {
        tmpX = x + (sin(i) * radius);
        tmpY = y + (cos(i) * radius);
        SDL_RenderDrawPoint(m_Renderer, tmpX, tmpY);
    }
}
Beispiel #26
0
void Display::drawFragment(const Vertex & v) {
    float x = v.attrs[0].x, y = v.attrs[0].y;
    if (v.attrs.size() >= 2) {
        glm::vec4 color = v.attrs[1];
        int X = (int)(round(x)), Y = (int)(round(y));
        color.x *= 255;
        color.y *= 255;
        color.z *= 255;
        SDL_SetRenderDrawColor(renderer, color.x, color.y, color.z, 255); 
        SDL_RenderDrawPoint(renderer, X, Y);
    }
}
Beispiel #27
0
	void SDLWindow::DrawEllipse(const Rect &rect)
	{
		// This is how often points will be drawn
		const static double granularity = 0.001;
		// We roll our own ellipse...
		double angle = 0;
		int x = rect.x, y = rect.y, w = rect.w, h = rect.h;
		while (angle <= M_PI * 2) {
			SDL_RenderDrawPoint(this->write_to, x + (w*cos(angle)), y + (h*sin(angle)));
			angle += granularity;
		}
	}
Beispiel #28
0
void CPhysicsDebugDraw::DrawPoint(const b2Vec2& p, float32 size, const b2Color& color)
{
	//SDL_SetRenderDrawColor(g_app->sdlRenderer,color.r,color.g,color.b,255);
	SDL_RenderDrawPoint(g_app->sdlRenderer,(int)(p.x),(int)(p.y));

	//glPointSize(size);
	//glBegin(GL_POINTS);
	//glColor3f(color.r, color.g, color.b);
	//glVertex2f(p.x, p.y);
	//glEnd();
	//glPointSize(1.0f);
}
Beispiel #29
0
void drawLissajousFigure(SDL_Renderer *ren, int m, int n)
{
    int x, y;
    SDL_SetRenderDrawColor(ren, 0x00, 0x00, 0x00, 0xFF);
    SDL_RenderClear(ren);
    SDL_SetRenderDrawColor(ren, 0xFF, 0xFF, 0xFF, 0xFF);
    for(double i = 0; i <= 180; i += 0.01)
    {
        x = (SCREEN_WIDTH / 2) + (SCREEN_WIDTH / 2) * cos(m * i), y = (SCREEN_HIGHT / 2) + (SCREEN_HIGHT / 2) * sin(n * i);
        SDL_RenderDrawPoint(ren, x, y);
    }
    SDL_RenderPresent(ren);
}
void Line::draw()
{
	int window_w, window_h;
	SDL_GetWindowSize(window, &window_w, &window_h);

	std::vector<SDL_Point> draw_points;

	// try to get minimal drawing area, so i don't have to draw across the entire window
	int tlx = window_w;
	int tly = window_h;
	int brx = 0;
	int bry = 0;

	if(start_point.x < tlx) tlx = start_point.x;
	if(end_point.x < tlx) tlx = end_point.x;
	if(start_point.y < tly) tly = start_point.y;
	if(end_point.y < tly) tly = end_point.y;
	if(start_point.x > brx) brx = start_point.x;
	if(end_point.x > brx) brx = end_point.x;
	if(start_point.y > bry) bry = start_point.y;
	if(end_point.y > bry) bry = end_point.y;

	// don't draw if it goes off screen either
	if(tlx < 0) tlx = 0;
	if(tly < 0) tly = 0;
	if(brx > window_w) brx = window_w;
	if(bry > window_h) bry = window_h;

	double slope = end_point.x - start_point.x != 0? double(end_point.y - start_point.y) / double(end_point.x - start_point.x) : global::VERTICAL_SLOPE;
	int b = start_point.y - slope * start_point.x;

	// for each pixel in drawing area
	for(int x = tlx; x <= brx; x++)
	{
		for(int y = tly; y <= bry; y++)
		{
			double dist = double(y - slope * x - b) / sqrt(slope*slope + 1);

			if(dist < 0) dist *= -1;
			
			// if distance is within 1 pixel, it's an edge
			if(dist <= 1)
			{
				int anti_alias = 255 * dist;

				SDL_SetRenderDrawColor(renderer, color.r, color.g, color.b, color.a - anti_alias);
				SDL_RenderDrawPoint(renderer, x, y);
			}
		}
	}
}