Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 04 Feb 2011
Offline Last Active Today, 02:35 PM

#5005972 Non-Microsoft Market Share

Posted by Yours3!f on 01 December 2012 - 02:22 AM

macs have at most 5%, but you can only use OGL 3.x
linux based systems have at most 1%, and latest OGL

For cross platform development you need to use cross platform libraries, and build with non-cross platform IDEs and compilers. For cross platform libraries your best choice IMO would be SFML + OGL + GLEW (and other libs like freetype, freeimage, assimp etc. if needed)
For example I chose cmake to create both a makefile (so yeah gcc/g++) on Linux and a Visual Studio solution on Windows. As far as I know it works for mac too.
On linux your best choice is cmake and kdevelop IMO, but 100 developers will give you 100 answers to this question. You still have other IDEs like Eclipse and Qt Creator.
In my experience OGL has been enough for everything, so I don't see why you'd use DX even on Windows (why would you develop the same thing twice?).

#5005325 sky rendering

Posted by Yours3!f on 29 November 2012 - 09:16 AM


I'm trying to do sky rendering based on this: http://codeflow.org/entries/2011/apr/13/advanced-webgl-part-2-sky-rendering/

I got through most of the set up, I can now render to a cubemap, and display it, however I can't get the inverse view rotation matrix.
This is because I only worked with view-space, projection space so far. I tried to pass the inverse modelview matrix, but that didn't quite work out.
So my question is, is it possible to do this using view-space? If so how?

here's the shader I'm using:
#version 420 core

//uniform mat3 inv_view_rot;
uniform mat4 inv_proj;
uniform mat4 inv_modelview;
uniform vec3 lightdir, kr;
//vec3 kr = vec3(0.18867780436772762, 0.4978442963618773, 0.6616065586417131); // air
uniform float rayleigh_brightness, mie_brightness, spot_brightness, scatter_strength, rayleigh_strength, mie_strength;
uniform float rayleigh_collection_power, mie_collection_power, mie_distribution;
float surface_height = 0.99;
float range = 0.01;
float intensity = 1.8;
const int step_count = 16;

in cross_shader_data
  vec2 tex_coord;
} i;

out vec4 color;

/*vec3 get_world_normal()
  vec2 frag_coord = gl_FragCoord.xy/viewport;
  frag_coord = (frag_coord-0.5)*2.0;
  vec4 device_normal = vec4(frag_coord, 0.0, 1.0);
  vec3 eye_normal = normalize((inv_proj * device_normal).xyz);
  vec3 world_normal = normalize(inv_view_rot*eye_normal);
  return world_normal;

//what i tried to do
vec3 get_world_normal()
vec4 device_coords = vec4(i.tex_coord * 2.0 - 1.0, 0, 0);
return normalize((inv_modelview * inv_proj * device_coords).xyz);

float atmospheric_depth(vec3 position, vec3 dir)
  float a = dot(dir, dir);
  float b = 2.0*dot(dir, position);
  float c = dot(position, position)-1.0;
  float det = b*b-4.0*a*c;
  float detSqrt = sqrt(det);
  float q = (-b - detSqrt)/2.0;
  float t1 = c/q;
  return t1;

float phase(float alpha, float g)
  float a = 3.0*(1.0-g*g);
  float b = 2.0*(2.0+g*g);
  float c = 1.0+alpha*alpha;
  float d = pow(1.0+g*g-2.0*g*alpha, 1.5);
  return (a/b)*(c/d);

float horizon_extinction(vec3 position, vec3 dir, float radius)
  float u = dot(dir, -position);
    return 1.0;
  vec3 near = position + u*dir;
  if(length(near) < radius)
    return 0.0;
    vec3 v2 = normalize(near)*radius - position;
    float diff = acos(dot(normalize(v2), dir));
    return smoothstep(0.0, 1.0, pow(diff*2.0, 3.0));

vec3 absorb(float dist, vec3 color, float factor)
  return color-color*pow(kr, vec3(factor/dist));

void main(void)
  vec3 eyedir = get_world_normal();

  float alpha = dot(eyedir, lightdir);
  float rayleigh_factor = phase(alpha, -0.01)*rayleigh_brightness;
  float mie_factor = phase(alpha, mie_distribution)*mie_brightness;
  float spot = smoothstep(0.0, 15.0, phase(alpha, 0.9995))*spot_brightness;
  vec3 eye_position = vec3(0.0, surface_height, 0.0);
  float eye_depth = atmospheric_depth(eye_position, eyedir);
  float step_length = eye_depth/float(step_count);
  float eye_extinction = horizon_extinction(eye_position, eyedir, surface_height-0.15);

  vec3 rayleigh_collected = vec3(0.0, 0.0, 0.0);
  vec3 mie_collected = vec3(0.0, 0.0, 0.0);

  for(int i=0; i<step_count; i++)
    float sample_distance = step_length*float(i);
    vec3 position = eye_position + eyedir*sample_distance;
    float extinction = horizon_extinction(position, lightdir, surface_height-0.35);
    float sample_depth = atmospheric_depth(position, lightdir);
    vec3 influx = absorb(sample_depth, vec3(intensity), scatter_strength)*extinction;
    rayleigh_collected += absorb(sample_distance, kr*influx, rayleigh_strength);
    mie_collected += absorb(sample_distance, influx, mie_strength);

  rayleigh_collected = (rayleigh_collected*eye_extinction*pow(eye_depth, rayleigh_collection_power))/float(step_count);
  mie_collected = (mie_collected*eye_extinction*pow(eye_depth, mie_collection_power))/float(step_count);

  vec3 result = vec3(spot*mie_collected + mie_factor*mie_collected + rayleigh_factor*rayleigh_collected);
  color = vec4(result + vec3(0.1)/*just to make sure that I am writing to the cubemap*/, 1.0);

