Replies: 3 comments 2 replies
-
🤷
eepp has its own methods to draw basically anything in 2D coordinates, but it's a huge library so I cannot give you many details, you'll have to read the examples. Here's a simple example using two different methods, Primitives class contains many facilities to draw simple primitives (lines, circles, rectangles, etc). It's an abstraction of the second method, the BatchRenderer. #include <eepp/ee.hpp>
EE_MAIN_FUNC int main( int, char*[] ) {
auto win = Engine::instance()->createWindow( WindowSettings( 960, 640, "eepp - Empty Window" ),
ContextSettings( true ) );
if ( win->isOpen() ) {
win->setClearColor( RGB( 255, 255, 255 ) );
Float frequency = 0.025f;
win->runMainLoop( [win, &frequency] {
win->clear();
win->getInput()->update();
if ( win->getInput()->isKeyDown( KEY_ESCAPE ) )
win->close();
else if ( win->getInput()->isKeyDown( KEY_UP ) )
frequency += win->getElapsed().asSeconds() * 0.1f;
else if ( win->getInput()->isKeyDown( KEY_DOWN ) )
frequency -= win->getElapsed().asSeconds() * 0.1f;
Sizef size = win->getSize().asFloat();
Float centerY = size.getHeight() * 0.5f;
Float amplitude = size.getHeight() / 2 * 0.5f;
// Using batch renderer
BatchRenderer br;
br.lineStripSetColor( Color::Red );
for ( Float x = 0; x < size.getWidth(); x++ )
br.batchLineStrip( x, amplitude * std::sin( frequency * x ) + centerY );
br.draw();
// Using Primitives class
Primitives p;
p.setColor( Color::Blue );
for ( Float x = 0; x < size.getWidth(); x++ ) {
Vector2f p1{ x, -amplitude * std::sin( frequency * x ) + centerY };
Vector2f p2{ x + 1, -amplitude * std::sin( frequency * ( x + 1 ) ) + centerY };
p.drawLine( { p1, p2 } );
}
win->display();
} );
}
Engine::destroySingleton();
return EXIT_SUCCESS;
} |
Beta Was this translation helpful? Give feedback.
-
How can I add a label to show the current frequency? |
Beta Was this translation helpful? Give feedback.
-
How would it look like if using the UI module? Is drawing the sine wave using the UI module different from when not using it? |
Beta Was this translation helpful? Give feedback.
-
This example draws a circle but isn't a sine wave more cool?
https://github.com/SpartanJ/eepp/blob/develop/src/examples/empty_window/empty_window.cpp
I'm basically have no knowledge of computer graphics and OpenGL. Don't tell me that I need to dive into OpenGL, pls.
Beta Was this translation helpful? Give feedback.
All reactions