Advertisement

Ported Nehe tutorials 2-10 to Firefox [multiple plugins per page issue]

Started by March 13, 2005 12:20 AM
41 comments, last by shadowwz 19 years, 8 months ago
Just so everything makes sense. I'll post the source project I have.

If you unpack [the modified SDK] to the C:\ then you will find the MSVC 6.0 project in:
C:\GeckoPluginSDK-samples\Win32SDK\sdk\samples\winless\windows

After you compile, you'll need to browse the [test page]. You can't compile while the test page is open. The test page is also located here:
C:\GeckoPluginSDK-samples\Win32SDK\sdk\samples\winless\test.html

Make sure you have Firefox installed in the default directory.

The important files are:
plugin.cpp
Lesson2.h
Lesson2.cpp


To answer your questions:

- Why not to create child window with same size as rect and then create your contex?
Because I don't think the plugin is provided with a valid HWND. The handle is supposed to be mWindow->window, but it just doesn't work out that way. So that's why I just created my own.

- If your opengl window is hidden,it may not work with device contex.
- you can draw scene to texture, wich can be saved to bitmap - or using glReadPixel to save scene to bitmap.
If I don't show the hidden window, everything seems to work just fine. So I'll try capturing the BITMAP with glReadPixel. But then how do I get the pixel into the RECT?

Found [OpenGL Off-Screen Rendering] on CodeProject that could potentially work.
Found these nice tutorials [Multiple PDFs] which describe the process better.

[Edited by - tgraupmann on March 13, 2005 12:47:26 PM]
*News tagenigma.com is my new domain.
Quote: Original post by tgraupmann
I found [OpenGL
Off-Screen Rendering]
on CodeProject that could potentially work.


render to bitmap will work only in software mode.
Advertisement
Quote: Original post by shadowwz
Quote: Original post by tgraupmann
I found [OpenGL
Off-Screen Rendering]
on CodeProject that could potentially work.


render to bitmap will work only in software mode.


What do you mean? You mean I couldn't get 3d acceleration?
*News tagenigma.com is my new domain.
So I suppose I should use the subwindow method then... Do you have any examples? Google is going crap for searches in this area. Nothin' but garbage.
*News tagenigma.com is my new domain.
maybe this will help you :
Window to Bitmap

* i checked you code,and tried to create child window for main plugin widnow but it always failed because the main window isn't normal OS window,and the DC not assigned to any window ,try "WindowFromDC" and "GetClassName".
    HDC destDC = (HDC)event->wParam;    char buf[256];    HWND wnd = WindowFromDC(destDC);    buf[0] = '\0';    GetClassName(wnd,buf,255);
You did see the second window popup on the [test page]?


HDC destDC = (HDC)event->wParam;char buf[256];HWND wnd = WindowFromDC(destDC);buf[0] = '\0';GetClassName(wnd,buf,255);MessageBox(NULL,buf,"ERROR",MB_OK|MB_ICONEXCLAMATION);


buf is empty...


Just need to put this in here:


[Edited by - tgraupmann on March 13, 2005 3:39:14 PM]
*News tagenigma.com is my new domain.
Advertisement
Quote: Original post by tgraupmann
You did see the second window popup on the [test page]?


yes.

- i'm try to find how it's done with GeckoPluginSDK.
- maybe there is some plugings on sourcefourge ,wich implement such feature ?
i have checked the basic sample plugin,and it has valid window handle ,with class name "MozillaWindowClass",so try to use this base code to create opengl pluging - try to create directly the opengl contex to the plugin window in "NPBool nsPluginInstance::init(NPWindow* aWindow)"

