Putting pixels in VBE 1024*768*32 mode is not working

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.
User avatar
abcdef4bfd
Member
Member
Posts: 492
Joined: Fri Apr 03, 2015 9:41 am

Putting pixels in VBE 1024*768*32 mode is not working

Post by abcdef4bfd »

It displays me a black screen. Here's the code of the putpixel function:

Code: Select all

   unsigned long pixindex=y*vbeMode.pitch+x*(vbeMode.bpp/8);
   framebuffer[pixindex+0]=color;
   framebuffer[pixindex+1]=color>>8;
   framebuffer[pixindex+1]=color>>16;
alexfru
Member
Member
Posts: 1118
Joined: Tue Mar 04, 2014 5:27 am

Re: Putting pixels in VBE 1024*768*32 mode is not working

Post by alexfru »

I can come up with about 10 ways for how the above can be broken.
You need to debug your code to narrow down the problem.
User avatar
abcdef4bfd
Member
Member
Posts: 492
Joined: Fri Apr 03, 2015 9:41 am

Re: Putting pixels in VBE 1024*768*32 mode is not working

Post by abcdef4bfd »

alexfru wrote:I can come up with about 10 ways for how the above can be broken.
You need to debug your code to narrow down the problem.
OK, but can you see the problem in my code?
alexfru
Member
Member
Posts: 1118
Joined: Tue Mar 04, 2014 5:27 am

Re: Putting pixels in VBE 1024*768*32 mode is not working

Post by alexfru »

*The* problem? You're kidding, right? I just told you, there are many possible problems and you provided us with no information whatsoever to decide on which one it is. It can be bad values, bad memory mapping, code not even executing, etc. How can we know?
User avatar
abcdef4bfd
Member
Member
Posts: 492
Joined: Fri Apr 03, 2015 9:41 am

Re: Putting pixels in VBE 1024*768*32 mode is not working

Post by abcdef4bfd »

alexfru wrote:*The* problem? You're kidding, right? I just told you, there are many possible problems and you provided us with no information whatsoever to decide on which one it is. It can be bad values, bad memory mapping, code not even executing, etc. How can we know?
What info I need to provide?
User avatar
abcdef4bfd
Member
Member
Posts: 492
Joined: Fri Apr 03, 2015 9:41 am

Re: Putting pixels in VBE 1024*768*32 mode is not working

Post by abcdef4bfd »

Do not answer to me in 3 hours, I need to try to solve the problem myself.
Ready4Dis
Member
Member
Posts: 571
Joined: Sat Nov 18, 2006 9:11 am

Re: Putting pixels in VBE 1024*768*32 mode is not working

Post by Ready4Dis »

catnikita255 wrote:It displays me a black screen. Here's the code of the putpixel function:

Code: Select all

   unsigned long pixindex=y*vbeMode.pitch+x*(vbeMode.bpp/8);
   framebuffer[pixindex+0]=color;
   framebuffer[pixindex+1]=color>>8;
   framebuffer[pixindex+1]=color>>16;
Not very much info to go on, or any explanation of what's going wrong, but the most obvious thing is your doing pixindex+1 in both of the last two colors...
What is the address of framebuffer? Is it mapped in correctly (are you using virtual memory?) What is the value of color? There is a lot of missing information in order to give a real answer to this, but those are the first things I would check. Also, ensure you're creating a mode with LFB (linear frame buffer) otherwise this will not work very well.
glauxosdever
Member
Member
Posts: 501
Joined: Wed Jun 17, 2015 9:40 am
Libera.chat IRC: glauxosdever
Location: Athens, Greece

Re: Putting pixels in VBE 1024*768*32 mode is not working

Post by glauxosdever »

Hi,

catnikita255 wrote:It displays me a black screen. Here's the code of the putpixel function:

Code: Select all

   unsigned long pixindex=y*vbeMode.pitch+x*(vbeMode.bpp/8);
   framebuffer[pixindex+0]=color;
   framebuffer[pixindex+1]=color>>8;
   framebuffer[pixindex+1]=color>>16;
Variable "framebuffer" is of what type? What does it equal? Where did you get it from? What does it represent? Please answer these questions for yourself and then try again to fix your code, when you have the answers you need.


Regards,
glauxosdever
User avatar
abcdef4bfd
Member
Member
Posts: 492
Joined: Fri Apr 03, 2015 9:41 am

Re: Putting pixels in VBE 1024*768*32 mode is not working

Post by abcdef4bfd »

Ready4Dis wrote:
catnikita255 wrote:It displays me a black screen. Here's the code of the putpixel function:

