Can't display pixel

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
GUGDUN
Posts: 3
Joined: Thu Mar 31, 2016 11:25 am
Libera.chat IRC: GUGDUN

Can't display pixel

Post by GUGDUN »

I've decided to create a graphical operating system and at the first steps I met a huge problem. I'm setting video mode with GRUB2(1024x768 32 bpp), but can't draw pixel. I'm doing it like this:

Code: Select all

uint32_t color;
uint8_t *video = (uint8_t*)framebuffer_address;
int where = x * (framebuffer_bpp / 8) + y * framebuffer_pitch;
video[where]  = color;
video[where + 1] = color >> 8;
video[where + 2] = color >> 16;
With the changing of X and Y coordinates only color of pixel changes, but pixel displayed in the upper left corner of the screen.
I'm using color in 0xRRGGBB format. Is it right?
User avatar
osdever
Member
Member
Posts: 492
Joined: Fri Apr 03, 2015 9:41 am
Contact:

Re: Can't display pixel

Post by osdever »

My code, Gugdun Frumin :)
Really - first you need to use unsigned int for where - normal int may overflow and do something wrong.
Show us your screenshots and full code, please.
Developing U365.
Source:
only testing: http://gitlab.com/bps-projs/U365/tree/testing

OSDev newbies can copy any code from my repositories, just leave a notice that this code was written by U365 development team, not by you.
glauxosdever
Member
Member
Posts: 501
Joined: Wed Jun 17, 2015 9:40 am
Libera.chat IRC: glauxosdever
Location: Athens, Greece

Re: Can't display pixel

Post by glauxosdever »

Hi,

catnikita255 wrote:My code, Gugdun Frumin :)
Really - first you need to use unsigned int for where - normal int may overflow and do something wrong.
Show us your screenshots and full code, please.
No, you should best use size_t for this.

What happens when you hardcode for example 100 and 200 for x and y respectively? Is the pixel still in the upper-left corner? Are you sure that x and y are really nonzero?

Code: Select all

(framebuffer_bpp / 8)
If framebuffer_bpp is 15, then this statement evaluates to 1, while 2 bytes are occupied in these modes. This is probably unrelated to the problem, though.

Code: Select all

((framebuffer_bpp + 7) / 8)
This should fix the issue easily.


Regards,
glauxosdever
User avatar
SpyderTL
Member
Member
Posts: 1074
Joined: Sun Sep 19, 2010 10:05 pm

Re: Can't display pixel

Post by SpyderTL »

Try replacing your variables with hard-coded numbers that you know are correct, temporarily. This will tell you whether the problem is on the software side (pixel offset calculation) or the hardware side (wrong address, wrong pitch, etc.)

My guess is that your framebuffer_pitch or framebuffer_bpp are zero...
Project: OZone
Source: GitHub
Current Task: LIB/OBJ file support
"The more they overthink the plumbing, the easier it is to stop up the drain." - Montgomery Scott
GUGDUN
Posts: 3
Joined: Thu Mar 31, 2016 11:25 am
Libera.chat IRC: GUGDUN

Re: Can't display pixel

Post by GUGDUN »

Using unsigned char* for video buffer and int for framebuffer_bpp and framebuffer_pitch helped, now all works fine :D
Attachments
screen.png
User avatar
Schol-R-LEA
Member
Member
Posts: 1925
Joined: Fri Oct 27, 2006 9:42 am
Location: Athens, GA, USA

Re: Can't display pixel

Post by Schol-R-LEA »

glauxosdever wrote:No, you should best use size_t for this.
That reminds me:
Note to self: The standard Thelema libraries should define at least one counter type specifically for use as definite loop indices, with zero-indexed indices as the default but supporting an optional lower bound for ranged indices. Set it up so that defining an index will silently define an anonymous Integer subtype for the specified index range. I will need to figure out how to default the handling of runtime overflow conditions, though it's probably best to throw an exception - while for the most common use case, this should only come up if there is some kind of memory corruption, dynamically defined ranges will require runtime checks. Include an analysis specializer to detect fixed ranges, to allow type generation and bounds checking to be done at compile time when possible.
Rev. First Speaker Schol-R-LEA;2 LCF ELF JAM POEE KoR KCO PPWMTF
Ordo OS Project
Lisp programmers tend to seem very odd to outsiders, just like anyone else who has had a religious experience they can't quite explain to others.
Post Reply