opengl,opengl-es,glsl,shader,glsles , Porting GL ES 2.0 shaders to desktop GLSL (should I?)

Porting GL ES 2.0 shaders to desktop GLSL (should I?)


Tag: opengl,opengl-es,glsl,shader,glsles

I'm developing a cross-platform game, for iOS, Windows, and OS X. Right now I'm at the point where I'm writing all my shaders for my graphics. So here's the question:

If I have working GL ES 2.0 shaders (#version 100) for the mobile version of the game (which I developed fist), should I rewrite them in a more modern version of desktop GLSL (like #version 330 or something) for the desktop port of the game, or should I just use those shaders as-is? I tested the ES 2.0 shaders in a desktop environment in a test application, and they seem to work perfectly.

So do I (generally speaking) benefit from rewriting the shaders in a more modern GLSL version? I'm not talking about optimizing the shader code itself for mobile/desktop, that's fairly obvious, I will do that of course. I'm talking about using different GLSL language versions on different platforms. Is there any performance difference, compatibility issue, or anything of that sort, that's a good enough reason for porting the ES 2.0 shaders to a more modern version on desktop?

Since we're talking about fairly simple shaders for a 2D game, I won't really benefit from the extra functionality and better API of more modern desktop GLSL versions. #version 100 has enough to get the job done, it works fine for me. So the more modern functionality, I can do without. Other than that, is there any reason not to use #version 100 on desktop?


So do I (generally speaking) benefit from rewriting the shaders in a more modern GLSL version? I'm not talking about optimizing the shader code itself for mobile/desktop, that's fairly obvious, I will do that of course. I'm talking about using different GLSL language versions on different platforms. Is there any performance difference, compatibility issue, or anything of that sort, that's a good enough reason for porting the ES 2.0 shaders to a more modern version on desktop?

Performance, no, not really.

Compatibility, on the other hand, is a very real concern.

The precision qualifiers will confuse older versions of GLSL, but everything else should port fine without any re-write. It is understood that precision in desktop GLSL is offered only for compatibility and that its addition to later version does nothing beyond prevent parse errors. It will not improve performance or anything of that sort.

The only reason you might be forced to significantly re-write the shaders is if you were to try to port the software to a core profile on OS X. You have to use GLSL 1.30+ syntax in that situation.

So the more modern functionality, I can do without. Other than that, is there any reason not to use #version 100 on desktop?

Technically speaking, #version 100 does not exist in desktop GL. There was an extension that pre-dates GL 2.0 that vaguely defined it, but generally you assume that in desktop GL the GLSL version numbering starts at 110. GLSL ES version 100 is actually closer in syntax and functionality to desktop GLSL 120, but with a few extra things such as precision that desktop GLSL did not understand for quite some time.

You are going to have to re-write the #version directive at the very least. Most desktop GLSL compilers will not like it if you tell them to compile the shader against GLSL 1.00.


Passing 2 Textures into fragmenshader

Im want to get to different textures in my fragment shader. But somehow it won't work. It is only getting one of them. I'm starting my rendering with : glBindVertexArrayOES(_heighMap.vertexArray); //Get Uniforms GLuint mapProj = glGetUniformLocation(_mapProgram, "modelViewProjectionMatrix"); GLuint mapView = glGetUniformLocation(_mapProgram, "modelViewMatrix"); GLuint mapNormal = glGetUniformLocation(_mapProgram, "normalMatrix"); GLuint map2D0 =glGetUniformLocation(_mapProgram,...

Can the OpenGL 'deprecated' functions possibly be unsupported?

I am testing with glDrawPixels to port my simple pixel-drawn 2D game from Windows API to OpenGL with GLFW. It runs nicely with FPS over 100, additionally cross-platform. Just one thing that is slightly annoying me is that I'm using a deprecated feature. I don't see any problems now, but...

OpenGl ES 3.0 Context not created on iPad (works in Simulator)

I'm working on a cross platform renderer for PC (Windows, Linux, Mac) and iOS. The iOS part is currently built around OpenGL ES 2.0 and I wanted to upgrade to ES 3.0. So I replaced the following line (that works) context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2]; with this line: context =...

Creating GUI with OpenGL

I am trying to write a Java programm using LWJGL 3 and so far I've made it to creating a window, rendering to it and getting basic input. But I've ran into a problem with creating GUI and namely text fields that my programm requires. I found information that there...

Fastest way to draw sprites in opengles 2.0 on android

So Im trying to figure out how to draw a single textured quad many times. My issue is that since these are create and deleted and every one of them has a unique position and rotation. Im not sure a vbo is the best solution as I've heard modifying buffers...

OpenGL glTexImage2D memory issue

I'm loading a cubemap to create a skybox, everything is fine and the skybox renders properly with a correct texture application. However, I decided to check my program safety with valgrind, Valgrind gives this error: The line 53 in sky.c is: glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_RGB, texture.width, texture.height, 0,...

Ambient and Specular lighting not working correctly in GLSL

In my lighting scene, for some reason the ambient lighting isn't working at all. The whole model is the same brightness, no matter which way it is facing. I tried getting rid of the attenuation but it still has the same results. Along with that, the specular lighting is always...

Effect of rendering calls on performance

Consider a situation , Case 1 : I am giving opengl calls to draw the world by drawing all polygons. So all polygons will be drawn according to all objects exist. (Considered all translation rotation). Case 2 : I will allow only polygons that are in field of view(FOV) of...

Opengl - Is glDrawBuffers modification stored in a FBO? No?

I try to create a FrameBuffer with 2 textures attaching to it (Multi Render Targets). Then in every time step, both textures are cleared and painted, as following code. (Some part will be replaced as pseudo code to make it shorter.) Version 1 //beginning of the 1st time step initialize(framebufferID12)...

Drawing a cube in iOS with OpenGL and GLKit

I was following this tutorial to understand how viewing works but then when I tried to apply it on my iOS app I had so much trouble so basically what I understood is that: The model is initially at the origin and so is the camera We then use...

Android OpenGLES Brown square

So I'm trying to learn openGLES 2.0 and create a textured rectangle. Apparently I didn't follow all the instructions and now I've ended up with just a odd color square. heres my shaders. final String vertexShader = "uniform mat4 u_MVPMatrix; \n" // A constant representing the combined model/view/projection matrix. +...

Need Minimum Textures required for OpenGL

Quick question, what is the minimum amount of textures that can be bound for the fragment shader that a OpenGL implementation is required to have? Note: I would like to know this for OpenGL 1.5, for OpenGL 2.0, and OpenGL 2.1...

Passing an int to a function, then using that int to create an array

I'm trying to create a textureLoader class for my openGL project and I can't initialize an array of textures inside of my class constructor because the the array won't accept anything unless it's a const int. To paint you a simple picture... myFunction(NUM) { GLuint textures[NUM]; } My past Failures...

glclearcolor best color?

this might seam like a stupid question but i was wondering, when calling glClear(GL11.GL_COLOR_BUFFER_BIT); glClearColor(1, 0, 0, 1); to clear the screen in my opengl project is there any performance differences for using different colors? i mean if for example i clear to red vs blue/green/*insert any color will it...

Why are shaders and programs stored as integers in OpenGL?

I'm following the "OpenGL Superbible" book and I can't help but notice that when we create a shader and create the program that we attach the shaders to, we store them as GLuint which are unsigned integers. Why are they stored as numbers? What does the value of the number...

Unable to render a texture on a quad

I am trying to program a simple game in C++ using OpenGL for graphics. In my game, I have objects that are rendered onscreen as a white square. I would like to be able to bind an image as a texture to these objects, so that I can render an...

Android: How to change OpenGLES texture data / bitmap from gallery / camera

I try reuse Android Media Effects samples and want to be able to change texture data with new bitmap from camera or gallery pick. No solution so far This is the initial load texture from the sample : private void loadTextures() { // Generate textures GLES20.glGenTextures(2, mTextures, 0); //...

scale texture opengl 2

I have a rectangle in opengl 2 and I'm using a texture for it. It Works, but the texture is repeated over the rectangle, and what I want is to adapt to the size of the rectangle. I have read in this tutorial about the different parameters you can set...

How to create latitudinal (horizontal) contour lines in GLSL?

I'm aiming for this effect: (horizontal-only contour lines): I did find this example, however it creates horizontal and vertical contour lines. I can't quite wrap my head around how the call to fwidth() is generating the lines. uniform float gsize;//size of the grid uniform float gwidth;//grid lines'width in pixels varying...

OpenGL: Using glColorPointer make color weird

Like the picture showed in the link below. I want to color my robot hand with white color(RGB: 0.9 0.9 0.9). When I use glColor3f, the white color display correctly. But when I store RGB data in GLfloat array and call glColorPointer, the color becomes so weird. Here is code...

Multitexturing theory with texture objects and samplers

I couldn't find any good theory articles on how to code multitexturing with either only texture objects or texture objects plus samplers. I just don't know how to manage the glActiveTexture function and what it exactly does. glGenTextures(1, &texture); glActiveTexture(GL_TEXTURE0 + 0); // Number between 0 and GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS glBindTexture(GL_TEXTURE_2D, texture);...

OpenGL: GL_FRAMEBUFFER_UNSUPPORTED on specific combinations of framebuffer attachments

Im trying to attach multiple targets to a framebuffer object. I have the following problem: There is no error, when using float texture attachments and a depth attachment. There is also no error, when using float texture attachments and integer texture attachments. Although these combinations work, I cant use float,...

Java: FloatBuffer to OpenGL - wrap() vs. allocate() vs. BufferUtils.createBuffer()

Datasource: float[] v = { ... }; Working example: FloatBuffer buf = BufferUtils.createFloatBuffer(v.length); buf.put(v); buf.flip(); // or buf.rewind() The buffer can now be uploaded to opengl and works fine: ... glBufferData(..., buf, ...); ... Why do the following examples of the buffer creation not also work? Not working 1: FloatBuffer...

OpenGL - translation stretches and distorts sprite

I am loosely following the very handy tutorial at I've been able to create a mesh, draw a sprite to it, and rotate and scale that mesh perfectly fine. However, I'm running into some issues when trying to translate the mesh. (pictures below) Here's an update function on the...

R32I sampler2D returns always 0

I have a (default vertex and) fragment shader that should resize textures and scale their color by a specific factor for brightness correction. The result is rendered into an GL_UNSIGNED_INT_8_8_8_8 framebuffer. #version 330 uniform sampler2D tex; uniform vec2 screenSize; uniform float scale; layout(location = 0) out vec4 color; void main()...

Is it possible to build a heatmap from point data at 60 times per second?

I'm working on a simulation for clouds (actual clouds) where the clouds are simulated by 3D points, then projected into a 2D heatmap, about 640x480 units big. The number of points is about 50k, which is as small as I can go without the simulation breaking, but I can't seem...

Need help finding out why the texture doesn't load

Trying to find a way to render a simple 2D image in Java using OpenGL I stumbled upon a more or less understandable class that does all of the image loading for you which I could not understand how to do. I believe it belongs to a person named Krythic...

Why normal mapping doesn't appear correctly?

I'm applying bump mapping to a tree. When no normal mapping applied, it appears like this. But when a normal texture is used, it turned out to be too aggressive as follow which is ugly. I checked tangent data which should be fine. So I was wondering if it's because...

C++ Opengl - How to load tgas and pngs in modern OpenGL? [on hold]

I am looking for a way to load tgas and pngs in C++ Opengl - I dislike the idea of using a library though. Is there any sample code / links / advice you could give me in this topic?...

Qt OpenGL transform feedback buffer functions missing

I've been following a tutorial series for learning OpenGL, and the current tutorial I'm trying to do involves creating particle systems using the OpenGL transform feedback buffer. In my application I've been using Qt version 5.4.2 for simple 2D interface design, as well as for 3D rendering since it seems...

Win32 Message Pump and std::thread Used to Create OpenGL Context and Render

If I have a function that does the following: bool foo::init() { [Code that creates window] std::thread run(std::bind(&foo::run, this)); while (GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } } Where run is defined as: void foo::run() { [Code that creates initial opengl context] [Code that recreates window based on new...

How to display a textured quad without the texture loaded yet(Android,opengles 2.0)

Currently in my app using opengl es, I have to display a bunch of quads with Different Textures. I want to asynchronously load textures with the quads displaying "blank" until the texture is loaded and start displaying the texture as the texture finishes loading.... what is the most desired way...

Xamarin : Loading resources via GetManifestResourceStream

I am working on a Xamarin forms project to use OpenGL/OpenTK. I am trying to load a shader using GetManifestResourceStream. Whatever I do I get null code is being run from .Shared project, shaders are in .ios / .Android resources directory string prefix; #if __IOS__ prefix = "OpenGLTesting.iOS."; #endif #if...

OpenGL: Defining variables in shaders

My OpenGL program, using GLSL for shaders, has a simple vertex and fragment shader (given by a tutorial). The vertex shader is: #version 330 layout (location = 0) in vec3 Position; void main() { gl_Position = vec4(0.5 * Position.x, 0.5 * Position.y, Position.z, 1.0); } And the fragment shader is:...

OpenGL stops rendering, possibly after an update

I am working on a small OpenGL project using the GLFW library. Everything was fine until from one day, I can't get it to render anything except the background. So I loaded up an older version, which I am sure worked just fine and the same thing happens. I then...

OpenGL, Access violation

I am making an OpenGL project in Visual Studio 2010. I am following a tutorial from youtube. I don't know where the error is, and I have this error: Unhandled exception at 0x00000000 in OpenGL First Game.exe: 0xC0000005: Access violation. Main.cpp #include <GL/glew.h> #include <iostream> #include <GL/glut.h> #include "Sprite.h" Sprite...

How can I render an infinite 2D grid in GLSL?

Ideally, what I'd like to do is draw a single quad and have GLSL handle the creation of the actual gridlines. In my attempt so far the vertex shader: #version 400 layout (location = 0) in vec4 in_position; layout (location = 2) in vec3 in_UV; uniform mat4 model; uniform mat4...

How to do calculation using OpenGL ES 2.0/3.0?

i'm thinking a problem that is it possible to do some arrays calcution using OpenGL ES in mobile devices. For example, i used glTexImage2D to pass shader a float array (which contains some 0.0 and 1.0, such as {0.0, 1.0, 1.0, 0.0, 0.0...}), and i wish to figure out how...

GLSL - program link error: Slot 0 unavailable from layout location request

I'm trying to draw a textured quad copying some code from a tutorial but I'm afraid there is a problem with the shaders. Both the vertex shader and the fragment shader compilation works, but when linking the program I get the error: ERROR: Active attribute aliasing. Slot 0 unavailable for...

OpenGL: Strange bahaviour of VBO deletion?

I am getting a strange issue in Vertex Buffer Object (VBO). I created a class that includes VBO creation and deletion. I delete all the VBOs (with glDeleteBuffers()) in the destructor of the class. Now I created 2 OpenGL context windows each running with VBO class. Now when I close...

Parsing .obj model from SD card Rajawali

I am Working with Rajawali 3D Framework and trying to Load .obj files from SDcard. I am able to upload and parse the obj file when I put these files (.obj, .mtl, texture.png (drawable folder)) on raw folder but when I try to parse it from sdcard it says: [org.rajawali3d.materials.Material]...

No OpenGL context is current in the current thread

I'm following a tutorial on youtube but I have a problem with OpenGL that I'm not able to solve. I have no idea how I can fix it. Exception in thread "EndlessRunner" java.lang.IllegalStateException: No OpenGL context is current in the current thread. at org.lwjgl.opengl.GLContextWindows.createFromCurrent( at org.lwjgl.opengl.GLContext.createFromCurrent( at net.alfredo.Main.init( at

What is the difference between glUseProgram() and glUseShaderProgram()?

In OpenGL what is the difference between glUseProgram() and glUseShaderProgram()? It seems in MESA and Nvidia provided glext.h, and in GLEW, both are defined, and both seem to do basically the same thing. I find documentation for glUseProgram() but not for glUseShaderProgram(). Are they truly interchangeable?...

How to update the “forward” movement in OpenGL

I have a problem with my OpenGL application that you can clearly see in this gif. Basically I would like to move in the direction pointed by the cursor, but this doesn't happen and instead the "forward" direction remains the same. For example if I turn 180° and press "w"...

The order of the linked libraries C++ linker

I was debugging a project that depends on a set of libraries including libfreenect, OpenGL and OpenCL. The problem is that a black screen was the output. As a debugging option, I have removed the OpenCL code and the linked library completely trying to make sure that OpenGL works fine...

GLFW3 create window returns null

I was trying to put all GLFW3 init code from main to separate file. When I'm running the code, I get EXC_BAD_ACCESS on glew init function, because GLFW could not create window. Before code separation everything was ok. Is it possible to have GLFW setup code in other function? I'm...

Spotlight with shadows becomes square-like

I've been following a two part tutorial on shadow mapping from OGLDev (part 1, part 2) for a couple of days now, and I've nearly finished implementing it. My problem is that when I enable shadow maps the illuminated region which shadows appear in appears as a "strip" and I'm...

Programmatically generate texture for WebGL in JavaScript

I have the following code to programmatically generate a texture for WebGL in C. I need to do the same thing in JavaScript for WebGL. How do I properly create the 3 dimensional checkerboard matrix? GLubyte checkerboard[64][64][3]; How do I set the values? checkerboard[i][j][0] = (GLubyte) c; How do I...

Bitmap quality using glReadPixels with frame buffer objects

I have the following issue when exporting a bitmap from frame buffer object on Android using OpenGL 2. I have an image loaded into OpenGL and shown on the screen. The loaded image is bigger than the actual screen, thus I do some matrix manipulation to fit it on the...