Browse Source

Update dgl test code

tags/1.9.4
falkTX 12 years ago
parent
commit
58d5d6900d
19 changed files with 7291 additions and 1 deletions
  1. +3
    -1
      .gitignore
  2. +61
    -0
      source/tests/DGL1.cpp
  3. +3128
    -0
      source/tests/DGL1_Artwork.cpp
  4. +15
    -0
      source/tests/DGL1_Artwork.hpp
  5. BIN
      source/tests/DGL1_Artwork/start-here-kxstudio.png
  6. +221
    -0
      source/tests/DGL2.cpp
  7. +3798
    -0
      source/tests/NekoArtwork.cpp
  8. +65
    -0
      source/tests/NekoArtwork.hpp
  9. BIN
      source/tests/NekoArtwork/background.png
  10. BIN
      source/tests/NekoArtwork/claw1.png
  11. BIN
      source/tests/NekoArtwork/claw2.png
  12. BIN
      source/tests/NekoArtwork/run1.png
  13. BIN
      source/tests/NekoArtwork/run2.png
  14. BIN
      source/tests/NekoArtwork/run3.png
  15. BIN
      source/tests/NekoArtwork/run4.png
  16. BIN
      source/tests/NekoArtwork/scratch1.png
  17. BIN
      source/tests/NekoArtwork/scratch2.png
  18. BIN
      source/tests/NekoArtwork/sit.png
  19. BIN
      source/tests/NekoArtwork/tail.png

+ 3
- 1
.gitignore View File

@@ -67,10 +67,12 @@ data/windows/Carla
data/windows/CarlaControl
source/tests/ANSI
source/tests/CarlaString
source/tests/DGL
source/tests/DGL1
source/tests/DGL2
source/tests/Print
source/tests/RtList
source/tests/Utils
source/tests/dgl-neko-test*

# Docs
doc/CarlaBackend/


+ 61
- 0
source/tests/DGL1.cpp View File

@@ -0,0 +1,61 @@
/*
* Carla Tests
* Copyright (C) 2013 Filipe Coelho <falktx@falktx.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* For a full copy of the GNU General Public License see the GPL.txt file
*/

#include "dgl/Image.hpp"
#include "dgl/StandaloneWindow.hpp"

#include "DGL1_Artwork.hpp"

USE_NAMESPACE_DGL;

class MyWidget : public Widget
{
public:
MyWidget(StandaloneWindow* win)
: Widget(win->getWindow()),
fWindow(win->getWindow())
{
{
using namespace DGL1_Artwork;
fImage.loadFromMemory(start_here_kxstudioData,
Size<int>(start_here_kxstudioWidth, start_here_kxstudioHeight),
GL_BGRA, GL_UNSIGNED_BYTE);
}

fWindow->setSize(fImage.getWidth(), fImage.getHeight());
fWindow->setWindowTitle("DGL Test");
}

protected:
void onDisplay() override
{
fImage.draw();
}

private:
Window* const fWindow;

Image fImage;
};

int main()
{
StandaloneWindow win;
MyWidget widget(&win);
win.exec();
return 0;
}

+ 3128
- 0
source/tests/DGL1_Artwork.cpp
File diff suppressed because it is too large
View File


+ 15
- 0
source/tests/DGL1_Artwork.hpp View File

@@ -0,0 +1,15 @@
/* (Auto-generated binary data file). */

#ifndef BINARY_DGL1_ARTWORK_HPP
#define BINARY_DGL1_ARTWORK_HPP

namespace DGL1_Artwork
{
extern const char* start_here_kxstudioData;
const unsigned int start_here_kxstudioDataSize = 262144;
const unsigned int start_here_kxstudioWidth = 256;
const unsigned int start_here_kxstudioHeight = 256;
}

#endif // BINARY_DGL1_ARTWORK_HPP


BIN
source/tests/DGL1_Artwork/start-here-kxstudio.png View File

Before After
Width: 256  |  Height: 256  |  Size: 61KB

+ 221
- 0
source/tests/DGL2.cpp View File