EDIT: it seems to work now. I just had to use the original, and pass inverse view matrix (it turned out to be the upper left 3x3 matrix of the modelview matrix), and I had to use the correct cameras (not the players camera, but turned to left, right up, do etc.).

Best regards,

#5003809 driver bug?

Posted by Yours3!f on 24 November 2012 - 02:20 PM

It shouldn't crash under any circumstances, right?

Well... not necessarily. For example, if you give it a garbage pointer or size and cause it to commit an access violation, it's free to crash.

I'm not much of a video programmer, but here's my guess as to why it crashed: glTexImage2D requires you to pass a pointer to the texture data, and in your OP you're passing 0. If you read the docs for that function, it says "If target is GL_PROXY_TEXTURE_2D, GL_PROXY_TEXTURE_1D_ARRAY, GL_PROXY_TEXTURE_CUBE_MAP, or GL_PROXY_TEXTURE_RECTANGLE, no data is read from data." In the next paragraph, it says "If target is GL_TEXTURE_2D, GL_TEXTURE_RECTANGLE or one of the GL_TEXTURE_CUBE_MAP targets, data is read from data..." (emphasis mine) This may explain why it crashes. I could be wrong, but that's my hunch.

well it is read if not 0 is passed.
"data may be a null pointer.
In this case, texture memory is
allocated to accommodate a texture of width width and height height.
You can then download subtextures to initialize this
texture memory.
The image is undefined if the user tries to apply
an uninitialized portion of the texture image to a primitive."

and that function didn't crash, but the fbo checker. And that function doesn't receive any pointer.

#5001214 picking in 2d

Posted by Yours3!f on 15 November 2012 - 07:29 AM

I implemented a simple 2d drawing sysytem that draws points and lines(for now)
I must implement a picking in 2d for intersection of a mouse click and a point and a line.
Has a sense create a ray for the intersection in 2d?
how i can implement these algorithm?
I also have to consider the modelview matrix and the scale/rotate that i can apply to the document .
there is an example?

hey there, I don't really know how to deal with lines (approximate them as thin quads maybe?), but I've recently done this using triangles/quads:

you might get an idea.

#4996807 uniforms

Posted by Yours3!f on 03 November 2012 - 03:16 AM

Why do you need this feature? If it is for the learning sake only, please wait until stable drivers release.
There are several sources of the problem.

What drivers are you using? GL_ARB_explicit_uniform_location is the part of GLSL 4.3 core spec, not 4.2. If you are using NV 310.xx drivers, then there could be a bug, since they are in a beta phase. If you are using previous releases, then you should check whether the extension is supported and probably enable it explicitly in GLSL (if it is supported).

