There is no OpenGL library in Sketch => Import Library or in Sketch => Import Library => Add Library in Processing 3.
Where can I find it?
Starting from Processing 2.0, OpenGL is a part of the core (https://github.com/processing/processing/wiki/OpenGL-Issues).
So eg this:
void setup(){
size(640, 480, OPENGL);
bezier(20, 20, 50, 10, 80, 100, 30, 200);
}
should work right away.
Related
I'm working on a little project using C++ and Allegro 5, my question is
Is there a way to draw antialiased primitives to a bitmap using Allegro 5?
I mean I'm using this function
void draw_to_gameBuffer(ALLEGRO_BITMAP *&gameBuffer, ALLEGRO_DISPLAY *&display)
{
static float x = 0;
al_set_target_bitmap(gameBuffer);
al_draw_filled_rectangle(0,0, 350, 622, al_map_rgb(130, 80, 120));
al_draw_filled_circle(x, 200, 100, al_map_rgb(12, 138, 129));
al_draw_filled_triangle(0, 0, 100, 0, 50, 100, al_map_rgb(12, 138, 129));
x += 2.7;
if(x > 350 + 100)
x = -250;
al_set_target_backbuffer(display);
}
to draw a cicle and a triangle (testing purposes) over a target bitmap as shown, on the project display options I have
al_set_new_display_option(ALLEGRO_SAMPLE_BUFFERS, 4, ALLEGRO_SUGGEST);
al_set_new_display_option(ALLEGRO_SAMPLES, 8, ALLEGRO_SUGGEST);
to enable antialiasing, the problem is that all primitives rendered on the gameBuffer have jaggies but the primitives rendered outside the gameBuffer are perfectly smooth, how can I solve that? Or is there a way to do what I'm trying to do and get smooth primitives drawn on the gameBuffer?
It seems that Allegro 5 has some experimental features that can be enabled defining this macro (before defining any allegro header):
#define ALLEGRO_UNSTABLE
With this macro enabled we are able to create a bitmap to draw anything we want and do whatever we want with the bitmap, yes we can do this without enabling the ALLEGRO_UNSTABLE macro but there's this new procedure called:
al_set_new_bitmap_samples(int numberOfSamplesDesired);
that defines how many samples we want in a newly created bitmap, "the downside" of this implementation is that it's only going to work with OpenGl so... we need to force OpenGl (Windows only) to see this new feature working and, how do we put this together and draw antialiased primitives over bitmaps?
first of all, we need to define the ALLEGRO_UNSTABLE macro
#define ALLEGRO_UNSTABLE
then we need to add some allegro headers (the ones we need)
#include <allegro5/allegro.h>
#include <allegro5/allegro_primitives.h>
after this we need to define a bitmap
ALLEGRO_BITMAP *buffer = nullptr;
now we enable OpenGl and the flags we want and the display options
al_set_new_display_flags(ALLEGRO_WINDOWED | ALLEGRO_RESIZABLE | ALLEGRO_OPENGL);
al_set_new_display_option(ALLEGRO_SAMPLE_BUFFERS, 2, ALLEGRO_SUGGEST); //antialias stuff
al_set_new_display_option(ALLEGRO_SAMPLES, 4, ALLEGRO_SUGGEST); //antialias stuff
to create our bitmap we first call the experimental procedure then create our bitmap
al_set_new_bitmap_samples(4);
buffer = al_create_bitmap(bufferWidth, bufferHeight);
4 samples as an example (lol), to draw to the bitmap we use a procedure like this
void draw_to_buffer(ALLEGRO_BITMAP *&buffer, ALLEGRO_DISPLAY *&display)
{
al_set_target_bitmap(buffer);
al_clear_to_color(al_map_rgb(0, 0, 0));
//anything you want to draw to the bitmap
al_set_target_backbuffer(display);
}
now we just need to draw our bitmap the way we usually draw bitmaps on screen
al_draw_bitmap(buffer, 0, 0, 0);
and that's pretty much it, if you have issues or questions with this implementation, yo can look at my post in the Allegro forums where I got the help of many lovely allegro users that taught me a lot without knowing.
my post in the Allegro forum
I'm working on a nice open-source project that I hope to release, however I'm having some trouble with a child window not redrawing after being damaged. Please see this image for details:
Here is the code I'm using to display this:
void showMessageWindow (std::string strMessage, std::string strTitle)
{
Fl_Window* msgWin = new Fl_Window(400, 255, NULL);
if (strTitle == "")
msgWin->label("Window Title");
msgWin->box(FL_BORDER_FRAME);
msgWin->set_non_modal();
Fl_PNG_Image* img = new Fl_PNG_Image("/home/obaker/Pictures/info-icon.png");
Fl_Box* ibox = new Fl_Box(20, 20, 48, 48);
ibox->image(img);
Fl_Multiline_Output* mOut = new Fl_Multiline_Output(90, 20, 275, 175, NULL);
mOut->box(FL_NO_BOX);
mOut->wrap(true);
mOut->readonly(true);
mOut->cursor_color(FL_BACKGROUND_COLOR);
mOut->value(strdup(strMessage.c_str()));
Fl_Button* btn = new Fl_Button(150, 210, 100, 35, "OK");
btn->box(FL_GTK_UP_BOX);
btn->shortcut(FL_Enter);
btn->callback(msgBoxClose, msgWin);
msgWin->add(ibox);
msgWin->add(mOut);
msgWin->add(btn);
msgWin->show();
}
I have tried using Fl_Double_Window instead of Fl_Window and it looks even worse:
As 'edgy' and 'cool' as that might look, it's not appropriate for my project. :-)
I'm developing and testing on Debian Linux 8, 64-bit, AMD Radeon HD 6670 video card, 8 GB RAM. The Debian-provided version of FLTK is 1.3 (1.3.2-6).
The parent window is an Fl_Double_Window and it redraws itself just fine.
Is there anything anyone could recommend to force this child window to redraw itself when it's damaged?
Thank you in advance! :-)
After guidance from Chris on the FLTK forums, I was able to resolve this issue.
The changes necessary are:
msgWin->box(FL_BORDER_BOX)
instead of
msgWin->box(FL_BORDER_FRAME)
"FL_NO_BOX for output may also lead to drawing artifacts. Better
set the outputs background color to the windows background color:"
mOut->box(FL_FLAT_BOX);
mOut->color(msgWin->color());
Thank you for all of your help! :-)
I'm new to allegro 5. I'm currently writing a simple 2D game in C++.
I used to use Allegro 4 but there was no major support for .PNG images so I changed it. The problem is that in Allegro 4 I could easily create a double buffer for my sprites so they do not flicker nor blink while moving. In allegro 5 there is just "al_draw_bitmap" function which does not let us give any buffer for an argument.
This part of my code looks like this:
al_draw_bitmap(image[0],poz_x,poz_y,0);
al_draw_bitmap(platf, 0, 400, 0);
al_draw_bitmap(p1, poz_p1x, poz_p1y, 0);
al_draw_bitmap(chmurka, 50, 50, 0);
al_flip_display();
al_clear_to_color(al_map_rgb(0,0,0));
I can't find any solution on the internet.
I would be really pleased if you could help me.
I use QGLWidget to draw my Graphics in QT, and I need to render some text inside my widget.
The problem is after some time, it turns from:
Fine version http://imageshack.com/a/img823/867/9ycf.png
to this:
Bugged version http://imageshack.com/a/img842/1774/57zs.png
And my code looks like this:
glPushMatrix();
qglColor(Qt::white);
renderText(-29, 11.0, -8, "Tablica wyników", QFont("Arial", 12, QFont::Light));
...
glPopMatrix();
What's wrong with that code/function?
I am currently crosscompiling a Sprite Engine under mingw.
Therefore i have 2 Questions.
The behavior of SDL is Emulated by Emscripten through the WebGL Layer.
i don't even have to link the SDL libraries when compiling with emcc.
Question is:
If i initalize my App Like this:
if(SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO) == -1)return -1;
SDL_Surface *screen= SDL_SetVideoMode(640, 480, 24, SDL_SWSURFACE);
SDL_FillRect(screen, 0, SDL_MapRGB(screen->format, 255, 0, 0));
SDL_Flip(screen);
then i am NOT able to put text into a textfield of the Browser, but i am getting the SDL_Events.
All other Browser Inputs like checkboxes or selectboxes are working.
If initialize my App like this (Emscripten works also without SDL_Init!):
SDL_Surface *screen= SDL_SetVideoMode(640, 480, 24, SDL_HWSURFACE);
SDL_FillRect(screen, 0, SDL_MapRGB(screen->format, 255, 0, 0));
SDL_Flip(screen);
then i am able to put tet into the browser textfield but i am not getting SDL_Events.
Is there a workaround to get the Browser Text Input Fields and SDL_Events working?
Question
This line of code compiled on my WIN32 System fills the screen blue
SDL_FillRect(screen,NULL, SDL_MapRGB(screen->format, 255, 0, 0));
the same line compiled with Emscripten fills the screen red.
Is there a way to switch the SDL colors in Emscripten or in the SDL headers?
From your native code, add this before the SDL_CreateWindow call:
SDL_SetHint(SDL_HINT_EMSCRIPTEN_KEYBOARD_ELEMENT, "#canvas");
More info here: https://wiki.libsdl.org/SDL_HINT_EMSCRIPTEN_KEYBOARD_ELEMENT
Emscripten, by default, captures all user events to the page. This makes sense for a fullscreen game for example. In your use case, you probably want to modify Emscripten's SDL_Init to not listen to key events, or change its receiveEvent return value.
Had the same problem. For me, doing this fixed it:
Module['doNotCaptureKeyboard'] = true;