hope it helps
this code is working,based on basic sample in SDK :
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- *//* ***** BEGIN LICENSE BLOCK ***** * Version: NPL 1.1/GPL 2.0/LGPL 2.1 * * The contents of this file are subject to the Netscape Public License * Version 1.1 (the "License"); you may not use this file except in * compliance with the License. You may obtain a copy of the License at * http://www.mozilla.org/NPL/ * * Software distributed under the License is distributed on an "AS IS" basis, * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License * for the specific language governing rights and limitations under the * License. * * The Original Code is mozilla.org code. * * The Initial Developer of the Original Code is  * Netscape Communications Corporation. * Portions created by the Initial Developer are Copyright (C) 1998 * the Initial Developer. All Rights Reserved. * * Contributor(s): * * Alternatively, the contents of this file may be used under the terms of * either the GNU General Public License Version 2 or later (the "GPL"), or  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), * in which case the provisions of the GPL or the LGPL are applicable instead * of those above. If you wish to allow use of your version of this file only * under the terms of either the GPL or the LGPL, and not to allow others to * use your version of this file under the terms of the NPL, indicate your * decision by deleting the provisions above and replace them with the notice * and other provisions required by the GPL or the LGPL. If you do not delete * the provisions above, a recipient may use your version of this file under * the terms of any one of the NPL, the GPL or the LGPL. * * ***** END LICENSE BLOCK ***** */#include <windows.h>#include <windowsx.h>#include "plugin.h"#include <gl\gl.h>			// Header File For The OpenGL32 Library#include <gl\glu.h>			// Header File For The GLu32 Library#include <gl\glaux.h>		// Header File For The Glaux Library#pragma comment(lib, "opengl32.lib")#pragma comment(lib, "glu32.lib")#pragma comment(lib, "glaux.lib")void KillGLWindow(void);void ReSizeGLScene(int width, int height);int InitGL(void);////////////////////////////////////////// general initialization and shutdown//NPError NS_PluginInitialize(){  return NPERR_NO_ERROR;}void NS_PluginShutdown(){}///////////////////////////////////////////////////////////////// construction and destruction of our plugin instance object//nsPluginInstanceBase * NS_NewPluginInstance(nsPluginCreateData * aCreateDataStruct){  if(!aCreateDataStruct)    return NULL;  nsPluginInstance * plugin = new nsPluginInstance(aCreateDataStruct->instance);  return plugin;}void NS_DestroyPluginInstance(nsPluginInstanceBase * aPlugin){  if(aPlugin)    delete (nsPluginInstance *)aPlugin;}//////////////////////////////////////////// nsPluginInstance class implementation//nsPluginInstance::nsPluginInstance(NPP aInstance) : nsPluginInstanceBase(),  mInstance(aInstance),  mInitialized(FALSE){  mhWnd = NULL;}nsPluginInstance::~nsPluginInstance(){}HDC			hGL_DC=NULL;		// Private GDI Device ContextHGLRC		hGL_RC=NULL;		// Permanent Rendering ContextHWND		hGL_Wnd=NULL;		// Holds Our Window Handlestatic LRESULT CALLBACK PluginWinProc(HWND, UINT, WPARAM, LPARAM);static WNDPROC lpOldProc = NULL;BOOL set_opengl_contex(int width, int height){	static	PIXELFORMATDESCRIPTOR pfd=				// pfd Tells Windows How We Want Things To Be	{		sizeof(PIXELFORMATDESCRIPTOR),				// Size Of This Pixel Format Descriptor		1,											// Version Number		PFD_DRAW_TO_WINDOW |						// Format Must Support Window		PFD_SUPPORT_OPENGL |						// Format Must Support OpenGL		PFD_DOUBLEBUFFER,							// Must Support Double Buffering		PFD_TYPE_RGBA,								// Request An RGBA Format		32,										// Select Our Color Depth		0, 0, 0, 0, 0, 0,							// Color Bits Ignored		0,											// No Alpha Buffer		0,											// Shift Bit Ignored		0,											// No Accumulation Buffer		0, 0, 0, 0,									// Accumulation Bits Ignored		16,											// 16Bit Z-Buffer (Depth Buffer)  		0,											// No Stencil Buffer		0,											// No Auxiliary Buffer		PFD_MAIN_PLANE,								// Main Drawing Layer		0,											// Reserved		0, 0, 0										// Layer Masks Ignored	};		if (!(hGL_DC=GetDC(hGL_Wnd))){		KillGLWindow();		MessageBox(NULL,"Can't Get A GL Device Context.","ERROR",MB_OK|MB_ICONEXCLAMATION);		return FALSE;								// Return FALSE		}	int PixelFormat = 0;	if (!(PixelFormat=ChoosePixelFormat(hGL_DC,&pfd))){		KillGLWindow();								// Reset The Display		MessageBox(NULL,"Can't Find A Suitable PixelFormat.","ERROR",MB_OK|MB_ICONEXCLAMATION);		return FALSE;								// Return FALSE		}	if(!SetPixelFormat(hGL_DC,PixelFormat,&pfd)){		KillGLWindow();								// Reset The Display		MessageBox(NULL,"Can't Set The PixelFormat.","ERROR",MB_OK|MB_ICONEXCLAMATION);		return FALSE;								// Return FALSE		}	if (!(hGL_RC=wglCreateContext(hGL_DC)))	{		KillGLWindow();								// Reset The Display		MessageBox(NULL,"Can't Create A GL Rendering Context.","ERROR",MB_OK|MB_ICONEXCLAMATION);		return FALSE;								// Return FALSE		}	if(!wglMakeCurrent(hGL_DC,hGL_RC)){		KillGLWindow();								// Reset The Display		MessageBox(NULL,"Can't Activate The GL Rendering Context.","ERROR",MB_OK|MB_ICONEXCLAMATION);		return FALSE;								// Return FALSE		}	ReSizeGLScene(width, height);	if (!InitGL()){		KillGLWindow();								// Reset The Display		MessageBox(NULL,"Initialization Failed.","ERROR",MB_OK|MB_ICONEXCLAMATION);		return FALSE;								// Return FALSE		}	return TRUE;}// Resize And Initialize The GL Windowvoid ReSizeGLScene(int width, int height){	if (height==0)	height=1;	glViewport(0,0,width,height);	glMatrixMode(GL_PROJECTION);	glLoadIdentity();	gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,0.1f,100.0f);	glMatrixMode(GL_MODELVIEW);	glLoadIdentity();		}// All Setup For OpenGL Goes Hereint InitGL(GLvoid)										{	glShadeModel(GL_SMOOTH);		glClearColor(0.0f, 0.0f, 0.0f, 0.5f);	glClearDepth(1.0f);						glEnable(GL_DEPTH_TEST);				glDepthFunc(GL_LEQUAL);					glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);	return TRUE;										}static float rot_z = 90.0f;int DrawGLScene(GLvoid){		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);	glLoadIdentity();										glRotatef(rot_z,0,0,1);	glTranslatef(-1.5f,0.0f,-6.0f);		rot_z +=0.353;				glBegin(GL_TRIANGLES);									glVertex3f( 0.0f, 1.0f, 0.0f);						glVertex3f(-1.0f,-1.0f, 0.0f);						glVertex3f( 1.0f,-1.0f, 0.0f);					glEnd();											glTranslatef(3.0f,0.0f,0.0f);						glBegin(GL_QUADS);										glVertex3f(-1.0f, 1.0f, 0.0f);						glVertex3f( 1.0f, 1.0f, 0.0f);						glVertex3f( 1.0f,-1.0f, 0.0f);						glVertex3f(-1.0f,-1.0f, 0.0f);					glEnd();										return TRUE;								}GLvoid KillGLWindow(GLvoid){	if (hGL_RC) {		if (!wglMakeCurrent(NULL,NULL))	{			MessageBox(NULL,"Release Of DC And RC Failed.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);			}		if (!wglDeleteContext(hGL_RC))	{			MessageBox(NULL,"Release Rendering Context Failed.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);			}		hGL_RC = NULL;										// Set RC To NULL		}	if (hGL_DC && !ReleaseDC(hGL_Wnd,hGL_DC)){		MessageBox(NULL,"Release Device Context Failed.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);		hGL_DC=NULL;										// Set DC To NULL		}	hGL_Wnd = 0;}struct TGLThread{	HANDLE hThread;	};const WM_GL_MESSAGE = WM_APP + 0x435;DWORD WINAPI gl_draw_thread(void* pv){	if(!pv) return 0;	TGLThread *sd = (TGLThread*)pv; 	int n = 0;	//*	while(hGL_DC && hGL_RC && hGL_Wnd){		::PostMessage(hGL_Wnd,WM_GL_MESSAGE,0,0);		Sleep(50);		}	//*/	HANDLE hTemp = sd->hThread;	delete sd;	CloseHandle(hTemp);	//ShowMsg("Done");  	 	return 0;}NPBool nsPluginInstance::init(NPWindow* aWindow){  if(aWindow == NULL)    return FALSE;  mhWnd = (HWND)aWindow->window;  if(mhWnd == NULL)    return FALSE;  // subclass window so we can intercept window messages and  // do our drawing to it  // associate window with our nsPluginInstance object so we can access   // it in the window procedure  if(!hGL_Wnd){   lpOldProc = SubclassWindow(mhWnd, (WNDPROC)PluginWinProc);	hGL_Wnd = mhWnd;	SetWindowLong(mhWnd, GWL_USERDATA, (LONG)this);	set_opengl_contex(aWindow->width,aWindow->height);	TGLThread* pData = new TGLThread();	DWORD	dwThreadID;	pData->hThread = ::CreateThread(NULL,0, ≷_draw_thread, (void*)pData, 0, &dwThreadID);	}  mInitialized = TRUE;  return TRUE;}void nsPluginInstance::shut(){  // subclass it back  KillGLWindow();  SubclassWindow(mhWnd, lpOldProc);  mhWnd = NULL;  mInitialized = FALSE;}NPBool nsPluginInstance::isInitialized(){  return mInitialized;}const char * nsPluginInstance::getVersion(){  return NPN_UserAgent(mInstance);}static LRESULT CALLBACK PluginWinProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam){  switch (msg) {	case WM_GL_MESSAGE:		//if(wglMakeCurrent(hGL_DC,hGL_RC)){			DrawGLScene();			SwapBuffers(hGL_DC);		//	}		break;	case WM_ERASEBKGND:		return 1;		break;    case WM_PAINT:      {		if(hGL_DC){			DrawGLScene();			SwapBuffers(hGL_DC);			}		else{			// draw a frame and display the string			PAINTSTRUCT ps;			HDC hdc = BeginPaint(hWnd, &ps);			RECT rc;			GetClientRect(hWnd, &rc);			FrameRect(hdc, &rc, GetStockBrush(BLACK_BRUSH));			// get our plugin instance object and ask it for the version string			nsPluginInstance *plugin = (nsPluginInstance *)GetWindowLong(hWnd, GWL_USERDATA);			if (plugin) {			  const char * string = plugin->getVersion();			  DrawText(hdc, string, strlen(string), &rc, DT_SINGLELINE | DT_CENTER | DT_VCENTER);			}			else {			  char string[] = "Error occured";			  DrawText(hdc, string, strlen(string), &rc, DT_SINGLELINE | DT_CENTER | DT_VCENTER);			}			EndPaint(hWnd, &ps);			}      }      break;    default:      break;  }  return DefWindowProc(hWnd, msg, wParam, lParam);}
sorry for previous "short" post &)

