Problem with OpenGLContext


#1

Hi,

I am new to JUCE and I have just started to write some of my OpenGL codes under JUCE. I want to have a single OpenGLContext and some OpenGLComponents connected with it. I worked around until I found that there is a problem with OpenGLContext.

first I tried to define the Context by

class A : public ... {
   OpenGLContext *context;
public :
   A () {
        context = new OpenGLContext;
   }
};

but when I compiled the code and I got an error like “cannot initiation an abstract class”

then I tried a line like

   OpenGLContext *context=getCurrentContext()

and I got :

MainWindow.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: class juce::OpenGLContext * __thiscall juce::OpenGLComponent::getCurrentContext(void)const " (_imp?getCurrentContext@OpenGLComponent@juce@@QBEPAVOpenGLContext@2@XZ) referenced in function “public: void __thiscall OpenGLCanvas::showTexture(unsigned int,int,int)” (?showTexture@OpenGLCanvas@@QAEXIHH@Z)

I also tried the line in JuceDemo.cpp and I got the same error too.
can anyone help me where the problem might be ?[/code]


#2

Hello, NikolaW… I’m a bit dummy on Juce programming, but I recently wrote some OpenGL code to plot some graphics. Why do you need to take control over the OpenGLContext?

I just extended an OpenGLComponent and implemented the renderOpenGL function.

#include <windows.h>
#include <juce.h>

#include <GL\gl.h>
#include <GL\glu.h>
#include <glut.h>

class MyOpenGLRender  : public OpenGLComponent
{
	public:

	MyOpenGLRender(void)
	{

		
	}

	~MyOpenGLRender()
	{
		this->deleteAllChildren();
	}

	void renderOpenGL(void){

        // do your opengl stuff here

	glClearColor (0.0f, 0.0f, 0.0f, 0.0f);
        glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
      
		
	glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();
	glPushMatrix();
        gluOrtho2D (0.0, 1.0, -1.0, 1.0);
        ... 




	}


	void newOpenGLContextCreated(void){
             // i don't use this function, but i have to implement it because
             // it's a pure virtual c++ class
	}
};

To put your OpenGL frame inside a window, write this code on your JUCEApplication file:

void JUCEApplication::initialise(...){
   ... // do your initialization stuff here
   mainWindow = new MyMainWindow(); // my basic window class
   myOpenGLComponent = new MyOpenGLComponent();
   myOpenGLComponent->setBounds(x,y,width,height);
   
   contentComponent = new MyContentComponent(); // my basic content component class
   
   myMainWindow->setContentComponent(contentComponent);

   contentComponent->addAndMakeVisible(myOpenGLComponent);

}

And that’s all. Your Open GL code should get working.


#3

OpenGL Context is an abstract base class. If you need to use one you’d have to create a subclass and implement some methods. Juce has helper functions on each platform to create native window contexts, and it does this automatically from the OpenGLComponent.

The simplest share would be the get the context from one, visible, usable OpenGLComponent (and make sure it stays valid) and pass it to another OpenGLComponent.

I’m using offscreen contexts and have rolled a context subclass based on the Juce code. It works well on Mac - although I use native methods that suit my other code - and not sure about Windows.

Bruce


#4

Thanks a lot . I will look into both ideas.

The point is that I have three windows. each of them has its own OpenGLcomponent. Window # 1 is showing an Image. Window #2 is showing the approximation of the image and the third one is the difference between the original image and the approximation. right now I am doing my computation in one of the OpenGLComponents which belongs to Window #2 by Cg Shading Language. The OpenGLContext of this window contains all three textures data.

I want a live feed to the difference texture which is updated in Window #2 to show the texture in Window #3. right now I am working on the problem and I have tested shareWith() but I am not getting any results.


#5