@@ -0,0 +1,221 @@
/*
* Carla Tests
* Copyright (C) 2013 Filipe Coelho <falktx@falktx.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* For a full copy of the GNU General Public License see the GPL.txt file
*/

#include "dgl/Image.hpp"
#include "dgl/StandaloneWindow.hpp"
#include "CarlaUtils.hpp"

#include "NekoArtwork.hpp"

// this is just a test file!
#include <QtCore/QThread>

USE_NAMESPACE_DGL;

class NekoWidget : public Widget,
QThread
{
public:
NekoWidget(StandaloneWindow* win)
: Widget(win->getWindow()),
fPos(0),
fTimer(0),
fTimerSpeed(20),
fCurAction(kActionNone),
fCurImage(&fImages.sit)
{
// load images
{
using namespace NekoArtwork;

fImages.background.loadFromMemory(backgroundData, backgroundWidth, backgroundHeight, GL_BGR);

#define JOIN(a, b) a ## b
#define LOAD_IMAGE(NAME) fImages.NAME.loadFromMemory(JOIN(NAME, Data), JOIN(NAME, Width), JOIN(NAME, Height));

LOAD_IMAGE(sit)
LOAD_IMAGE(tail)
LOAD_IMAGE(claw1)
LOAD_IMAGE(claw2)
LOAD_IMAGE(scratch1)
LOAD_IMAGE(scratch2)
LOAD_IMAGE(run1)
LOAD_IMAGE(run2)
LOAD_IMAGE(run3)
LOAD_IMAGE(run4)

#undef JOIN
#undef LOAD_IMAGE
}

QThread::start();
}

~NekoWidget()
{
hide();
QThread::quit();
QThread::wait();
}

protected:
void onDisplay() override
{
int x = fPos+118;
int y = -2;

if (fCurImage == &fImages.claw1 || fCurImage == &fImages.claw2)
{
x += 2;
y += 12;
}

fImages.background.draw();
fCurImage->draw(x, y);
}

void idle()
{
if (++fTimer % fTimerSpeed != 0) // target is 25ms
return;

if (fTimer == fTimerSpeed*9)
{
if (fCurAction == kActionNone)
fCurAction = static_cast<Action>(rand() % kActionCount);
else
fCurAction = kActionNone;

fTimer = 0;
}

switch (fCurAction)
{
case kActionNone:
if (fCurImage == &fImages.sit)
fCurImage = &fImages.tail;
else
fCurImage = &fImages.sit;
break;

case kActionClaw:
if (fCurImage == &fImages.claw1)
fCurImage = &fImages.claw2;
else
fCurImage = &fImages.claw1;
break;

case kActionScratch:
if (fCurImage == &fImages.scratch1)
fCurImage = &fImages.scratch2;
else
fCurImage = &fImages.scratch1;
break;

case kActionRunRight:
if (fTimer == 0 && fPos > 20*9)
{
// run the other way
--fTimer;
fCurAction = kActionRunLeft;
idle();
break;
}

fPos += 20;

if (fCurImage == &fImages.run1)
fCurImage = &fImages.run2;
else
fCurImage = &fImages.run1;
break;

case kActionRunLeft:
if (fTimer == 0 && fPos < 20*9)
{
// run the other way
--fTimer;
fCurAction = kActionRunRight;
idle();
break;
}

fPos -= 20;

if (fCurImage == &fImages.run3)
fCurImage = &fImages.run4;
else
fCurImage = &fImages.run3;
break;

case kActionCount:
break;
}

repaint();
}

void run() override
{
while (isVisible())
{
idle();
carla_msleep(10);
}
}

private:
enum Action {
kActionNone, // bounce tail
kActionClaw,
kActionScratch,
kActionRunRight,
kActionRunLeft,
kActionCount
};

struct Images {
Image background;
Image sit;
Image tail;
Image claw1;
Image claw2;
Image scratch1;
Image scratch2;
Image run1;
Image run2;
Image run3;
Image run4;
} fImages;

int fPos;
int fTimer;
int fTimerSpeed;

Action fCurAction;
Image* fCurImage;
};

