OpenGL - Fixed shader errors for the trunk (Mimic fixed pipeline with shaders)

Can someone provide me with a shader that looks like a channel with a fixed function?

I need the default fader shader more, because I found a similar vertex shader online. But if you have a couple, that should be good!

I want to use a fixed pipeline, but have the flexibility of shaders, so I need similar shaders, so I can simulate the functionality of a fixed pipeline.

Many thanks!

I am new here, so if you need more information, tell me: D

This is what I would like to reproduce: (texture unit 0)

  • glTranslatef functionality
  • glColor4f functionality
  • glTexCoord2f functionality
  • glVertex2f functionality
  • glOrtho functionality (I know that it does some magic things behind the scenes using a shader)

Here it is. This is all the functionality that I would like to replicate from the pipeline of a fixed function. Can someone show me an example of how to copy these things using shaders?

+4
source share
2 answers

You have a couple of problems that will help implement this with shaders.

First of all, in addition to using fixed function functions, you also use immediate mode. Before you can move on to shaders, you must switch to vertex arrays. You can write a class that accepts immediate mode-like commands that will be between glBegin (...) and glEnd (...) and glEnd (...) them into an array of vertices if you absolutely need to structure your software this way.

As for glTranslatef (...) and glOrtho (...) , this is nothing special. They create translation matrices and spelling projection matrices and multiply the β€œcurrent” matrix by them. It is not clear which language you are using, but one possible replacement for these functions may come from using a library like glm (C ++).

The biggest obstacle will be getting rid of the "current" state mentality, which comes with thinking in terms of a conveyor with a fixed function. With shaders, you have full control over each state, and you do not need to use functions that multiply the "current" matrix or set the "current" color. You can simply convey the exact matrix or color value that you need for your shader. This is the best way to approach these problems, and therefore I honestly think that you should completely abandon the fixed-function approach, and not try to imitate it.

That is why your desire to "use a conveyor with a fixed function, but have the flexibility of shaders" basically does not make much sense.

Having said all this, in OpenGL compatibility mode in GLSL there are reserved words that apply to many fixed function constructs. These include things like gl_MultiTexCoord<N> , gl_ModelViewProjectionMatrix , etc. They can be used as transitional assistance, but really should not be relied upon in the end.

+3
source

Se also has this question: OpenGL Fixed implementation of a function shader , where they point to several web resources.


The OpenGL ES 2 book contains an implementation of the pipeline with the fixed function OpenGL ES 1.1 in chapter 8 (vertex shader) and in chapter 10 (fragment shader).

Unfortunately, these shaders do not seem to be included in the sample code for the book. Reading a book and entering code, on the other hand, is certainly noteworthy.

+1
source

Source: https://habr.com/ru/post/1502209/


All Articles