Can I plot individual pixels using SDL? |
MrTAToad
|
You would use SDL_RenderDrawPoint for rendering to a texture/screen
|
|||||||||||
|
Alex
|
Additionally you can use SDL_Surface as a pixel array and manipulate any pixel you want. After this manipulations draw this surface.
|
|||||||||||
|
Can I plot individual pixels using SDL? |
j_post
Guest
|
On Saturday 28 February 2015 07:33:08 bilsch01 wrote:
and their derivatives (up to the 4th) and displays them quickly. If your screen saver is animated, though, it may not be fast enough. If you like, let me know and I'll send you the source directly. It's written in C++ and uses SDL 1.2, but should easily adapt to SDL2. If all you need is a function that plots individual points, the code used is // Set pixel at given coordinates to the given color void setPixel(int x, int y, int color) { Uint8 *row8; Uint16 *row16; Uint32 *row32; if (x < 0 || x >= SCREEN_PIXEL_WIDTH || y < 0 || y >= SCREEN_PIXEL_HEIGHT) return; // Don't allow overwriting boundaries of the screen switch (bytes_per_pixel) { case 1: row8 = (Uint8 *) (screen->pixels + y * pitch + x * bytes_per_pixel); *row8 = (Uint8) color; break; case 2: row16 = (Uint16 *) (screen->pixels + y * pitch + x * bytes_per_pixel); *row16 = (Uint16) color; break; case 4: row32 = (Uint32 *) (screen->pixels + y * pitch + x * bytes_per_pixel); *row32 = (Uint32) color; break; } } The 'screen' variable above is a pointer to an SDL_Surface. Jeff _______________________________________________ SDL mailing list http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org |
|||||||||||||
|
bilsch01
|
I can run other SDL programs so I think I have the SDL libraries I need. But when I put SDL_RenderDrawPoint in the program I get the following error: sdlsnx2.c.text+0x192): undefined reference to `SDL_RenderDrawPoint' collect2: error: ld returned 1 exit status Is there some other library or header file I need? I notice the command is not included in the reference pages at: http://www.libsdl.org/release/SDL-1.2.15/docs/html/. Apparently that site is missing some commands. Can you tell me a site that has complete set of SDL commands? Thanks. |
|||||||||||||
|
Alex
|
|
|||||||||||
|
Can I plot individual pixels using SDL? |
Jared Maddox
Guest
|
You want to use either the renderer with the SDL_Render* functions, or an SDL_Surface with a hand-written pixel manipulation function. Only you can decide which is the correct choice. _______________________________________________ SDL mailing list http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org |
|||||||||||||
|
Can I plot individual pixels using SDL? |
Jared Maddox
Guest
|
<snip>
<snip>
If you don't have an objection, then I'm going to use this for my own textured-triangles code. _______________________________________________ SDL mailing list http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org |
|||||||||||||||||||
|
Can I plot individual pixels using SDL? |
Jared Maddox
Guest
|
Are you COMPLETELY certain that you're using SDL 2? The reference link that you posted is for SDL 1.2, which is one of the predecessor versions, but actually doesn't have API or ABI compatibility with SDL 2. If for some reason you need to use SDL 1.2, then you'll need to go with the software-surface method that Jeff mentioned. _______________________________________________ SDL mailing list http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org |
|||||||||||||||
|
Can I plot individual pixels using SDL? |
j_post
Guest
|
On Saturday 28 February 2015 21:03:50 Jared Maddox wrote:
Jeff _______________________________________________ SDL mailing list http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org |
|||||||||||||||||
|
Re: Can I plot individual pixels using SDL? |
bilsch01
|
[/quote]
Are you COMPLETELY certain that you're using SDL 2? The reference link that you posted is for SDL 1.2, which is one of the predecessor versions, but actually doesn't have API or ABI compatibility with SDL 2. If for some reason you need to use SDL 1.2, then you'll need to go with the software-surface method that Jeff mentioned. The SDL2 library is in my system however I think my capability is limited to 1.2 because the compiler says UNDEFINED REFERENCE to SDL_RenderDrawPoint. I don't see that the code posted by Jeff will plot a pixel. My code computes x and y coordinates for 640x480 display and uses TurboC putpixel() to display the computed point. putpixel is very slow. SDL_RenderDrawPoint is not available apparently because I have SDL 1.2 capability only. Apparently there is no command in SDL 1.2 that displays individual pixels. |
|||||||||||
|
Re: Can I plot individual pixels using SDL? |
Alex
|
You should correctly add paths to your include and libs files when compiling and linking your app. Try this console commands: sdl2-config --cflags sdl2-config --libs Is this commands show something on your system? |
|||||||||||||
|
Can I plot individual pixels using SDL? |
j_post
Guest
|
On Sunday 01 March 2015 05:46:34 bilsch01 wrote:
It sets the pixel in the SDL_Surface pointed to by 'screen'. At some point you need to call SDL_UpdateRect to actually display the changes, but you don't want to do that after every call to setPixel or it will be *real* slow. What my code (call 'polygraph' for polynomial graphing) does is plot the entire function within the applicable domain and range using calls to setPixel and only then calls SDL_UpdateRect. I've never actually timed how long it takes since once it begins plotting, the curve appears on screen faster than a human can detect. Good enough for my uses. If, on the other hand, by 'plot a pixel' you mean knowing which pixel to set to what color, that's the job of your application code. Again, if you'd like the program's source code (which is GPL'd) I'll send you a zip or tar.gz file, but I see no need to burden the mailing list with it. It will compile for either Linux or Windows, but not OSX, 'cause, you know, Apple sucks
that the TurboC library is updating the displayed data (the physical screen) after every call to putpixel(). See above. Jeff _______________________________________________ SDL mailing list http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org |
|||||||||||||||
|
Re: Can I plot individual pixels using SDL? |
Alex
|
Jared, if you plan to publish your textured-triangles code under conditions of zlib license, like SDL2 library license, then you can't use that code because it under GPL license. This two licenses are incompatible. I think you can use zlib-licensed code in GPL-ed application, but you can't use GPL-ed code in zlib-licensed app or library. Be careful with this licenses. |
|||||||||||||
|
Can I plot individual pixels using SDL? |
j_post
Guest
|
On Sunday 01 March 2015 08:31:00 Alex wrote:
routine in their software under any license they choose as long as said license doesn't try to make the code proprietary. Same applies to any function in the program that interfaces to SDL functions or structures, as opposed to the higher level application code which must remain GPL. I'm no lawyer (I have ethics :-), but the above statement is legally binding. --------------------------- | Application | GPL | (bunch of math stuff) | --------------------------- | V ------------------ | SDL interface | any license you want that is not proprietary ------------------- | V -------------- | SDL | SDL's license -------------- Jeff _______________________________________________ SDL mailing list http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org |
|||||||||||||||
|
Re: Can I plot individual pixels using SDL? |
Alex
|
Thanks, Jeff. I'm not lawyer too, but I have some (limited) knowledge about licenses Cause you can use SDL2 in your GPL application - zlib-license permit you to use it. Zlib-license is much more permissive than GPL. Any code licensed under zlib conditions can be used even inside of proprietary application (not only in free apps). If you forbid to use this code in proprietary application, then this code can't be licensed under zlib conditions. You right, this scheme is correct: |GPL App| (use/include code)-> |SDL2| This scheme is correct too: |Proprietary app| (use/include code)-> |SDL2| This scheme is not correct: |SDL2| (use/include code)-> |GPL code| I mean you can't use GPL code inside SDL2 library. But you can use SDL2 code even in proprietary app or lib. Sorry for offtopic. This topic is not about licenses. |
|||||||||||||
|
Can I plot individual pixels using SDL? |
j_post
Guest
|
On Sunday 01 March 2015 09:33:22 Alex wrote:
Since I wrote that app more than 8 years ago, it uses SDL1.2. If anyone cares to port it to SDL2, please let me know. I'd love to have an SDL2 version of it, but I lack the time to port it myself. (It's written in C++, but much of it is very C-ish.) Jeff _______________________________________________ SDL mailing list http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org |
|||||||||||||||
|
Re: Can I plot individual pixels using SDL? |
Alex
|
You still can use SDL_Surface to draw in SDL2 (http://wiki.libsdl.org/SDL_Surface). I think it is not very hard work to port your code to SDL2. Just rewrite some small parts of code |
|||||||||||||
|
Can I plot individual pixels using SDL? |
Jared Maddox
Guest
|
Are you COMPLETELY certain that you're using SDL 2? The reference link that you posted is for SDL 1.2, which is one of the predecessor versions, but actually doesn't have API or ABI compatibility with SDL 2. If for some reason you need to use SDL 1.2, then you'll need to go with the software-surface method that Jeff mentioned. The SDL2 library is in my system however I think my capability is limited to 1.2 because the compiler says UNDEFINED REFERENCE to SDL_RenderDrawPoint. I don't see that the code posted by Jeff will plot a pixel. My code computes x and y coordinates for 640x480 display and uses TurboC putpixel() to display the computed point. putpixel is very slow. SDL_RenderDrawPoint is not available apparently because I have SDL 1.2 capability only. Apparently there is no command in SDL 1.2 that displays individual pixels. [/quote] Time for a history lesson. Once upon a time ( specifically, before the mid-90s), programs accessed the display card directly. This worked in the following manner: the card would have a block of memory, and that block of memory could be accessed by the CPU as if it was part of the computer's normal memory. The display card would in turn also be accessing that block of memory, through a physically separate set of access pins (this type of memory is called "dual-ported", and still exists for this type of application), and use the information that it obtained to control the actual display. The arrangement of this memory was that of a set of one-dimensional matrixes, arranged sequentially in memory, with the elements of each array also in sequential order, with whatever padding was necessary inside or between the arrays. Text displays would have a byte-per-character + a separate ROM to contain the appearance of the actual characters, black and white displays would usually have a bit-per-pixel, "True-color" displays would (and technically still do, for the sake of boot-stage graphics and backwards-compatibility) usually have either 3 bytes or 4 bytes per pixel, etc. To access the space of an individual pixel you would determine the X and Y coordinates of the pixel, calculate the affect of bit-alignment on the location (we don't do this with SDL, because SDL doesn't do pixels that are a non-whole multiple of a byte), and then do some multiplication and addition to determine the location in memory of the pixel. SDL's surfaces work with this exact same scheme. The "pitch" variable in Jeff's code is the distance between the beginning of adjacent one-dimensional pixel matrixes (called scanlines): this number takes into account both the space occupied by the pixels, as well as any padding. The TurboC putpixel() function most likely works very similarly, since Windows started using "dib" (basically the in-memory form of a .bmp file) images in it's rendering system very early. SDL 1.2 (and 2, though for more recent graphics models) is basically built around providing a platform-independent interface to graphics that's compatible with common rendering practices, so the natural assumption going in was that the pixel access code would already be there (and probably be optimized already), and just need to be modified instead of being written from scratch. Thus, it didn't actually make sense to include pixel access routines. _______________________________________________ SDL mailing list http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org |
|||||||||||||
|
Can I plot individual pixels using SDL? |
Jared Maddox
Guest
|
I was going to point out that Alex's point about this still not being compatible was right (since SDL 2 is allowed to be static-linked, the code in it can become INDIRECTLY subject to a license making the code proprietary, thereby conflicting with your terms), but then I looked at the code and noticed it doesn't actually calculate the pixel value from raw RGB(A) values, so it isn't actually useful to me anyways . I'll just go digging around in the Hg for a while to see if I can find something. _______________________________________________ SDL mailing list http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org |
|||||||||||||||||
|
MrTAToad
|
I would go with the fact that your library pathing is somewhat inaccurate - you need to #include "SDL2.h" and make sure that the libraries are accessible when compiling. |
|||||||||||||||
|
Can I plot individual pixels using SDL? |
Jonny D
|
I'm wondering why a putpixel function is suddenly so desirable to you guys... Â
Anyhow, just use SDL_MapRGBA() to get a Uint32 instead of the int that Jeff's code uses. I'm pretty sure you can easily find the same code elsewhere online. Jonny D On Sun, Mar 1, 2015 at 4:56 PM, MrTAToad wrote:
|
|||||||||||||
|
Can I plot individual pixels using SDL? |
j_post
Guest
|
On Sunday 01 March 2015 13:00:21 Jonathan Dearborn wrote:
It has its uses. (Disclaimer: I don't write games. I use SDL for application software involving math and/or software development tools. I've also done some wrapper applications for graphic and video software on Linux.)
Actually, it is a Uint32. I set up the colors I need for my app during initialization. Uint32 red; red = SDL_MapRGB(vfmt, (Uint8) 0xa6, (Uint8) 0x00, (Uint8) 0x00); and likewise for other colors. The colors are stored in an indexed array for speed. I probably should change the declaration of setPixel's color void setPixel(int x, int y, int color) to be Uint32 instead of int just to be pedantic, but on both my 32 bit and 64 bit machines, an int is 32 bits so it's no big deal. (64 bits is a 'long' to the compiler.) <rant> And as for the licensing issues.... C'mon guys, this is trivial code! It's not a big deal. Do what you want with it except don't try to claim you have exclusive rights to it and can prevent others from using it in their projects, which is what I mean by 'proprietary'. Okay, maybe I'm a bit overly sensitive on that issue right now. I'm having to deal with an a-hole lawyer in a civil case who bitches about nickels and dimes when hundreds of thousands of dollars are at stake. He's convinced me that 'Stupidity 101' was a required course at his law school. Let's behave like grown-up software developers and not a-hole lawyers, okay? (And just in case anyone might be feeling a little sympathy for my plight, don't bother. My lawyer intends to ask the court to issue sanctions against the a-hole because in addition to his stupidity, he's lied on forms he signed under penalty of perjury and we can prove it.) </rant> Jeff _______________________________________________ SDL mailing list http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org |
|||||||||||||||
|
Re: Can I plot individual pixels using SDL? |
Alex
|
Jeff, can you, please, post a link to your code (at any site)? I don't like to show my email at public forum. |
|||||||||||||
|
Re: Can I plot individual pixels using SDL? |
bilsch01
|
|
|||||||||||||||||
|
Re: Can I plot individual pixels using SDL? |
bilsch01
|
Those console commands generate more errors. I'm going to abandon SDL for now. Thanks for your time. Bill S. |
|||||||||||||||
|
Can I plot individual pixels using SDL? |
j_post
Guest
|
On Sunday 01 March 2015 15:16:52 Alex wrote:
From header and I've sent the tar.gz file of the source code to that address. Jeff _______________________________________________ SDL mailing list http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org |
|||||||||||||||
|
Can I plot individual pixels using SDL? |
Driedfruit
Guest
|
On Sun, 1 Mar 2015 14:55:30 -0800
"j_post" wrote:
It certainly has. Personally, for all my pixel-crunching needs, I've been using the putpixel/setpixel (or variations of those) described in the SDL 1.2 docs http://www.libsdl.org/release/SDL-1.2.15/docs/html/guidevideo.html and although I never liked them not being in the SDL itself, I think being in the docs is the next best thing. -- driedfruit _______________________________________________ SDL mailing list http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org |
|||||||||||||||
|
Can I plot individual pixels using SDL? |
Jared Maddox
Guest
|
In my case, it's because the last time that I tried writing it myself I eventually just gave up on debugging the code that used it.
I already dug it up in Hg. Thanks, though.
SDL mailing list http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org |
|||||||||||||||||
|