int main()
{
StandaloneWindow win;
win.setSize(NekoArtwork::backgroundWidth, NekoArtwork::backgroundHeight);
win.setWindowTitle("Neko Test");
NekoWidget widget(&win);
win.exec();
return 0;
}

+ 3798
- 0
source/tests/NekoArtwork.cpp
File diff suppressed because it is too large
View File


+ 65
- 0
source/tests/NekoArtwork.hpp View File

@@ -0,0 +1,65 @@
/* (Auto-generated binary data file). */

#ifndef BINARY_NEKOARTWORK_HPP
#define BINARY_NEKOARTWORK_HPP

namespace NekoArtwork
{
extern const char* backgroundData;
const unsigned int backgroundDataSize = 206064;
const unsigned int backgroundWidth = 636;
const unsigned int backgroundHeight = 108;

extern const char* claw1Data;
const unsigned int claw1DataSize = 4096;
const unsigned int claw1Width = 32;
const unsigned int claw1Height = 32;

extern const char* claw2Data;
const unsigned int claw2DataSize = 4096;
const unsigned int claw2Width = 32;
const unsigned int claw2Height = 32;

extern const char* run1Data;
const unsigned int run1DataSize = 4096;
const unsigned int run1Width = 32;
const unsigned int run1Height = 32;

extern const char* run2Data;
const unsigned int run2DataSize = 4096;
const unsigned int run2Width = 32;
const unsigned int run2Height = 32;

extern const char* run3Data;
const unsigned int run3DataSize = 4096;
const unsigned int run3Width = 32;
const unsigned int run3Height = 32;

extern const char* run4Data;
const unsigned int run4DataSize = 4096;
const unsigned int run4Width = 32;
const unsigned int run4Height = 32;

extern const char* scratch1Data;
const unsigned int scratch1DataSize = 4096;
const unsigned int scratch1Width = 32;
const unsigned int scratch1Height = 32;

extern const char* scratch2Data;
const unsigned int scratch2DataSize = 4096;
const unsigned int scratch2Width = 32;
const unsigned int scratch2Height = 32;

extern const char* sitData;
const unsigned int sitDataSize = 4096;
const unsigned int sitWidth = 32;
const unsigned int sitHeight = 32;

extern const char* tailData;
const unsigned int tailDataSize = 4096;
const unsigned int tailWidth = 32;
const unsigned int tailHeight = 32;
}

#endif // BINARY_NEKOARTWORK_HPP


BIN
source/tests/NekoArtwork/background.png View File

Before After
Width: 636  |  Height: 108  |  Size: 46KB

BIN
source/tests/NekoArtwork/claw1.png View File

Before After
Width: 32  |  Height: 32  |  Size: 359B

BIN
source/tests/NekoArtwork/claw2.png View File

Before After
Width: 32  |  Height: 32  |  Size: 354B

BIN
source/tests/NekoArtwork/run1.png View File

Before After
Width: 32  |  Height: 32  |  Size: 383B

BIN
source/tests/NekoArtwork/run2.png View File

Before After
Width: 32  |  Height: 32  |  Size: 370B

BIN
source/tests/NekoArtwork/run3.png View File

Before After
Width: 32  |  Height: 32  |  Size: 383B

BIN
source/tests/NekoArtwork/run4.png View File

Before After
Width: 32  |  Height: 32  |  Size: 369B

BIN
source/tests/NekoArtwork/scratch1.png View File

Before After
Width: 32  |  Height: 32  |  Size: 375B

BIN
source/tests/NekoArtwork/scratch2.png View File

Before After
Width: 32  |  Height: 32  |  Size: 348B

BIN
source/tests/NekoArtwork/sit.png View File

Before After
Width: 32  |  Height: 32  |  Size: 347B

BIN
source/tests/NekoArtwork/tail.png View File

Before After
Width: 32  |  Height: 32  |  Size: 353B

Loading…
Cancel
Save