Appendix B. Best Practices

This appendix includes OpenGL programming tips designed to improve code reusability and reduce application bugs. Some topics covered will also help improve application performance, but for more performance information, see Appendix C, “Performance.”

B.1 State

OpenGL is a state machine, and when your application puts OpenGL in a certain state, OpenGL stays in that state until code changes it to another state. Often, this is the behavior you want. Many applications typically enable depth testing with glEnable ( GL_DEPTH_TEST ) at init time, for example, and leave it enabled for the duration of their program execution.

If state isn’t set the way you want it, however, OpenGL probably won’t produce the results you want. ...

Get OpenGL Distilled now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.