/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- *//* ***** BEGIN LICENSE BLOCK ***** * Version: NPL 1.1/GPL 2.0/LGPL 2.1 * * The contents of this file are subject to the Netscape Public License * Version 1.1 (the "License"); you may not use this file except in * compliance with the License. You may obtain a copy of the License at * http://www.mozilla.org/NPL/ * * Software distributed under the License is distributed on an "AS IS" basis, * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License * for the specific language governing rights and limitations under the * License. * * The Original Code is mozilla.org code. * * The Initial Developer of the Original Code is  * Netscape Communications Corporation. * Portions created by the Initial Developer are Copyright (C) 1998 * the Initial Developer. All Rights Reserved. * * Contributor(s): * * Alternatively, the contents of this file may be used under the terms of * either the GNU General Public License Version 2 or later (the "GPL"), or  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), * in which case the provisions of the GPL or the LGPL are applicable instead * of those above. If you wish to allow use of your version of this file only * under the terms of either the GPL or the LGPL, and not to allow others to * use your version of this file under the terms of the NPL, indicate your * decision by deleting the provisions above and replace them with the notice * and other provisions required by the GPL or the LGPL. If you do not delete * the provisions above, a recipient may use your version of this file under * the terms of any one of the NPL, the GPL or the LGPL. * * ***** END LICENSE BLOCK ***** */#include <windows.h>#include <windowsx.h>#include "plugin.h"#include <gl\gl.h>			// Header File For The OpenGL32 Library#include <gl\glu.h>			// Header File For The GLu32 Library#include <gl\glaux.h>		// Header File For The Glaux Library#pragma comment(lib, "opengl32.lib")#pragma comment(lib, "glu32.lib")#pragma comment(lib, "glaux.lib")void KillGLWindow(void);void ReSizeGLScene(int width, int height);int InitGL(void);////////////////////////////////////////// general initialization and shutdown//NPError NS_PluginInitialize(){  return NPERR_NO_ERROR;}void NS_PluginShutdown(){}///////////////////////////////////////////////////////////////// construction and destruction of our plugin instance object//nsPluginInstanceBase * NS_NewPluginInstance(nsPluginCreateData * aCreateDataStruct){  if(!aCreateDataStruct)    return NULL;  nsPluginInstance * plugin = new nsPluginInstance(aCreateDataStruct->instance);  return plugin;}void NS_DestroyPluginInstance(nsPluginInstanceBase * aPlugin){  if(aPlugin)    delete (nsPluginInstance *)aPlugin;}//////////////////////////////////////////// nsPluginInstance class implementation//nsPluginInstance::nsPluginInstance(NPP aInstance) : nsPluginInstanceBase(),  mInstance(aInstance),  mInitialized(FALSE){  mhWnd = NULL;}nsPluginInstance::~nsPluginInstance(){}HDC			hGL_DC=NULL;		// Private GDI Device ContextHGLRC		hGL_RC=NULL;		// Permanent Rendering ContextHWND		hGL_Wnd=NULL;		// Holds Our Window Handlestatic LRESULT CALLBACK PluginWinProc(HWND, UINT, WPARAM, LPARAM);static WNDPROC lpOldProc = NULL;BOOL set_opengl_contex(int width, int height){	static	PIXELFORMATDESCRIPTOR pfd=				// pfd Tells Windows How We Want Things To Be	{		sizeof(PIXELFORMATDESCRIPTOR),				// Size Of This Pixel Format Descriptor		1,											// Version Number		PFD_DRAW_TO_WINDOW |						// Format Must Support Window		PFD_SUPPORT_OPENGL |						// Format Must Support OpenGL		PFD_DOUBLEBUFFER,							// Must Support Double Buffering		PFD_TYPE_RGBA,								// Request An RGBA Format		32,										// Select Our Color Depth		0, 0, 0, 0, 0, 0,							// Color Bits Ignored		0,											// No Alpha Buffer		0,											// Shift Bit Ignored		0,											// No Accumulation Buffer		0, 0, 0, 0,									// Accumulation Bits Ignored		16,											// 16Bit Z-Buffer (Depth Buffer)  		0,											// No Stencil Buffer		0,											// No Auxiliary Buffer		PFD_MAIN_PLANE,								// Main Drawing Layer		0,											// Reserved		0, 0, 0										// Layer Masks Ignored	};		if (!(hGL_DC=GetDC(hGL_Wnd))){		KillGLWindow();		MessageBox(NULL,"Can't Get A GL Device Context.","ERROR",MB_OK|MB_ICONEXCLAMATION);		return FALSE;								// Return FALSE		}	int PixelFormat = 0;	if (!(PixelFormat=ChoosePixelFormat(hGL_DC,&pfd))){		KillGLWindow();								// Reset The Display		MessageBox(NULL,"Can't Find A Suitable PixelFormat.","ERROR",MB_OK|MB_ICONEXCLAMATION);		return FALSE;								// Return FALSE		}	if(!SetPixelFormat(hGL_DC,PixelFormat,&pfd)){		KillGLWindow();								// Reset The Display		MessageBox(NULL,"Can't Set The PixelFormat.","ERROR",MB_OK|MB_ICONEXCLAMATION);		return FALSE;								// Return FALSE		}	if (!(hGL_RC=wglCreateContext(hGL_DC)))	{		KillGLWindow();								// Reset The Display		MessageBox(NULL,"Can't Create A GL Rendering Context.","ERROR",MB_OK|MB_ICONEXCLAMATION);		return FALSE;								// Return FALSE		}	if(!wglMakeCurrent(hGL_DC,hGL_RC)){		KillGLWindow();								// Reset The Display		MessageBox(NULL,"Can't Activate The GL Rendering Context.","ERROR",MB_OK|MB_ICONEXCLAMATION);		return FALSE;								// Return FALSE		}	ReSizeGLScene(width, height);	if (!InitGL()){		KillGLWindow();								// Reset The Display		MessageBox(NULL,"Initialization Failed.","ERROR",MB_OK|MB_ICONEXCLAMATION);		return FALSE;								// Return FALSE		}	return TRUE;}// Resize And Initialize The GL Windowvoid ReSizeGLScene(int width, int height){	if (height==0)	height=1;	glViewport(0,0,width,height);	glMatrixMode(GL_PROJECTION);	glLoadIdentity();	gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,0.1f,100.0f);	glMatrixMode(GL_MODELVIEW);	glLoadIdentity();		}// All Setup For OpenGL Goes Hereint InitGL(GLvoid)										{	glShadeModel(GL_SMOOTH);		glClearColor(0.0f, 0.0f, 0.0f, 0.5f);	glClearDepth(1.0f);						glEnable(GL_DEPTH_TEST);				glDepthFunc(GL_LEQUAL);					glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);	return TRUE;										}static float rot_z = 90.0f;int DrawGLScene(GLvoid){		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);	glLoadIdentity();										glRotatef(rot_z,0,0,1);	glTranslatef(-1.5f,0.0f,-6.0f);		rot_z +=0.353;				glBegin(GL_TRIANGLES);									glVertex3f( 0.0f, 1.0f, 0.0f);						glVertex3f(-1.0f,-1.0f, 0.0f);						glVertex3f( 1.0f,-1.0f, 0.0f);					glEnd();											glTranslatef(3.0f,0.0f,0.0f);						glBegin(GL_QUADS);										glVertex3f(-1.0f, 1.0f, 0.0f);						glVertex3f( 1.0f, 1.0f, 0.0f);						glVertex3f( 1.0f,-1.0f, 0.0f);						glVertex3f(-1.0f,-1.0f, 0.0f);					glEnd();										return TRUE;								}GLvoid KillGLWindow(GLvoid){	if (hGL_RC) {		if (!wglMakeCurrent(NULL,NULL))	{			MessageBox(NULL,"Release Of DC And RC Failed.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);			}		if (!wglDeleteContext(hGL_RC))	{			MessageBox(NULL,"Release Rendering Context Failed.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);			}		hGL_RC = NULL;										// Set RC To NULL		}	if (hGL_DC && !ReleaseDC(hGL_Wnd,hGL_DC)){		MessageBox(NULL,"Release Device Context Failed.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);		hGL_DC=NULL;										// Set DC To NULL		}	hGL_Wnd = 0;}struct TGLThread{	HANDLE hThread;	};const WM_GL_MESSAGE = WM_APP + 0x435;DWORD WINAPI gl_draw_thread(void* pv){	if(!pv) return 0;	TGLThread *sd = (TGLThread*)pv; 	int n = 0;	//*	while(hGL_DC && hGL_RC && hGL_Wnd){		::PostMessage(hGL_Wnd,WM_GL_MESSAGE,0,0);		Sleep(50);		}	//*/	HANDLE hTemp = sd->hThread;	delete sd;	CloseHandle(hTemp);	//ShowMsg("Done");  	 	return 0;}NPBool nsPluginInstance::init(NPWindow* aWindow){  if(aWindow == NULL)    return FALSE;  mhWnd = (HWND)aWindow->window;  if(mhWnd == NULL)    return FALSE;  // subclass window so we can intercept window messages and  // do our drawing to it  // associate window with our nsPluginInstance object so we can access   // it in the window procedure  if(!hGL_Wnd){   lpOldProc = SubclassWindow(mhWnd, (WNDPROC)PluginWinProc);	hGL_Wnd = mhWnd;	SetWindowLong(mhWnd, GWL_USERDATA, (LONG)this);	set_opengl_contex(aWindow->width,aWindow->height);	TGLThread* pData = new TGLThread();	DWORD	dwThreadID;	pData->hThread = ::CreateThread(NULL,0, ≷_draw_thread, (void*)pData, 0, &dwThreadID);	}  mInitialized = TRUE;  return TRUE;}void nsPluginInstance::shut(){  // subclass it back  KillGLWindow();  SubclassWindow(mhWnd, lpOldProc);  mhWnd = NULL;  mInitialized = FALSE;}NPBool nsPluginInstance::isInitialized(){  return mInitialized;}const char * nsPluginInstance::getVersion(){  return NPN_UserAgent(mInstance);}static LRESULT CALLBACK PluginWinProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam){  switch (msg) {	case WM_GL_MESSAGE:		//if(wglMakeCurrent(hGL_DC,hGL_RC)){			DrawGLScene();			SwapBuffers(hGL_DC);		//	}		break;	case WM_ERASEBKGND:		return 1;		break;    case WM_PAINT:      {		if(hGL_DC){			DrawGLScene();			SwapBuffers(hGL_DC);			}		else{			// draw a frame and display the string			PAINTSTRUCT ps;			HDC hdc = BeginPaint(hWnd, &ps);			RECT rc;			GetClientRect(hWnd, &rc);			FrameRect(hdc, &rc, GetStockBrush(BLACK_BRUSH));			// get our plugin instance object and ask it for the version string			nsPluginInstance *plugin = (nsPluginInstance *)GetWindowLong(hWnd, GWL_USERDATA);			if (plugin) {			  const char * string = plugin->getVersion();			  DrawText(hdc, string, strlen(string), &rc, DT_SINGLELINE | DT_CENTER | DT_VCENTER);			}			else {			  char string[] = "Error occured";			  DrawText(hdc, string, strlen(string), &rc, DT_SINGLELINE | DT_CENTER | DT_VCENTER);			}			EndPaint(hWnd, &ps);			}      }      break;    default:      break;  }  return DefWindowProc(hWnd, msg, wParam, lParam);}

This topic is closed to new replies.

Advertisement