openGL convases

Started by
2 comments, last by LtJax 16 years, 10 months ago
Hi My application had one canvas on which I was drawing using the GLSL shaders. I was reading a dataset and it was displayed on that canvas. This thing is workign prefectly well!! Now I have to add another canvas to it so that we can see two datasets simultaniously on the screen. The name of my 1st canvas class is COpenGLCanvas. The name of my 2nd canvas class is COpenGLCanvas2. both of them have the following functions: initilizeGL () --> called automatically on the initilization of the canvas resizeGL() paintGL() --> when the canvas needs to be redrawn. Some code of the paintGL() in the second canvas (i.e. COpenGLCanvas) is creating trouble and complains that cannot read from the location.... and the program terminates. The code is given below:

	glViewport(0, 0, fbWidth, fbHeight);
	glUseProgram(0);

	for (int pass = 0; pass < 2; ++pass) {

		switch (pass) {

			case 0: // render back depth into framebuffer 0
				glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, framebuffer0);
				glDepthFunc(GL_GREATER);
				glClearDepth(0.0f);
				glCullFace(GL_FRONT);
				break;

			case 1: // render front depth into framebuffer 1
				glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, framebuffer1);
				glDepthFunc(GL_LESS);
				glClearDepth(1.0f);
				glCullFace(GL_BACK);
				break;
		}

		glClear(GL_DEPTH_BUFFER_BIT);

		if (volume.cubeQuads2 > 0) {
			glBindBuffer(GL_ARRAY_BUFFER, volume.vbCubes2);
			glVertexPointer(3, GL_FLOAT, 0, 0);
			glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, volume.ibCubes2);
			glEnableClientState(GL_VERTEX_ARRAY);

			glDrawElements(GL_QUADS, volume.cubeQuads2 * 4, GL_UNSIGNED_INT, 0);
//ERROR OCCOURS HERE WHEN THE PROGRAM GOES FROM THE ABOVE LINE TO NEXT. it screams about inability to read from the location: (
			glDisableClientState(GL_VERTEX_ARRAY);
			glBindBuffer(GL_ARRAY_BUFFER, 0);
			glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
		}
	




Approx similar code from the first canvas works and produces a kool output here is the code that works fine :

        glViewport(0, 0, fbWidth, fbHeight);
	glUseProgram(0);

	for (int pass = 0; pass < 2; ++pass) {

		switch (pass) {

			case 0: // render back depth into framebuffer 0
				glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, framebuffer0);
				glDepthFunc(GL_GREATER);
				glClearDepth(0.0f);
				glCullFace(GL_FRONT);
				break;

			case 1: // render front depth into framebuffer 1
				glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, framebuffer1);
				glDepthFunc(GL_LESS);
				glClearDepth(1.0f);
				glCullFace(GL_BACK);
				break;
		}

		glClear(GL_DEPTH_BUFFER_BIT);

		if (volume.cubeQuads > 0) {
			glBindBuffer(GL_ARRAY_BUFFER, volume.vbCubes);
			glVertexPointer(3, GL_FLOAT, 0, 0);
			glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, volume.ibCubes);
			glEnableClientState(GL_VERTEX_ARRAY);

	                glDrawElements(GL_QUADS, volume.cubeQuads * 4, GL_UNSIGNED_INT, 0);
			glDisableClientState(GL_VERTEX_ARRAY);
			glBindBuffer(GL_ARRAY_BUFFER, 0);
			glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
		}
	}




thanks in advance [Edited by - me_here_me on May 21, 2007 5:14:21 AM]
Advertisement
are those using seperate drawing contexts? if so, you need to make sure you switch to the right one before drawing. seems like this could cause your problem, since the vbo would prolly not exist in canvas2's context then.
--are those using seperate drawing contexts?
well I am not sure how to anser this. Let me explain the program a bit. Both the classes have a seperate GLPaint method (called whenever the display is updated). I am generating all the textures and doing the drawing withing this method. So I think that they have seperate drawing mechanism which will be called automatically with any update.

Both the classes have thier seperate methods to initilize the OpenGL context in the start.

--if so, you need to make sure you switch to the right one before drawing.
I guess the switching is to be done by the compiler and not me. Its like the display function which is called when needed by the OpenGL. Or am i wrong and there is some kind of context switching required?

-seems like this could cause your problem, since the vbo would prolly not exist in canvas2's context then.

could be!! but a little clarification, what do you mean by vbo? As far as the fbo and textures are concerned, both classes have seperate fbo's and textures and they need not share any.


thanks for the help

Quote:Original post by me_here_me
--are those using seperate drawing contexts?
well I am not sure how to anser this. Let me explain the program a bit. Both the classes have a seperate GLPaint method (called whenever the display is updated). I am generating all the textures and doing the drawing withing this method. So I think that they have seperate drawing mechanism which will be called automatically with any update.

Both the classes have thier seperate methods to initilize the OpenGL context in the start.


Yes, that sounds like they have different OpenGL contexts. But I can not tell for sure without seeing the rest of your code.

Quote:
--if so, you need to make sure you switch to the right one before drawing.
I guess the switching is to be done by the compiler and not me. Its like the display function which is called when needed by the OpenGL. Or am i wrong and there is some kind of context switching required?


You are wrong if you're indeed using two or more rendering contexts in one process. GL has no way of knowing to which OpenGL context you want to draw to, so you need to make sure to select the right one (using wglMakeCurrent on Windows, or something equivalent on MacOSX or Linux).

Quote:
-seems like this could cause your problem, since the vbo would prolly not exist in canvas2's context then.

could be!! but a little clarification, what do you mean by vbo? As far as the fbo and textures are concerned, both classes have seperate fbo's and textures and they need not share any.


The vertex buffer object (the GL_ARRAY_BUFFER thing.). I'm suspecting you're just not creating the resources for the right OpenGL context.

This topic is closed to new replies.

Advertisement