Page 1 of 1

[2.1] Rendering some lines with openGL

Posted: Thu Oct 25, 2018 3:11 pm
by Slicky
I have some visual debugging code that uses glBegin(GL_LINES);

Rather, than reinventing the wheel I have tried to get it to render at the same times as Ogre. I haven't been successful in getting anything to show on the screen.

Is a particular point in the Ogre rendering process where I should use this?

Re: [2.1] Rendering some lines with openGL

Posted: Thu Oct 25, 2018 3:31 pm
by dark_sylinc
Ogre 2.1 creates a GL Core context (in contrast to a Compatibility Profile context, which is optional though provided by most drivers except Mesa).

glBegin has been deprecated thus it is likely that it will fail to work as expected in core contexts.
Changing all instances of WGL_CONTEXT_CORE_PROFILE_BIT_ARB for WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB in Ogre's codebase might make it work. (GLX_CONTEXT_CORE_PROFILE_BIT_ARB for GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB in Linux)
Also I suggest you call RenderSystem->_startLegacyV1Rendering(); before your immediate mode calls, as that will bind a global VAO, though you may have to call: glBindVertexArray( 0 ); instead.

Re: [2.1] Rendering some lines with openGL

Posted: Thu Oct 25, 2018 3:39 pm
by Slicky
Ok thanks for the info I will see if I can pull that off. I was aware of the deprecated GLines but I tried newer code too and it also didn't work.

One of my attempts was:

Code: Select all

		GLfloat vertices[] =
		{
			20.0f, 150.0f, 0.0f, 1.0f,
			220.0f, 150.0f, 0.0f, 1.0f,
			200.0f, 160.0f, 0.0f, 1.0f
		};
		glUseProgram(gProgramID);
		// This binds our vbo
		glBindBuffer(GL_ARRAY_BUFFER, gVBO);
		// This hands the vertices into the vbo and to the rendering pipeline    
		glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
		// "Enable a port" to the shader pipeline
		glEnableVertexAttribArray(0);
		glBindBuffer(GL_ARRAY_BUFFER, gVBO);
		// pass information about how vertex array is composed
		glVertexAttribPointer(0, // same as in glEnableVertexAttribArray(0)
			4, // # of coordinates that build a vertex
			GL_FLOAT, // data type
			GL_FALSE, // normalized?
			0,        // stride
			(void*)0);// vbo offset

		glDrawArrays(GL_LINES, 0, 2);
		glDisableVertexAttribArray(0);
		//Unbind program
		glUseProgram(NULL);