如何在SDL 2.0中绘制像素? [英] How to draw pixels in SDL 2.0?

查看:254
本文介绍了如何在SDL 2.0中绘制像素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在SDL2.0中如何用像素绘制?

How does one draw with pixels in SDL2.0?

我试图熟悉C ++,但是如果没有漂亮的图片,这很难做到,所以我试图让基本的图形显示东西运行。我真正想要做的就是给我一个窗口,让我在其上绘制rgbα像素,并访问有关这些像素的信息。我可能还想知道其他一些我不知道的东西,但这就是我现在要列出的全部。我对此的研究使我尝试使用SDL,当前版本为2.0。

I'm trying to get familiar with C++, but this is very difficult to do without pretty pictures, so I'm trying to get a very basic graphics display thing running. All I really want it to do is give me a window, let me draw rgbα pixels on it, and access information about those pixels. There may be other things I want that I'm not aware of, but that's all that's on my list right now. My research on this has lead me to try using SDL, the current version being 2.0.

我几乎所有的图形体验都来自在< canvas> 上使用JavaScript。其余的大部分来自我的计算器,该计算器具有 really 这个很棒的 Pxl-On()命令,非常简单。

Almost all my graphics experience comes from using JavaScript on a <canvas>. Most of the other bit comes from my calculator, which has this really awesome Pxl-On() command, so easy.

如果重要的话,我正在为我的C ++使用MinGW。另外,如果我需要的东西比SDL2.0更好,**欢迎提出建议。

I'm using MinGW for my C++, if it matters. Also, if there's something better** out there than SDL2.0 for what I need, advice welcome.

** 更好是指包含我需要的功能,但总功能少于SDL2.0,并且/或者比SDL2.0具有更直观/更少复杂的API。

** "better" means "contains what functionality I need, but less total functionality than SDL2.0, and/or has a more intuitive/less complex*** API than SDL2.0."

***更少的代码行可以完成相同的任务。

*** Less lines of code to accomplish the same task.

推荐答案

我不知道您如何代码是结构化的。假设您有一个SDL_Window和一个SDL_Renderer,则只需调用 SDL_RenderDrawPoint(renderer,x,y)

I don't know how your code is structured. Assuming you have a SDL_Window and a SDL_Renderer, you just have to call SDL_RenderDrawPoint(renderer, x, y).

如果您既没有渲染器也没有窗口,则可以使用SDL_CreateWindowAndRenderer()来创建两者。例如:

If you don't have a renderer nor window, you can create both with SDL_CreateWindowAndRenderer(). For example:

SDL_Window *window;
SDL_Renderer *renderer;
SDL_CreateWindowAndRenderer(800, 600, 0, &window, &renderer);

//Probably on a loop
  SDL_RenderDrawPoint(renderer, 400, 300); //Renders on middle of screen.
  SDL_RenderPresent(renderer);

这应该在屏幕中间绘制一个像素。读取像素要复杂一些。您可以使用 SDL_RenderReadPixels(),它是用于读取区域的,但是您始终可以指定1x1的区域。阅读维基页面(如果确实需要)。

This should draw a pixel on the middle of screen. To read a pixel is a little more complicated. You can use SDL_RenderReadPixels(), it is made for read an area, but you can always specify an area of 1x1. Read the wiki page if you really need it.

如果您在使用SDL2时遇到很多麻烦,建议您阅读惰性Foo教程。 SDL2部分仍在进行中,但是有足够的材料可以开始学习。

If you are having much trouble with SDL2 a recommend you to read the Lazy Foo tutorials. The SDL2 section still a work in progress, but there is enough material to begin learning.

这篇关于如何在SDL 2.0中绘制像素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