Code: Select all

   unsigned long pixindex=y*vbeMode.pitch+x*(vbeMode.bpp/8);
   framebuffer[pixindex+0]=color;
   framebuffer[pixindex+1]=color>>8;
   framebuffer[pixindex+1]=color>>16;
Not very much info to go on, or any explanation of what's going wrong, but the most obvious thing is your doing pixindex+1 in both of the last two colors...
What is the address of framebuffer? Is it mapped in correctly (are you using virtual memory?) What is the value of color? There is a lot of missing information in order to give a real answer to this, but those are the first things I would check. Also, ensure you're creating a mode with LFB (linear frame buffer) otherwise this will not work very well.
THere's a old code, that's the new code.

Code: Select all

//This is from kmain
	framebuffer=(uint32_t*)(*mbinfo).framebuffer_addr;
	fbpitch=(*mbinfo).framebuffer_pitch;
	fbbpp=(*mbinfo).framebuffer_bpp;
//and this is my putpixel
  uint32_t fbpitch;
  uint8_t fbbpp;
inline void putpixel(int x,int y,uint32_t color)
{
	unsigned where = x*(fbbpp/8) + y*fbpitch;
	framebuffer[where] = color & 255;              // BLUE
    framebuffer[where + 1] = (color >> 8) & 255;   // GREEN
    framebuffer[where + 2] = (color >> 16) & 255;  // RED
}
User avatar
abcdef4bfd
Member
Member
Posts: 492
Joined: Fri Apr 03, 2015 9:41 am

Re: Putting pixels in VBE 1024*768*32 mode is not working

Post by abcdef4bfd »

glauxosdever wrote:Hi,

catnikita255 wrote:It displays me a black screen. Here's the code of the putpixel function:

Code: Select all

   unsigned long pixindex=y*vbeMode.pitch+x*(vbeMode.bpp/8);
   framebuffer[pixindex+0]=color;
   framebuffer[pixindex+1]=color>>8;
   framebuffer[pixindex+1]=color>>16;
Variable "framebuffer" is of what type? What does it equal? Where did you get it from? What does it represent? Please answer these questions for yourself and then try again to fix your code, when you have the answers you need.


Regards,
glauxosdever
1) uint32_t
2) Framebuffer address
3) From Multiboot info struct.
4) Framebuffer address
User avatar
Roman
Member
Member
Posts: 568
Joined: Thu Mar 27, 2014 3:57 am
Location: Moscow, Russia
Contact:

Re: Putting pixels in VBE 1024*768*32 mode is not working

Post by Roman »

Why do you use uint32_t? Do you understand, what offset 'framebuffer[1]' will be from 'framebuffer[0]'?
"If you don't fail at least 90 percent of the time, you're not aiming high enough."
- Alan Kay
User avatar
abcdef4bfd
Member
Member
Posts: 492
Joined: Fri Apr 03, 2015 9:41 am

Re: Putting pixels in VBE 1024*768*32 mode is not working

Post by abcdef4bfd »

Roman wrote:Why do you use uint32_t? Do you understand, what offset 'framebuffer[1]' will be from 'framebuffer[0]'?
Is I need to use uint8_t?
glauxosdever
Member
Member
Posts: 501
Joined: Wed Jun 17, 2015 9:40 am
Libera.chat IRC: glauxosdever
Location: Athens, Greece

Re: Putting pixels in VBE 1024*768*32 mode is not working

Post by glauxosdever »

Hi,


You can use uint32_t only if you know that the width of each pixel is 32 bits. But you don't know it. GRUB may fall back to a 24-bit mode or a 16-bit mode or even a 8-bit palette mode if it can't find the desired mode. So uint8_t is the best solution, combined with other useful fields from multiboot info struct.


Regards,
glauxosdever
User avatar
abcdef4bfd
Member
Member
Posts: 492
Joined: Fri Apr 03, 2015 9:41 am

Re: Putting pixels in VBE 1024*768*32 mode is not working

Post by abcdef4bfd »

Ok. And I fixed the problem, it was in the palette, it was old 16-color.
glauxosdever
Member
Member
Posts: 501
Joined: Wed Jun 17, 2015 9:40 am
Libera.chat IRC: glauxosdever
Location: Athens, Greece

Re: Putting pixels in VBE 1024*768*32 mode is not working

Post by glauxosdever »

Hi,

catnikita255 wrote:Ok. And I fixed the problem, it was in the palette, it was old 16-color.
Are the colors displayed correctly now?

16-color?! You were supposedly using VBE! Maybe you meant 16-bit?


Regards,
glauxosdever
Post Reply