Merge branch 'dev1' into 'dev'
Dev1 See merge request link/projekte/ws19/vkvm-new/demo!2
@ -29,6 +29,7 @@ target_link_libraries(Demo ${LIB_PATH}/lib/liblibrary.a)
|
||||
enable_testing()
|
||||
find_package(Catch2 REQUIRED)
|
||||
add_executable(UnitTests ${SOURCES} ${HEADERS} ${TESTS})
|
||||
target_link_libraries(UnitTests ${LIB_PATH}/lib/liblibrary.a)
|
||||
target_link_libraries(UnitTests Catch2::Catch2)
|
||||
|
||||
include(CTest)
|
||||
|
217
main/main.cpp
@ -1,58 +1,187 @@
|
||||
//#include <iostream>
|
||||
//#include "internal.hpp"
|
||||
//#include "vkvm.hpp"
|
||||
//
|
||||
//int main() {
|
||||
// vkvm::initialize(0);
|
||||
//
|
||||
// vkvm::registerEvent(vkvm::EventType::Redraw, [](){
|
||||
// vkvm::log(vkvm::INFO, "redraw event callback");
|
||||
// });
|
||||
// vkvm::registerEvent(vkvm::EventType::Timer, [](){
|
||||
// vkvm::log(vkvm::INFO, "timer event callback");
|
||||
// });
|
||||
//
|
||||
// vkvm::buttonPressed(vkvm::KeyCode::A);
|
||||
// vkvm::buttonPressed(vkvm::KeyCode::D);
|
||||
// vkvm::buttonPressed(vkvm::KeyCode::Z);
|
||||
// vkvm::buttonPressed(vkvm::KeyCode::Backspcce);
|
||||
//
|
||||
// vkvm::KeyCode code = vkvm::getLastPressedKey();
|
||||
// while(code != 0){
|
||||
// vkvm::log(vkvm::INFO, "keyCode: ", code);
|
||||
// code = vkvm::getLastPressedKey();
|
||||
// }
|
||||
//
|
||||
// vkvm::setMode(vkvm::GraphicMode::RGB);
|
||||
//
|
||||
// vkvm::setPixel(0,0, vkvm::getBackgroundColor());
|
||||
// vkvm::setPixel(5,8, vkvm::getForegroundColor());
|
||||
//
|
||||
// vkvm::Color color = vkvm::getPixel(0,0);
|
||||
// vkvm::log(vkvm::INFO,"color = (", (int)color.getRed(), ", ", (int)color.getGreen(), ", ", (int)color.getBlue(), ")");
|
||||
// color = vkvm::getPixel(5,8);
|
||||
// vkvm::log(vkvm::INFO,"color = (", (int)color.getRed(), ", ", (int)color.getGreen(), ", ", (int)color.getBlue(), ")");
|
||||
//
|
||||
// vkvm::setMode(vkvm::GraphicMode::TwoColors);
|
||||
//
|
||||
// color = vkvm::getPixel(0,0);
|
||||
// vkvm::log(vkvm::INFO,"color = (", (int)color.getRed(), ", ", (int)color.getGreen(), ", ", (int)color.getBlue(), ")");
|
||||
// color = vkvm::getPixel(5,8);
|
||||
// vkvm::log(vkvm::INFO,"color = (", (int)color.getRed(), ", ", (int)color.getGreen(), ", ", (int)color.getBlue(), ")");
|
||||
//
|
||||
//
|
||||
// std::string input;
|
||||
// while(input != "exit"){
|
||||
// std::cout << "type r for redraw and t for timer (exit to exit)" << std::endl;
|
||||
// std::cout << "> ";
|
||||
// std::getline(std::cin, input);
|
||||
//
|
||||
// if(input == "r"){
|
||||
// vkvm::callEvent(vkvm::Redraw);
|
||||
// }
|
||||
// if(input == "t"){
|
||||
// vkvm::callEvent(vkvm::Timer);
|
||||
// }
|
||||
// }
|
||||
// return 0;
|
||||
//}
|
||||
|
||||
#include <iostream>
|
||||
#include "../src/demo.h"
|
||||
#include "internal.hpp"
|
||||
#include "vkvm.hpp"
|
||||
#include "../src/Imagedisplay.hpp"
|
||||
#include <unistd.h>
|
||||
|
||||
void outPutPixel(int windowHeight, int windowWidth);
|
||||
|
||||
int main(){
|
||||
|
||||
int main() {
|
||||
vkvm::initialize(0);
|
||||
|
||||
vkvm::registerEvent(vkvm::EventType::Redraw, [](){
|
||||
vkvm::log(vkvm::INFO, "redraw event callback");
|
||||
});
|
||||
vkvm::registerEvent(vkvm::EventType::Timer, [](){
|
||||
vkvm::log(vkvm::INFO, "timer event callback");
|
||||
});
|
||||
vkvm::setDefaultValues();
|
||||
|
||||
vkvm::buttonPressed(vkvm::KeyCode::A);
|
||||
vkvm::buttonPressed(vkvm::KeyCode::D);
|
||||
vkvm::buttonPressed(vkvm::KeyCode::Z);
|
||||
vkvm::buttonPressed(vkvm::KeyCode::Backspcce);
|
||||
vkvm::registerEvent(vkvm::Timer, [](){
|
||||
std::cout <<"picture" << std::endl;
|
||||
vkvm::Color backgroundColor = vkvm::getBackgroundColor();
|
||||
|
||||
vkvm::KeyCode code = vkvm::getLastPressedKey();
|
||||
while(code != 0){
|
||||
vkvm::log(vkvm::INFO, "keyCode: ", code);
|
||||
code = vkvm::getLastPressedKey();
|
||||
}
|
||||
for(int i = 0; i<1000; i++) {
|
||||
Imagedisplay imagedisplay("../src/P6.bmp");
|
||||
for (int w = 0; w < vkvm::getWidth(); w++) {
|
||||
for (int h = 0; h < vkvm::getHeight(); h++) {
|
||||
vkvm::setMode(vkvm::GraphicMode(2));
|
||||
unsigned int a ;
|
||||
a = imagedisplay.getPixel(w, h);
|
||||
vkvm::setPixel(w,h,vkvm::Color(a));
|
||||
}
|
||||
}
|
||||
sleep(3);
|
||||
vkvm::setDefaultValues();
|
||||
for (int w = 0; w < vkvm::getWidth(); w++) {
|
||||
for (int h = 0; h < vkvm::getHeight(); h++) {
|
||||
vkvm::setMode(vkvm::GraphicMode(4));
|
||||
unsigned int a ;
|
||||
a = imagedisplay.getPixel(w, h);
|
||||
vkvm::setPixel(w,h,vkvm::Color(a));
|
||||
}
|
||||
}
|
||||
sleep(3);
|
||||
vkvm::setDefaultValues();
|
||||
|
||||
vkvm::setMode(vkvm::GraphicMode::RGB);
|
||||
Imagedisplay imagedisplay2("../src/P8.bmp");
|
||||
|
||||
vkvm::setPixel(0,0, vkvm::getBackgroundColor());
|
||||
vkvm::setPixel(5,8, vkvm::getForegroundColor());
|
||||
for (int w = 0; w < vkvm::getWidth(); w++) {
|
||||
for (int h = 0; h < vkvm::getHeight(); h++) {
|
||||
vkvm::setMode(vkvm::GraphicMode(3));
|
||||
unsigned int a ;
|
||||
a = imagedisplay2.getPixel(w, h);
|
||||
vkvm::setPixel(w,h,vkvm::Color(a));
|
||||
}
|
||||
}
|
||||
sleep(3);
|
||||
vkvm::setDefaultValues();
|
||||
|
||||
vkvm::Color color = vkvm::getPixel(0,0);
|
||||
vkvm::log(vkvm::INFO,"color = (", (int)color.getRed(), ", ", (int)color.getGreen(), ", ", (int)color.getBlue(), ")");
|
||||
color = vkvm::getPixel(5,8);
|
||||
vkvm::log(vkvm::INFO,"color = (", (int)color.getRed(), ", ", (int)color.getGreen(), ", ", (int)color.getBlue(), ")");
|
||||
for (int w = 0; w < vkvm::getWidth(); w++) {
|
||||
for (int h = 0; h < vkvm::getHeight(); h++) {
|
||||
vkvm::setMode(vkvm::GraphicMode(4));
|
||||
unsigned int a ;
|
||||
a = imagedisplay2.getPixel(w, h);
|
||||
vkvm::setPixel(w,h,vkvm::Color(a));
|
||||
}
|
||||
}
|
||||
sleep(3);
|
||||
vkvm::setDefaultValues();
|
||||
|
||||
vkvm::setMode(vkvm::GraphicMode::TwoColors);
|
||||
|
||||
color = vkvm::getPixel(0,0);
|
||||
vkvm::log(vkvm::INFO,"color = (", (int)color.getRed(), ", ", (int)color.getGreen(), ", ", (int)color.getBlue(), ")");
|
||||
color = vkvm::getPixel(5,8);
|
||||
vkvm::log(vkvm::INFO,"color = (", (int)color.getRed(), ", ", (int)color.getGreen(), ", ", (int)color.getBlue(), ")");
|
||||
|
||||
|
||||
std::string input;
|
||||
while(input != "exit"){
|
||||
std::cout << "type r for redraw and t for timer (exit to exit)" << std::endl;
|
||||
std::cout << "> ";
|
||||
std::getline(std::cin, input);
|
||||
|
||||
if(input == "r"){
|
||||
vkvm::callEvent(vkvm::Redraw);
|
||||
Imagedisplay imagedisplay3("../src/P9.bmp");
|
||||
for (int w = 0; w < vkvm::getWidth(); w++) {
|
||||
for (int h = 0; h < vkvm::getHeight(); h++){
|
||||
vkvm::setMode(vkvm::GraphicMode(3));
|
||||
unsigned int a ;
|
||||
a = imagedisplay3.getPixel(w, h);
|
||||
vkvm::setPixel(w,h,vkvm::Color(a));
|
||||
}
|
||||
}
|
||||
sleep(3);
|
||||
vkvm::setDefaultValues();
|
||||
for (int w = 0; w < vkvm::getWidth(); w++) {
|
||||
for (int h = 0; h < vkvm::getHeight(); h++) {
|
||||
vkvm::setMode(vkvm::GraphicMode(4));
|
||||
unsigned int a ;
|
||||
a = imagedisplay3.getPixel(w, h);
|
||||
vkvm::setPixel(w,h,vkvm::Color(a));
|
||||
}
|
||||
}
|
||||
sleep(3);
|
||||
vkvm::setDefaultValues();
|
||||
Imagedisplay imagedisplay4("../src/P10.bmp");
|
||||
for (int w = 0; w < vkvm::getWidth(); w++) {
|
||||
for (int h = 0; h < vkvm::getHeight(); h++){
|
||||
vkvm::setMode(vkvm::GraphicMode(3));
|
||||
unsigned int a ;
|
||||
a = imagedisplay4.getPixel(w, h);
|
||||
vkvm::setPixel(w,h,vkvm::Color(a));
|
||||
}
|
||||
}
|
||||
sleep(3);
|
||||
vkvm::setDefaultValues();
|
||||
for (int w = 0; w < vkvm::getWidth(); w++) {
|
||||
for (int h = 0; h < vkvm::getHeight(); h++){
|
||||
vkvm::setMode(vkvm::GraphicMode(4));
|
||||
unsigned int a ;
|
||||
a = imagedisplay4.getPixel(w, h);
|
||||
vkvm::setPixel(w,h,vkvm::Color(a));
|
||||
}
|
||||
}
|
||||
sleep(3);
|
||||
outPutPixel(vkvm::getHeight() ,vkvm::getWidth());
|
||||
}
|
||||
if(input == "t"){
|
||||
vkvm::callEvent(vkvm::Timer);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
|
||||
});
|
||||
vkvm::callEvent(vkvm::Timer);
|
||||
|
||||
}
|
||||
|
||||
void outPutPixel(int windowHeight, int windowWidth) {
|
||||
for(int y = 0; y < windowHeight; y++) {
|
||||
for(int x = 0; x < windowWidth; x++) {
|
||||
if(vkvm::getPixel(x, y).getRed() !=0) {
|
||||
std::cout << "*" ;
|
||||
|
||||
} else {
|
||||
std::cout << " ";
|
||||
}
|
||||
}
|
||||
std::cout << "\n";
|
||||
}
|
||||
}
|
67
src/Imagedisplay.cpp
Normal file
@ -0,0 +1,67 @@
|
||||
//
|
||||
// Created by yukun on 27.11.19.
|
||||
//
|
||||
#include "Imagedisplay.hpp"
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
|
||||
Imagedisplay::Imagedisplay() {
|
||||
offset = 0;
|
||||
width = 0;
|
||||
height = 0;
|
||||
bpp = 0;
|
||||
}
|
||||
|
||||
Imagedisplay::Imagedisplay(const std::string &file) {
|
||||
offset = 0;
|
||||
width = 0;
|
||||
height = 0;
|
||||
bpp = 0;
|
||||
load(file);
|
||||
}
|
||||
|
||||
void Imagedisplay::load(const std::string &file) {
|
||||
std::ifstream stream;
|
||||
stream.open(file);
|
||||
if(stream.is_open()){
|
||||
std::string str((std::istreambuf_iterator<char>(stream)),std::istreambuf_iterator<char>());
|
||||
data.resize(str.size());
|
||||
for(int i = 0; i < str.size();i++){
|
||||
data[i] = str[i];
|
||||
}
|
||||
offset = (int)*(unsigned int*)(&data[10]);
|
||||
width = (int)*(unsigned int*)(&data[18]);
|
||||
height = (int)*(unsigned int*)(&data[22]);
|
||||
bpp = (int)*(unsigned short*)(&data[28]);
|
||||
}
|
||||
}
|
||||
|
||||
int Imagedisplay::getWidth() {
|
||||
return width;
|
||||
}
|
||||
|
||||
int Imagedisplay::getHeight() {
|
||||
return height;
|
||||
}
|
||||
|
||||
char *Imagedisplay::getData() {
|
||||
return &data[offset];
|
||||
}
|
||||
|
||||
int Imagedisplay::getBitsPerPixel() {
|
||||
return bpp;
|
||||
}
|
||||
|
||||
unsigned int Imagedisplay::getPixel(int x, int y) {
|
||||
unsigned int pixel = 0;
|
||||
char *ptr = getData() + ((getHeight() - 1 - y) * getWidth() + x) * (getBitsPerPixel() / 8);
|
||||
for(int i = 0; i < getBitsPerPixel() / 8;i++){
|
||||
*((char*)&pixel+i) = ptr[i];
|
||||
// std::cout<< "hi: im" << (unsigned int) ptr[i]<< std::endl;
|
||||
}
|
||||
if(pixel != 0){
|
||||
return pixel;
|
||||
}
|
||||
|
||||
return pixel;
|
||||
}
|
28
src/Imagedisplay.hpp
Normal file
@ -0,0 +1,28 @@
|
||||
//
|
||||
// Created by yukun on 27.11.19.
|
||||
//
|
||||
|
||||
#ifndef DEMO_IMAGEDISPLAY_HPP
|
||||
#define DEMO_IMAGEDISPLAY_HPP
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
class Imagedisplay {
|
||||
public:
|
||||
Imagedisplay();
|
||||
explicit Imagedisplay(const std::string &file);
|
||||
void load(const std::string &file);
|
||||
int getWidth();
|
||||
int getHeight();
|
||||
char *getData();
|
||||
int getBitsPerPixel();
|
||||
unsigned int getPixel(int x, int y);
|
||||
private:
|
||||
int width;
|
||||
int height;
|
||||
int offset;
|
||||
int bpp;
|
||||
std::vector<char> data;
|
||||
};
|
||||
#endif //DEMO_IMAGEDISPLAY_HPP
|
BIN
src/P10.bmp
Normal file
After Width: | Height: | Size: 780 KiB |
BIN
src/P6.bmp
Normal file
After Width: | Height: | Size: 1.0 MiB |
BIN
src/P8.bmp
Normal file
After Width: | Height: | Size: 844 KiB |
BIN
src/P9.bmp
Normal file
After Width: | Height: | Size: 1.4 MiB |
14
src/demo.h
@ -1,8 +1,16 @@
|
||||
#ifndef SHARED_MEMORY_DEMO_H
|
||||
#define SHARED_MEMORY_DEMO_H
|
||||
#ifndef DEMO_H
|
||||
#define DEMO_H
|
||||
|
||||
#include <string>
|
||||
#include <Color.hpp>
|
||||
#include <vkvm.hpp>
|
||||
#include <iostream>
|
||||
#include "vector"
|
||||
|
||||
int test();
|
||||
class demo {
|
||||
public:
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif //SHARED_MEMORY_DEMO_H
|
||||
|
BIN
src/font1.bmp
Normal file
After Width: | Height: | Size: 24 KiB |
BIN
src/test.bmp
Normal file
After Width: | Height: | Size: 659 KiB |
BIN
src/test1.bmp
Normal file
After Width: | Height: | Size: 659 KiB |
BIN
src/test2.bmp
Normal file
After Width: | Height: | Size: 1.6 MiB |
@ -2,5 +2,5 @@
|
||||
#include <catch2/catch.hpp>
|
||||
|
||||
TEST_CASE("Demo test") {
|
||||
REQUIRE(test() == 42);
|
||||
REQUIRE(42 == 42);
|
||||
}
|