Рисование специфических символов ASCII вызывает глюки экрана в круговой структуре для RPIC++

Программы на C++. Форум разработчиков
Ответить Пред. темаСлед. тема
Anonymous
 Рисование специфических символов ASCII вызывает глюки экрана в круговой структуре для RPI

Сообщение Anonymous »

Я второкурсник в колледже, работающий над личным проектом, включающим встроенный RPI и HDMI. Когда я рисую 32 или более из определенных символов, вывод видео выводит для всех пикселей после символов. Шрифт, который я использую, представляет собой шрифт с фиксированной шириной (2-байтовой) растровой картой с каждым символом, представленным в виде персонажей рядов U16, наиболее значимым битом в первую очередь. Персонажи, которые вызывают сбой, представляются (я не проверял каждого символа, но проверял диапазоны символов): все числа,?, @, Все заглавные буквы и строчные буквы a. Я проверил символы между этими диапазонами (например,: и `), и эти символы не вызывают сбой.

Код: Выделить всё

void drawChar(MemoryBuffer& buffer, const Font& font, char character, u32 posX, u32 posY, u32 color)
{
// y represents position in character
for(u32 y = 0; y < font.characterHeight; ++y)
{
// Current line is character * characterHeight + y because char*charHeight gets you to the correct array and + y gets you to the correct line in the array
u16 currLine = font.font[character * font.characterHeight + y];
// x represents position in character
for(u32 x = 0; x < font.characterWidth; ++x)
{
// currLine anded with 1 shifted over characterWidth - 1 - x bits because 1 
void MemoryBuffer::DrawPixel(u32 x, u32 y, u32 color)
{
m_BufferPointer[y * (m_Pitch / 4) + x] = color;
}
< /code>
Мне не ясно, что вызывает этот сбой, поэтому помощи с причиной или возможным исправлением было бы очень оценено! (Я прикрепил изображение глюка) он маленький, как я мог.#ifndef _kernel_h
#define _kernel_h

#include "HDMIDraw.h"
#include 
#include 

enum TShutdownMode
{
ShutdownNone,
ShutdownHalt,
ShutdownReboot
};

class CKernel
{
public:
CKernel (void);
~CKernel (void);

boolean Initialize (void);

TShutdownMode Run (void);

private:
CBcmFrameBuffer m_FrameBuffer;
MemoryBuffer m_VirtBuffer;
};

#endif
< /code>
kernel.cpp:
#include "kernel.h"
#include "text.h"

const Font FontTerminus = {.font= &font16x32norm[0][0], .characterWidth = 16, .characterHeight = 32};

CKernel::CKernel (void)
: m_FrameBuffer(0, 0, 32)
{
}

CKernel::~CKernel (void)
{
}

boolean CKernel::Initialize (void)
{
if (!m_FrameBuffer.Initialize())
return FALSE;

u32 width = m_FrameBuffer.GetWidth();
u32 height = m_FrameBuffer.GetHeight();
u32 pitch = m_FrameBuffer.GetPitch();

m_VirtBuffer.Allocate(width, height, pitch);

return TRUE;
}

TShutdownMode CKernel::Run (void)
{

// Display loop
while (true)
{
// Fill screen white (blank screen at start of loop)
m_VirtBuffer.FillScreen(0xFFFFFF);

// Draw a colored box, and test string
m_VirtBuffer.DrawRect(0, 0, m_VirtBuffer.GetWidth()/2, m_VirtBuffer.GetHeight()/2, 0x00FF00);
m_VirtBuffer.DrawString(FontTerminus, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", 0, 0, 0x000000);

// Copy m_VirtBuffer (the draw buffer) to m_FrameBuffer (the display buffer), then wait for vsync to avoid tearing
m_VirtBuffer.CopyToFrameBuffer(m_FrameBuffer);
m_FrameBuffer.WaitForVerticalSync();  // Ensure clean display
}

return ShutdownHalt;
}
< /code>
hdmidraw.h:
#ifndef _hdmi_draw
#define _hdmi_draw

#include 
#include 

struct Font;
struct Bitmap
{
const u32* pixelMap;
const u32 width;
const u32 height;

constexpr Bitmap(const u32* pixels, u32 w, u32 h)
: pixelMap(pixels), width(w), height(h) {}
};

class MemoryBuffer {
public:
MemoryBuffer();
~MemoryBuffer();
void Allocate(u32 Width, u32 Height, u32 Pitch);

u32* GetBuffer()       { return m_BufferPointer; }
u32  GetPitch()  const { return m_Pitch; }
u32  GetWidth()  const { return m_Width; }
u32  GetHeight() const { return m_Height; }

void DrawPixel(u32 x, u32 y, u32 color);
void FillScreen(u32 color);
void DrawRect(u32 x1, u32 y1, u32 x2, u32 y2, u32 color);
void DrawString(const Font& font, const char* string, u32 posX, u32 posY, u32 color);
void CopyToFrameBuffer(CBcmFrameBuffer&  frameBuffer);

private:
u32* m_BufferPointer{nullptr};
u32  m_Width{0};
u32  m_Height{0};
u32  m_Pitch{0};
u32  m_Size{0};
};

#endif
< /code>
hdmidraw.cpp:
#include "HDMIDraw.h"
#include "text.h"
#include 

MemoryBuffer::MemoryBuffer()
: m_BufferPointer(nullptr), m_Width(0), m_Height(0), m_Pitch(0), m_Size(0)
{
}

MemoryBuffer::~MemoryBuffer()
{
delete[] m_BufferPointer;
}

// Method to allocate the buffer in memory and set fields m_Width, m_Height, and m_Pitch
void MemoryBuffer::Allocate(u32 Width, u32 Height, u32 Pitch)
{
m_Width = Width;
m_Height = Height;
m_Pitch = Pitch;

m_Size = Height * Pitch;
m_BufferPointer = new u32[(Pitch / 4) * Height];
}

// Method to draw pixel at x, y, in color
void MemoryBuffer::DrawPixel(u32 x, u32 y, u32 color)
{
// y * (m_Pitch / 4) because m_Pitch is bytes per row, where each pixel is 4 bytes.  + x gets to x position in row
m_BufferPointer[y * (m_Pitch / 4) + x] = color;
}

// Method to draw rectangle from x1, y1 to x2, y2 in color
void MemoryBuffer::DrawRect(u32 x1, u32 y1, u32 x2, u32 y2, u32 color)
{
for (unsigned y = y1; y < y2; ++y)
{
for (unsigned x = x1; x < x2; ++x)
{
DrawPixel(x, y, color);
}
}
}

// Method to fill screen with color
void MemoryBuffer::FillScreen(u32 color)
{
for (u32 i = 0; i < m_Size; ++i)
{
m_BufferPointer[i] = color;
}
}

// Method to draw string at posX, posY in color, simply calls drawString with reference to this
void MemoryBuffer::DrawString(const Font& font, const char* string, u32 posX, u32 posY, u32 color)
{
drawString(*this, font, string, posX, posY, color);
}

// Method to copy the buffer in memory to a provided frameBuffer
void MemoryBuffer::CopyToFrameBuffer(CBcmFrameBuffer& frameBuffer)
{
memcpy(reinterpret_cast(frameBuffer.GetBuffer()), m_BufferPointer, m_Pitch * m_Height);
}
< /code>
xtext.h:
#ifndef _text_h
#define _text_h

#include "terminusFont.h"
#include "HDMIDraw.h"
#include 
#include 
struct Font
{
const u16* font;
u32 characterWidth, characterHeight;
};

void drawChar(MemoryBuffer& buffer, const Font& font, char character, u32 posX, u32 posY, u32 color);
void drawString(MemoryBuffer& buffer, const Font& font, const char* string, u32 posX, u32 posY, u32 color);

#endif
< /code>
xtext.cpp:
#include "text.h"
#include "terminusFont.h"

// Function to draw a given character in a given font and color at a given position
void drawChar(MemoryBuffer& buffer, const Font& font, char character, u32 posX, u32 posY, u32 color)
{
// y represents position in character
for(u32 y = 0; y < font.characterHeight; ++y)
{
// Current line is character * characterHeight + y because char*charHeight gets you to the correct array and + y gets you to the correct line in the array
u16 currLine = font.font[character * font.characterHeight + y];
// x represents position in character
for(u32 x = 0; x < font.characterWidth; ++x)
{
// currLine anded with 1 shifted over characterWidth - 1 - x bits because 1 
CIRCLEHOME = ../..

OBJS = main.o kernel.o HDMIDraw.o text.o

LIBS = $(CIRCLEHOME)/lib/libcircle.a

# Override dependency checking
override CHECK_DEPS := 1

# Include Rules.mk *before* your rules, so you can override them
include $(CIRCLEHOME)/Rules.mk

# Correct dependency generation using MMD
CPPFLAGS += -MMD -MP

# Include dependency files
-include $(DEPS)
Вот ссылка на terminusfont.h https://pastebin.com/aggnjulv (он был слишком большой, чтобы вписаться в тело). Каталог проекта находится под кругом/образец.

Подробнее здесь: https://stackoverflow.com/questions/796 ... mework-for
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

Вернуться в «C++»