I guess you don't have support GL_ARB_explicit_uniform_location and the reason it works for the first uniform is accidental correspondence with compiler's associated locations. NV uses alphabetical order of names. So, locations are as follows:
0 - mvp
2 - texture0
1 - overlay_color

Before trying to use some new feature check if it is presented and read specification to understand how it works. ;)

:( I'm on AMD with only OGL4.2 drivers... I guess I'll have to stick with glGetUniformLocation...
as for the why: I just wanted to get rid of keeping track of uniform locations. It's not that cumbersome, but it would be great if I didn't have to.
I guess for the rest you're right, I just accidentally got the uniform locations right. Well, thank you for clarifying the situation. I just thought this was available since gl 3.1

#4990024 Using shaders vs fixed pipline

Posted by Yours3!f on 14 October 2012 - 06:51 AM

ok, thanks for all the replies.
I actually am working on the project for a pretty long time now, but switching still may be worth it.
So I decided to learn more about shaders and program two or three and probably I will stick with them.
"Master of my own lighting" sounds very good, but I´d rather like to focus on features for the gameplayPosted Image

Even if I don´t use it in this project in the end, I hope it at least will be worth the experience.

here's a cg implementation of the whole OpenGL fixed function pipeline. Cg is very similar to GLSL so you should have no problem porting it after you learned a bit of GLSL.

#4989810 Using shaders vs fixed pipline

Posted by Yours3!f on 13 October 2012 - 10:33 AM

for each object you need to choose between rendering by shaders or fixed pipeline.
for example you can use shaders for the terrain, but render everything else using the fixed pipeline.
however shaders give you much greater flexibility, and new features (because of programmability).
generally it is only advisable to use fixed pipeline when the given hardware (and driver) can't handle shaders.

and yes, you need to reimplement the fixed function pipeline in the shaders if you want those effects (ie. lighting).

#4973441 Deferred shading and High Range Definition

Posted by Yours3!f on 26 August 2012 - 04:22 AM

since you're doing deferred LIGHTING - and I assume you know the difference between deferred lighting and deferred shading - therefore you have a nice solution by Cryengine 3. In the CE3 slides it is explained how they did this.
Essentially it goes like this:
1. render opaque geometry to the G-Buffer ( 24 bit depth + 8 bit stencil, RGBA8 rgb for normals, a for specular exponent )
2. do the shading pass (ie. read in the 2 textures, do Blinn-Phong shading based on them, and save the result to 2 textures, RGBA16F for diffuse, RGBA16F for specular )
3. re-render the opaque geometry, read in the 2 RGBA16F textures, use early-z using the depth buffer, and combine the shading result with the material properties (ie. surface diffuse color and surface specular color), plus add the ambient term, save the result into a RGBA16F texture.

use this RGBA16F texture for input for further post-processing.

you usually use this resulting texture for depth of field and bloom/hdr/tonemapping. These are usually dependent on each other, so you don't need to blend.

#4966948 OpenGL 4.3 - compute shaders and much more

Posted by Yours3!f on 07 August 2012 - 03:04 AM

CL/GL interop didn't fail to work. It did work quite well. Despite this I have to admit that it is way more complicated than the DX11 compute shaders, BUT it DID work. In fact I could port DX11 compute shaders to OpenCL and make it work together with OpenGL. see:
I'm looking forward to trying out OGL compute shaders though, as it seems more reasonable to use it for processing textures / lighting.
The debugging feature is quite an improvement as such functionality was missing.

#4963060 [HELP] Porting SMAA from Direct3D to OpenGL

Posted by Yours3!f on 25 July 2012 - 02:40 PM


I hope this doesn't count as resurrecting old topic :)
SMAA got finally fixed, it now works in OGL/GLSL, you can find the source code here: https://github.com/scrawl/smaa-opengl

#4962650 Cleanup at end of program

Posted by Yours3!f on 24 July 2012 - 10:30 AM

its important to distinguish between ogl resources and other resources. ogl resources get freed automatically when your drawing context is deleted, that is when you call Window::close. You only want to delete them manually if you want to unload resources at runtime, and load something else, like streaming textures. if you have time for it then it is advisable to do manual deleting just for the sake of practicing.
other resources such as cpu side memory are usually freed by your os upon exit, but special oses may not. you still want to delete stuff here though to make sure youre not doing memory leaking.
Edit: the non-annoying way would be to encapsulate your objects in classes and make a on_delete function in each class. then when you react to the sf::Event::Close, just call the on_delete function of each object, then in the end call window.close(). you may want to employ some kind of global class that holds all these objects in some way, so that you can access your objects anywhere in your code. by making your global class lightweight and the actual objects heavyweight you can easily manage memory later (ie. the global object will live until your app is closed, everybody else dies as soon as they get deleted / get out of context).

#4958342 Seriously don't understand WHY my framebuffer isn't rendering as a te...

Posted by Yours3!f on 12 July 2012 - 04:31 AM

So as a further note, is there a debug tool available that can check the contents of textures/video memory? I'm not sure if there is a problem with rendering to a texture or something happening to the texture (somehow) between the render to the framebuffer and the render to the full screen quad

google: gDEBugger

#4958135 Seriously don't understand WHY my framebuffer isn't rendering as a te...

Posted by Yours3!f on 11 July 2012 - 01:30 PM


here's a tiny little program that does fbos, hope this will help you. (The result you should see is a white triangle)

#include <iostream>

#ifdef _WIN32
#include <Windows.h>
#undef near
#undef far

#include "GL/glew.h" //the mighty GLEW <img src='http://public.gamedev.net//public/style_emoticons/default/smile.png' class='bbc_emoticon' alt=':)' />
#include "SFML/Window.hpp"

 * Global variables

sf::Window the_window;
sf::Event the_event;

float fps = 1.0f;
int frames = 0;
sf::Clock the_clock;
std::string app_path;
#define SCREEN_WIDTH 800
#define SCREEN_HEIGHT 600

GLuint tex;

GLuint fbo;

 * Function declarations

void get_opengl_error( bool ignore = false );

void draw_quad()
  glBegin( GL_QUADS );
  glTexCoord2f( 0, 0 );
  glVertex2f( 0, 0 );
  glTexCoord2f( 1, 0 );
  glVertex2f( 1, 0 );
  glTexCoord2f( 1, 1 );
  glVertex2f( 1, 1 );
  glTexCoord2f( 0, 1 );
  glVertex2f( 0, 1 );

void check_fbo()
  if( glCheckFramebufferStatus( GL_FRAMEBUFFER ) != GL_FRAMEBUFFER_COMPLETE )
    std::cerr << "FBO not complete.\n";
    exit( 1 );

int main( int argc, char* args[] )
   * Initialize OpenGL context

  the_window.create( sf::VideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, 32 ), "FBO", sf::Style::Default );

  if( !the_window.isOpen() )
    std::cerr << "Couldn't initialize SFML.\n";
    exit( 1 );

  GLenum glew_error = glewInit();

  if( glew_error != GLEW_OK )
    std::cerr << "Error initializing GLEW: " << glewGetErrorString( glew_error ) << "\n";
    exit( 1 );

  if( !GLEW_VERSION_3_3 )
    std::cerr << "Error: OpenGL 3.3 is required\n";
    exit( 1 );

   * Initialize and load textures

  glEnable( GL_TEXTURE_2D );

  glGenTextures( 1, &tex );
  glBindTexture( GL_TEXTURE_2D, tex );


   * Initialize FBOs

  GLenum modes[] = { GL_COLOR_ATTACHMENT0 };

  glGenFramebuffers( 1, &fbo );
  glBindFramebuffer( GL_FRAMEBUFFER, fbo );
  glDrawBuffers( 1, modes );
  glFramebufferTexture2D( GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex, 0 );


  glBindFramebuffer( GL_FRAMEBUFFER, 0 );

  glBindTexture( GL_TEXTURE_2D, 0 );


   * Set up matrices

  glViewport( 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT );
  glMatrixMode( GL_PROJECTION );
  //x_min:0, x_max:1, y_min:0, y_max:1, z_min:0, z_max:-1
  float ortho_matrix[] = { 2, 0, 0, 0,
						   0, 2, 0, 0,
						   0, 0, 2, 0,
						   -1, -1, -1, 1
  glLoadMatrixf( ortho_matrix );
  glMatrixMode( GL_MODELVIEW );


   * Generate input

  glBindFramebuffer( GL_FRAMEBUFFER, fbo );

  glClearColor( 0, 0, 0, 0 );

  glTranslatef( 0.5f, 0.5f, 0.0f );
  glBegin( GL_TRIANGLES );
  glColor3f( 1, 1, 1 );
  glVertex2f( -0.25f, -0.25f );
  glVertex2f( 0, 0.25f );
  glVertex2f( 0.25f, -0.25f );

  glBindFramebuffer( GL_FRAMEBUFFER, 0 );




  glEnable( GL_TEXTURE_2D );

  glActiveTexture( GL_TEXTURE0 );
  glBindTexture( GL_TEXTURE_2D, tex );

  while( true )
	 * Handle events

    while( the_window.pollEvent( the_event ) )
	  if( the_event.type == sf::Event::Closed )
	    exit( 0 );



	 * Show the result



    if( the_clock.getElapsedTime().asMilliseconds() > 1000.0f )
	  int timepassed = the_clock.getElapsedTime().asMilliseconds();
	  fps = 1000.0f / ( ( float ) timepassed / ( float ) frames );
	  std::cout << "FPS: " << fps << " Time: " << ( float ) timepassed / ( float ) frames << "\n";
	  frames = 0;
	  timepassed = 0;

  return 0;

void get_opengl_error( bool ignore )
  bool got_error = false;
  GLenum error = 0;
  error = glGetError();
  std::string errorstring = "";

  while( error != GL_NO_ERROR )
    if( error == GL_INVALID_ENUM )
	  //An unacceptable value is specified for an enumerated argument. The offending command is ignored and has no other side effect than to set the error flag.
	  errorstring += "OpenGL error: invalid enum...\n";
	  got_error = true;

    if( error == GL_INVALID_VALUE )
	  //A numeric argument is out of range. The offending command is ignored and has no other side effect than to set the error flag.
	  errorstring += "OpenGL error: invalid value...\n";
	  got_error = true;

    if( error == GL_INVALID_OPERATION )
	  //The specified operation is not allowed in the current state. The offending command is ignored and has no other side effect than to set the error flag.
	  errorstring += "OpenGL error: invalid operation...\n";
	  got_error = true;

    if( error == GL_STACK_OVERFLOW )
	  //This command would cause a stack overflow. The offending command is ignored and has no other side effect than to set the error flag.
	  errorstring += "OpenGL error: stack overflow...\n";
	  got_error = true;

    if( error == GL_STACK_UNDERFLOW )
	  //This command would cause a stack underflow. The offending command is ignored and has no other side effect than to set the error flag.
	  errorstring += "OpenGL error: stack underflow...\n";
	  got_error = true;

    if( error == GL_OUT_OF_MEMORY )
	  //There is not enough memory left to execute the command. The state of the GL is undefined, except for the state of the error flags, after this error is recorded.
	  errorstring += "OpenGL error: out of memory...\n";
	  got_error = true;

    if( error == GL_TABLE_TOO_LARGE )
	  //The specified table exceeds the implementation's maximum supported table size.  The offending command is ignored and has no other side effect than to set the error flag.
	  errorstring += "OpenGL error: table too large...\n";
	  got_error = true;

    error = glGetError();

  if( got_error && !ignore )
    std::cerr << errorstring;

#4948291 Clouds in OpenGL?

Posted by Yours3!f on 11 June 2012 - 02:34 PM

http://lmgtfy.com/?q...cloud rendering


#4941858 Blinn-Phong with Fresnel effect.

Posted by Yours3!f on 21 May 2012 - 02:34 AM

here's the relevant wiki article:
here's Schlick's original paper from 1994:
and if you're successful with implementing the Schlick method, then you may proceed to more advanced approximations:

so for you I think the fresnel term should be:

//Fresnel approximation
float base = 1-dot(f_viewDirection, halfWay);
float exp = pow(base, 5);
float fresnel = fZero + (1 - fZero)*exp;

I've taken a look at the first article (as well as several others that mentioned it). Haven't checked the original paper yet though. Anyhow, the code you wrote is exactly the same as the one I posted, it's just that the one I've posted is re-written. Both of them give: f0 + exp - f0*exp

oh, ok, then you just need to find out how to use the fresnel term, because then you calculated it right...
maybe try to add it:
outputColor.rgb =  ambientReflection + diffuseReflection + specularReflection + fresnel;