I'm building a browser plugin which will draw pictures as a slideshow inside browser windows, however the plugin I created only draws on first plugin instance. If I open multiple instances of the plugin, it keeps on drawing on the first plugin window overlapping each picture.
I'm using opengl to draw picture from the url.
Following is a code which draws dummy opengl tringles in a loop using a thread:
FB::PluginWindowWin *pluginWindowWin = dynamic_cast(pluginWindow);
EnableOpenGL(pluginWindowWin->getHWND(), &hDC, &hRC);
SetFocus(pluginWindowWin->getHWND());
//FB::
static int fps = 1;
GLfloat rotate = 0;
static double start = 0, diff, wait;
wait = 1 / fps;
//return 0;
while (true)
{
//lets check for keyboard input
try
{
FB::Rect pos = pluginWindow->getWindowPosition();
PAINTSTRUCT ps;
if (pluginWindowWin){
hDC = BeginPaint(pluginWindowWin->getHWND(), &ps);
pos.right -= pos.left;
pos.left = 0;
pos.bottom -= pos.top;
pos.top = 0;
rotate += 0.1f;
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClear(GL_COLOR_BUFFER_BIT);
glPushMatrix();
glRotatef(rotate, 0.0f, 1.0f, 0.0f);
glBegin(GL_TRIANGLES);
glColor3f(1.0f, 0.0f, 0.0f); glVertex2f(0.0f, 1.0f);
glColor3f(0.0f, 1.0f, 0.0f); glVertex2f(0.87f, -0.5f);
glColor3f(0.0f, 0.0f, 1.0f); glVertex2f(-0.87f, -0.5f);
glEnd();
glBegin(GL_QUADS); // Draw A Quad
glColor3f(1.0f, 0.0f, 0.0f); glVertex3f(-0.5f, 0.5f, 0.0f); // Top Left
glColor3f(0.0f, 1.0f, 0.0f); glVertex3f(0.5f, 0.5f, 0.0f); // Top Right
glColor3f(0.0f, 0.0f, 1.0f); glVertex3f(0.5f, -0.5f, 0.0f); // Bottom Right
glColor3f(0.0f, 0.0f, 0.0f); glVertex3f(-0.5f, -0.5f, 0.0f); // Bottom Left
glEnd(); // Done Drawing The Quad
glPopMatrix();
glRotatef(rotate, 0.0f, 1.0f, 0.0f);
SwapBuffers(hDC);
}
//rtri+=0.1f;
::SetTextAlign(hDC, TA_CENTER | TA_BASELINE);
LPCTSTR pszText = _T("FireBreath Plugin!\n:-)");
::TextOut(hDC, pos.left + (pos.right - pos.left) / 2, pos.top + (pos.bottom - pos.top) / 2, pszText, lstrlen(pszText));
if (pluginWindowWin) {
// Release the device context
EndPaint(pluginWindowWin->getHWND(), &ps);
}
}
catch (...)
{
return 0;
}
Sleep(10);
}//end of while run
Any thing I'm doing wrong here?
From what you've told me in the comments, your primary issue is that you're starting with a flawed example. Remember that every instance of the plugin starts up in the same process; the example you're using is a simplified one which does not use good practices for plugins. Most specifically, it uses several global variables.
In addition to that you are threading but don't seem to be doing any locks to make sure that you are totally threadsafe. You live in someone else's process, you don't own it -- the browser does. You need to be very careful with a lot of things.
Most likely your crash has to do with not shutting down cleanly or perhaps with a race condition in your threading code. The best way to troubleshoot that is to attach a debugger and find out where it's crashing, rather than just running around in circles asking "Why?? why???!?" (exagerating for effect, obviously). You'd be shocked how few people do that simple step -- attaching a debugger -- until I tell them to, but it should always be your first step in troubleshooting a crash.
Finally, it bears asking: Do you realize that you are building this on a technology which won't be available in 6 months? FireFox is removing support for NPAPI at the end of the year. I expect ActiveX to work a bit longer than that, but edge doesn't support it.
FireBreath 2 (in the 2.0 branch) is a major change from firebreath 1 but it supports Chrome via native messaging and will support FireFox as well. there are many trying to convince MS to add native messaging support to Edge, but we'll see how that goes. Feel free to follow that link and vote, since it would help you as well I suspect.
Thing is, you don't get SDL or SDL2 w/ native messaging; you'd have to use WebGL and do the dev on the javascript side, then pull data over native messaging. alternately you could look into using NaCL which does have some opengl / drawing stuff (maybe even SDL? not sure) but is sandboxed and may or may not have the networking things you need. Also, of course, it only works on Chrome.
Food for thought. Good luck.