1
\$\begingroup\$

Recently, I am trying to make a 3D game in LWJGL 2, not LWJGL 3, just because I am more familiar with LWJGL 2. Since LWJGL decided to shut down their legacy wiki website, I've been researching alot lately on adding shaders. The thing is, most of these tutorials use VBOs and VAOs to render objects.

I am trying to use vertex and fragment shaders to edit the objects. Yes, I am using the depreciated methods glBegin(); and those rendering methods to draw shapes. I am not sure if this affects the use of shaders or not, so that is why I am asking this question.

If anyone wants to know, I am using the depreciated methods because I don't want to really use VAOs and VBOs, I know it reduces performance to use the depreciated methods, but I am fine with this for now.

\$\endgroup\$
0
0
\$\begingroup\$

There's nothing special you need to do for this - shaders work just fine with glBegin/glEnd code.

You create and bind shaders in the normal way, set uniforms in the normal way. You still need to pay attention to the parts of the OpenGL pipeline that shaders replace, but that's the case no matter how you do your vertex submission.

For reading your vertex data in your vertex shader, you might find it easier to use the legacy built-in vertex attributes (https://www.opengl.org/sdk/docs/tutorials/ClockworkCoders/attributes.php) but if you wanted you could use standalone glVertexAttrib calls with glBegin/glEnd too.

\$\endgroup\$
6
  • \$\begingroup\$ Ok, I used some code to load the vertex and fragment shaders, yet the colors are not passing through (the cube is just all white even though the color isn't) \$\endgroup\$ – Pale_Gray May 11 at 1:56
  • \$\begingroup\$ Wait I got it working thank you for the link! \$\endgroup\$ – Pale_Gray May 11 at 2:00
  • \$\begingroup\$ wait shaders aren't updating \$\endgroup\$ – Pale_Gray May 11 at 2:01
  • \$\begingroup\$ @Pale_Gray - there are many reasons why this could be happening, and you'll need to post the code you use for updating uniforms in order to help us to help you. Also look at where you're making your glGetUniformLocation calls. \$\endgroup\$ – Maximus Minimus May 11 at 9:33
  • \$\begingroup\$ I am never using glGetUniformLocation at all... I guess that's why I can't update the color, but where should I even put it? Should I make a custom method called update in the shader program class? I'm calling glGetUniformLocation in the !Display.isCloseRequested. I think I don't need to get the variable every frame, so do I just make a method to bind the shader data and then call glUniform1f in the !Display.isCloseRequested code? \$\endgroup\$ – Pale_Gray May 11 at 11:19
0
\$\begingroup\$
  1. First, make your classes to load the shader files. There should be methods to start/stop the shader, to wash (cleanup) the shader and to grab the shaders' program ID.

  2. In your MainLoop (gameloop) After starting the shader for an object, type this in:

GL20.glUniformXf(GL20.glGetUniformLocation(shader.getProgID(), variablename), a);

Where variablename is the name of your uniform variable in either shader file (vertes or fragment), where X is specified uniform (4, 2, 1, etc), and where a is the number you want to set it to (what the variable will equal to)

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.