Sign in to follow this  

OpenGL artifacts caused by scaling (2D).. (was mini-map thread)

This topic is 4708 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hi, im working on a 2d persistant online RPG. anyway, i have been thinking about a mini-map lately. you know, a kind of radar that appeared in the corner of the screen, so that you could see where you were and where other things were in your area. NOTE: the mini-map i am looking for should not display the entire map - only the area around the player. i was thinking this should be relatively fast and easy to do, but im not sure how to approach it. the easiest way would be to do this: take a screenshot of the map zoomed out in my map editor. then, when loading the map, load in that screenshot to a texture. then, just render a portion of this texture using texture coordinates, depending on where the player is on the map. there are a few downsides to this. the first one being that whenever i make a change to the map, i would have to make a new screenshot of the zoomed out map. the other problem is dynamic portions of the map, e.g. player housing. for that, i would have to over-lay the dynamic portion of the map over the static portion, making it about as difficult as my next, more flexible option. the way i want to do it is this - when loading in the map, i render the entire map, scale it to make it zoomed out, and then render this all to a texture. then, i use this texture how i would normally, just render a portion of this texture based on where the player is. my problem is i dont understand how exactly to do this. im using SDL to load in images and to make the window. i *could* create this in SDL, e.g., load in the image as an SDL_Surface, blit the entire map onto one huge SDL Surface, and then turn this SDL_Surface into a texture. but then, how would i scale this texture? its just kind of confusing, i need to use SDL to create the initial image, but OpenGL to scale it. im just not sure what to do.. thanks for any help. [Edited by - graveyard filla on January 23, 2005 1:25:23 AM]

Share this post


Link to post
Share on other sites
i'm not familiar with SDL but if its like OpenGL then call glViewport with like 256 for width and height (how big you want the texture), then render your map and copy that viewport area to a texture. Boom automatically scaled down texture of the world. Dont forget to set the viewport back to the windows widht and height.

btw another alternative would be to render a minimap every frame, texture generation at beginning would probably be more efficient tho.

HTH

Share this post


Link to post
Share on other sites
A simple possibility would actually be to make your map class abstract enough that you can have both the minimap and your normal generator load it. That way, the minimap simply draws it to a specific part of the screen with more "general" textures. What I mean by this, is that if your map says tiles of type 1-8 are different grass tiles, your minimap may just draw them all as green.

Then you could have your minimap scroll, and draw the same way as your regular map...just smaller, and less detailed.

Just an idea.

Share this post


Link to post
Share on other sites
Quote:
Original post by nts
i'm not familiar with SDL but if its like OpenGL then call glViewport with like 256 for width and height (how big you want the texture), then render your map and copy that viewport area to a texture. Boom automatically scaled down texture of the world. Dont forget to set the viewport back to the windows widht and height.

btw another alternative would be to render a minimap every frame, texture generation at beginning would probably be more efficient tho.

HTH


if you dont mind, could you please explain a little more how to do this and how it works? it sounds exactly what im looking for. i googled for glViewPort() but im not even sure what this does exactly (its been months since ive worked on rendering code [grin]).

thanks for any help.

Share this post


Link to post
Share on other sites
with my current project, I have my map editor save a small 128x128 color rendering of the map form high above with some modificationtions, but overly it seems to have worked for me. in the game I just load the textures from the map files, and use those for a mini map, making the overhead very small.

Share this post


Link to post
Share on other sites
Quote:
Original post by Xero-X2
with my current project, I have my map editor save a small 128x128 color rendering of the map form high above with some modificationtions, but overly it seems to have worked for me. in the game I just load the textures from the map files, and use those for a mini map, making the overhead very small.


And then, instead of changing the texture by adding dots for moving units, you could use points.
That would also be quite efficient together with that last idea I've quoted, especially in a vertex array (VBO's are not good for < 100 triangles, so it's only good in a RTS I guess).

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Quote:
Original post by graveyard filla
Quote:
Original post by nts
i'm not familiar with SDL but if its like OpenGL then call glViewport with like 256 for width and height (how big you want the texture), then render your map and copy that viewport area to a texture. Boom automatically scaled down texture of the world. Dont forget to set the viewport back to the windows widht and height.

btw another alternative would be to render a minimap every frame, texture generation at beginning would probably be more efficient tho.

HTH


if you dont mind, could you please explain a little more how to do this and how it works? it sounds exactly what im looking for. i googled for glViewPort() but im not even sure what this does exactly (its been months since ive worked on rendering code [grin]).

thanks for any help.



glViewport will set the rendering area in your window, usually set to left and top to 0 and the width and height to the window size. If you modify this to (0,0, 256, 256) then everything will be rendered into a very small section of the window (depending on what you use for width and height). You can then copy this viewport area to a texture which will give you your resized minimap texture. Reset the viewport back to the windows size when your done.

HTH

[nts] - If i'm not logged in

Share this post


Link to post
Share on other sites
hey everyone,

ok, ive been working on this, but im stuck. i just cant get it to work.

first of all, it seems like only a screen's worth of the map is being rendered. im not sure how to get the entire map rendered on the screen. i tried scaling(), but then my texture is completely black.

next, what does show up on the screen is a mirrored, or flipped version of what it should be. im not sure why this happends. i was playing with it for awhile and im just getting nowhere. im thinking it appears mirrored because of the parameters of glCopyTexImage2D(), but i played with them and im still not sure..

anyway, let me show the code. first, here is the function which generates the mini-map texture: (notice i followed NeHe tutorials [grin])


GLuint Map::Generate_Mini_Map() // Create An Empty Texture
{
GLuint txtnumber; // Texture ID
unsigned int* data; // Stored Data

// Create Storage Space For Texture Data (128x128x4)
data = (unsigned int*)new GLuint[((256 * 256)* 4 * sizeof(unsigned int))];

std::fill(data,data+((256 * 256)* 4 * sizeof(unsigned int)),0); // Clear Storage Memory

glGenTextures(1, &txtnumber); // Create 1 Texture
glBindTexture(GL_TEXTURE_2D, txtnumber); // Bind The Texture
glTexImage2D(GL_TEXTURE_2D, 0, 4, 256,256, 0,
GL_RGBA, GL_UNSIGNED_BYTE, data); // Build Texture Using Information In data
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);

delete [] data; // Release data

//return txtnumber; // Return The Texture ID
glViewport(0,0,256,256); // Set Our Viewport (Match Texture Size)

Draw_Map_For_Mini_Map(); // Render The Helix

glBindTexture(GL_TEXTURE_2D,txtnumber); // Bind To The Blur Texture

// Copy Our ViewPort To The Blur Texture (From 0,0 To 128,128... No Border)
glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 0, 0, 256, 256, 0);

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear The Screen And Depth Buffer

glViewport(0 , 0,SCREEN_RESW , SCREEN_RESH); // Set Viewport (0,0 to 640x480)

return txtnumber;
}





now, the function Draw_Map_For_Mini_Map() looks like this:

void Map::Draw_Map_For_Mini_Map()
{
glClear(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT);
glPushMatrix();
glColor4f(1.0,1.0f,1.0f,1.0f);

float scale_x = 1.0f;//SCREEN_RESW / (width*32);
float scale_y = 1.0f;//SCREEN_RESH / (height*32);

float invx = 1.0f / scale_x;
float invy = 1.0f / scale_y;

glScalef(scale_x,scale_y,1.0f);

for(int t = 0; t < tilesets.size(); t++)
{
glBindTexture(GL_TEXTURE_2D,tilesets[t].tilemap_texture);//map_data.tilemap_texture[0]

glBegin(GL_QUADS);

for(int y = 0; y < height; ++y)
{
//y draw coordinate, the offset is for smooth scrolling
for(int x = 0; x < width; ++x)
{
Tile &tmp = current_map[y][x];

for(int q = 0; q < tmp.layers.size(); q++)
{
if(tmp.layers[q].layer == -2 && tmp.layers[q].texture == tilesets[t].tilemap_texture)
Draw_Tile((float)(x*32)*invx,(float)(y*32)*invy,tmp.layers[q].x_map_loc,
tmp.layers[q].y_map_loc,tmp.layers[q].t_perc_w,tmp.layers[q].t_perc_h);
}

for(int q = 0; q < tmp.layers.size(); q++)
{
if(tmp.layers[q].layer == -1 && tmp.layers[q].texture == tilesets[t].tilemap_texture)
Draw_Tile((float)(x*32)*invx,(float)(y*32)*invy,tmp.layers[q].x_map_loc,
tmp.layers[q].y_map_loc,tmp.layers[q].t_perc_w,tmp.layers[q].t_perc_h);
}

for(int q = 0; q < tmp.layers.size(); q++)
{
if(tmp.layers[q].layer == 0 && tmp.layers[q].texture == tilesets[t].tilemap_texture)
Draw_Tile((float)(x*32)*invx,(float)(y*32)*invy,tmp.layers[q].x_map_loc,
tmp.layers[q].y_map_loc,tmp.layers[q].t_perc_w,tmp.layers[q].t_perc_h);
}

}//end inner for loop

}//end outer for loop


glEnd();
}


glColor4f(1.0,1.0f,1.0f,1.0f);

for(int t = 0; t < tilesets.size(); t++)
{
glBindTexture(GL_TEXTURE_2D,tilesets[t].tilemap_texture);//map_data.tilemap_texture[0]

glBegin(GL_QUADS);

for(int y = 0; y < height; ++y)
{
//y draw coordinate, the offset is for smooth scrolling
for(int x = 0; x < width; ++x)
{

Tile &tmp = current_map[y][x];

for(int q = 0; q < tmp.layers.size(); q++)
{
if(tmp.layers[q].layer == 1 && tmp.layers[q].texture == tilesets[t].tilemap_texture)
Draw_Tile((float)(x*32)*invx,(float)(y*32)*invy,tmp.layers[q].x_map_loc,
tmp.layers[q].y_map_loc,tmp.layers[q].t_perc_w,tmp.layers[q].t_perc_h);
}

for(int q = 0; q < tmp.layers.size(); q++)
{
if(tmp.layers[q].layer == 2 && tmp.layers[q].texture == tilesets[t].tilemap_texture)
Draw_Tile((float)(x*32)*invx,(float)(y*32)*invy,tmp.layers[q].x_map_loc,
tmp.layers[q].y_map_loc,tmp.layers[q].t_perc_w,tmp.layers[q].t_perc_h);
}

}//end inner for loop


}//end outer for loop

glEnd();

}//end for each texture

glPopMatrix();

SDL_GL_SwapBuffers();

}





if you see, im scaling and trying to render the entire map onto the space, but its just not working like that, so i commented out this line (at around the 5th line of the function) to look like this:

float scale_x = 1.0f;//SCREEN_RESW / (width*32);
float scale_y = 1.0f;//SCREEN_RESH / (height*32);

i only commented out this line and set the scale to 1.0 so that everything would work (except, well, only a screens worth of the map is drawn into the mini-map..i want the entire map). however, in theory, if i make it

float scale_x = SCREEN_RESW / (width*32);
float scale_y = SCREEN_RESH / (height*32);

this should scale enough to fit the entire map into the texture (i think? im not really sure). SCREEN_RESW/H is the resolution of the window (800x600). width/height are the size of the map in tiles. 32 is the tilesize.

maybe i have to scale in relation to the size of the view port, and not of the window? im just not sure...

thanks a lot for any help..

NOTE: some more info

the tilesize is 32x32
the size i want the mini-map texture to be is 256x256

thanks again.

Share this post


Link to post
Share on other sites
I think you are scaling down the map way to much, (assuming your width/height is 256) your scale value is 0.07.
I'm going to assume you realise that a scale of 1 is defaut size, 0.5 half size, 0.25 a quarter....
As for the minimap being mirrored either flip the verts around or the texcoords.

If you are trying to make a minimap as seen in HalfLife, they simply have a pre-generated image, they then render the ents ontop of it.
Yes copying the buffer will get everyting into the minimap, and is easier than drawing each ent ontop, but there is also a price to pay for reading back (although it is diminishing).

Share this post


Link to post
Share on other sites
thanks for the reply.

yes, i understand what scaling is. and no, width/height is the width/height of the map in tiles. a big map is 250x250. a small map is 35x35. yeah, maybe i am scaling wrong.. maybe i dont need to scale at all? but then why is only a screens worth of the map being rendered to the texture? wouldnt i have to scale to fit the whole map?

also, what do you mean by flip the verts/tex coords? and why would i have to do that? im using the same Draw_Tile() function that i use to draw my map each frame. why would it have to be different?

thanks again.

Share this post


Link to post
Share on other sites
ok, i found the answer to both my problems, but of course, a new problem has arised..

first of all, the reason why switching texture coordines didnt work is because i was switching the wrong texture coordinates. i thought you meant i should switch the texture coordinates of the quads i drew on the screen before i converted the screen into a texture. however, i now see you meant to reverse the texture coordinates of the actual quad that i rendered using the texture i got from rendering to a texture.

next, i figured out how to render the entire map onto the texture. i did use scaling. and in fact, the main problem was from from integer division [flaming]. i forgot to cast to float, so my scale factors were 0.0, hence the black texture.

anyway, now on to my new problem. there are visual artifacts appearing in my texture. i think it has to do with scaling... and i think ive read this before, i think i can solve this problem with some sort of texture settings.. basically, i believe this problem is due to the tiles bleeding togeather due to scaling. i have this same exact problem with my map editors "zoom" function. when i zoom out, i just scale everything and draw more quads - the problem is, the tiles seem to bleed togeather unless i am scaling be .5. .5 seems to work fine for some reason (i think another worked fine too, i cant remember what it was though).

anyway, can anyone help me here? here's a few pictures.

first, heres me standing in a small map (around 35x35 tiles). the mini-map is being rendered in the top left corner of the screen. notice how the mini-map has artifacts spread throughout it. in this case, its not very bad or noticable.


now, in this map, its much worse. i belive its much worse because this map is much bigger, and therefore i had to scale a lot more. this map is 250x250 tiles, so the i had to scale a lot (around .1 scale factor).


if you look at the mini-map, the most noticable artifact is those grey lines (which appear to be my grey tiles you see to the left of my character) striping down in almost perfect columns. note that these do NOT exist in the map. they are pure artifacts!

thanks a lot for any help!

Share this post


Link to post
Share on other sites
after talking with some people, it has come to my attention that this is actually a much more difficult problem to solve then i expected. i talked to someone who said theres really no way around this, even using software. is this true? is this really an unsolvable problem?

im using SDL with OpenGL. i thought i could maybe do this in software. render the map into an SDL_Surface, use SDL_gfx to scale it, and then convert that surface to a texture. but apparently this is not possible either? someone said that even using software the same artifacts will appear. how could this be? and is there any nice way to handle this?

what i really dont get is, how is Paint Shop Pro able to shrink images without these artifacts? surely it must be possible then..

thanks a lot for any help.

Share this post


Link to post
Share on other sites
EDIT: NOOO!!! My beautiful post was eaten by the evil cgi error! anywho:

Why not just render-to-texture? it would be (relatively) easy, and you could do it after youve loaded the map (or at any other time really) so it would be quite well suited to your persistent world (NOTE: i admit i didnt read really anything from this thread, so if anyone else has said it, i second it :-D)

hope that helps
-Dan

[Edited by - Ademan555 on January 23, 2005 3:10:42 AM]

Share this post


Link to post
Share on other sites
graveyard filla: The problem is your image size, your storing a largemap into a small texture, if you think about it each tile is likely becoming one pixel or less.
So how do you get around this? You could just use a larger texture, but I would go ahead and say use multiple small textures. This way you wont scale the map down as much, but you'll have to translate it for each texture.
Allternatively dont put the whole level into the minimap - just a subset, like a 3 screen radius, thats one screen offset from the current scroll offset in each direction (negative & positive).

Share this post


Link to post
Share on other sites
@ademan

i already am rendering to a texture

@x-out

well, if you think about it, the texture is 256x256, and the map is 250x250 tiles, so a tile IS a little bigger then a pixel. also, i am not planning on drawing the entire map - i am only going to draw a section of the map, a small piece that represents the area immediately around the player. i dont think rendering a piece of the texture will change anything, if you think about it, either way the texture itself is distorted.

so, how can i do this then? i know its possible by doing something like re-sampling, but i have no clue how to do something like that..

thanks a lot for any more help.

Share this post


Link to post
Share on other sites
You need a higher resolution texture to store it in. Like I said, one tile is becoming more or less 1 pixel.
Just to prove a fact, Half-lifes minimap texture dimensions are 1024*768 (thats split into smaller sections of 256)

Share this post


Link to post
Share on other sites
I would try rendering to a size that is a whole multiple of the map size. If your map is 250x250, and you render it to a texture that's 256x256, each pixel of the texture will hit the texture of the underlying image in a slightly different place.

Think of stretching a grid of 256 horizontal lines and 256 vertical lines over your whole map. The spots where the lines cross would be on a different place in every row. It is those spots that OpenGL is getting the color from.

You also may want to make sure that you're using either bilinear filtering, mipmaping, or both... Apparently the default minification filter is GL_NEAREST_MIPMAP_LINEAR. I don't think it will do much if you haven't set up any mipmap levels, though. You might want to try changing it to GL_LINEAR like this:

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

That should cause it to use the four closest pixels to the point of intersection instead of just the closest pixel.

You might also want to look into the GLU function gluBuild2DMipmaps to automatically generate mipmaps for your tiles as you will get better quality that way than you would with simple linear filtering. =)

Share this post


Link to post
Share on other sites
thanks for the replies.

you guys were right, i resized my map to be 256x256, and the mini-map looks perfect. but, is there anyway to get this to work the way i want, or do my maps have to be a power of 2 for the mini-map to work?

i tried using gluBuild2DMipmaps and GL_LINEAR_MIPMAP_LINEAR, however, this didnt work. the mini-map still looked distorted. also, my regular textures didnt look to right. one of my tiles appeared all grey except at the corners, when normally the tile is grey with slightly darker grey dots spread across it.

thanks a lot for any more help.

Share this post


Link to post
Share on other sites
Just an FYI...

For a minimap you probably shouldn't use mipmapping because you'll really only ever see one mipmap level, so creating all the other levels is just a waste of vram.

Share this post


Link to post
Share on other sites

This topic is 4708 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

  • Forum Statistics

    • Total Topics
      628714
    • Total Posts
      2984357
  • Similar Content

    • By alex1997
      I'm looking to render multiple objects (rectangles) with different shaders. So far I've managed to render one rectangle made out of 2 triangles and apply shader to it, but when it comes to render another I get stucked. Searched for documentations or stuffs that could help me, but everything shows how to render only 1 object. Any tips or help is highly appreciated, thanks!
      Here's my code for rendering one object with shader!
       
      #define GLEW_STATIC #include <stdio.h> #include <GL/glew.h> #include <GLFW/glfw3.h> #include "window.h" #define GLSL(src) "#version 330 core\n" #src // #define ASSERT(expression, msg) if(expression) {fprintf(stderr, "Error on line %d: %s\n", __LINE__, msg);return -1;} int main() { // Init GLFW if (glfwInit() != GL_TRUE) { std::cerr << "Failed to initialize GLFW\n" << std::endl; exit(EXIT_FAILURE); } // Create a rendering window with OpenGL 3.2 context glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); glfwWindowHint(GLFW_RESIZABLE, GL_FALSE); // assing window pointer GLFWwindow *window = glfwCreateWindow(800, 600, "OpenGL", NULL, NULL); glfwMakeContextCurrent(window); // Init GLEW glewExperimental = GL_TRUE; if (glewInit() != GLEW_OK) { std::cerr << "Failed to initialize GLEW\n" << std::endl; exit(EXIT_FAILURE); } // ----------------------------- RESOURCES ----------------------------- // // create gl data const GLfloat positions[8] = { -0.5f, -0.5f, 0.5f, -0.5f, 0.5f, 0.5f, -0.5f, 0.5f, }; const GLuint elements[6] = { 0, 1, 2, 2, 3, 0 }; // Create Vertex Array Object GLuint vao; glGenVertexArrays(1, &vao); glBindVertexArray(vao); // Create a Vertex Buffer Object and copy the vertex data to it GLuint vbo; glGenBuffers(1, &vbo); glBindBuffer(GL_ARRAY_BUFFER, vbo); glBufferData(GL_ARRAY_BUFFER, sizeof(positions), positions, GL_STATIC_DRAW); // Specify the layout of the vertex data glEnableVertexAttribArray(0); // layout(location = 0) glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, 0); // Create a Elements Buffer Object and copy the elements data to it GLuint ebo; glGenBuffers(1, &ebo); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ebo); glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(elements), elements, GL_STATIC_DRAW); // Create and compile the vertex shader const GLchar *vertexSource = GLSL( layout(location = 0) in vec2 position; void main() { gl_Position = vec4(position, 0.0, 1.0); } ); GLuint vertexShader = glCreateShader(GL_VERTEX_SHADER); glShaderSource(vertexShader, 1, &vertexSource, NULL); glCompileShader(vertexShader); // Create and compile the fragment shader const char* fragmentSource = GLSL( out vec4 gl_FragColor; uniform vec2 u_resolution; void main() { vec2 pos = gl_FragCoord.xy / u_resolution; gl_FragColor = vec4(1.0); } ); GLuint fragmentShader = glCreateShader(GL_FRAGMENT_SHADER); glShaderSource(fragmentShader, 1, &fragmentSource, NULL); glCompileShader(fragmentShader); // Link the vertex and fragment shader into a shader program GLuint shaderProgram = glCreateProgram(); glAttachShader(shaderProgram, vertexShader); glAttachShader(shaderProgram, fragmentShader); glLinkProgram(shaderProgram); glUseProgram(shaderProgram); // get uniform's id by name and set value GLint uRes = glGetUniformLocation(shaderProgram, "u_Resolution"); glUniform2f(uRes, 800.0f, 600.0f); // ---------------------------- RENDERING ------------------------------ // while(!glfwWindowShouldClose(window)) { // Clear the screen to black glClear(GL_COLOR_BUFFER_BIT); glClearColor(0.0f, 0.5f, 1.0f, 1.0f); // Draw a rectangle made of 2 triangles -> 6 vertices glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, NULL); // Swap buffers and poll window events glfwSwapBuffers(window); glfwPollEvents(); } // ---------------------------- CLEARING ------------------------------ // // Delete allocated resources glDeleteProgram(shaderProgram); glDeleteShader(fragmentShader); glDeleteShader(vertexShader); glDeleteBuffers(1, &vbo); glDeleteVertexArrays(1, &vao); return 0; }  
    • By Vortez
      Hi guys, im having a little problem fixing a bug in my program since i multi-threaded it. The app is a little video converter i wrote for fun. To help you understand the problem, ill first explain how the program is made. Im using Delphi to do the GUI/Windows part of the code, then im loading a c++ dll for the video conversion. The problem is not related to the video conversion, but with OpenGL only. The code work like this:

       
      DWORD WINAPI JobThread(void *params) { for each files { ... _ConvertVideo(input_name, output_name); } } void EXP_FUNC _ConvertVideo(char *input_fname, char *output_fname) { // Note that im re-initializing and cleaning up OpenGL each time this function is called... CGLEngine GLEngine; ... // Initialize OpenGL GLEngine.Initialize(render_wnd); GLEngine.CreateTexture(dst_width, dst_height, 4); // decode the video and render the frames... for each frames { ... GLEngine.UpdateTexture(pY, pU, pV); GLEngine.Render(); } cleanup: GLEngine.DeleteTexture(); GLEngine.Shutdown(); // video cleanup code... }  
      With a single thread, everything work fine. The problem arise when im starting the thread for a second time, nothing get rendered, but the encoding work fine. For example, if i start the thread with 3 files to process, all of them render fine, but if i start the thread again (with the same batch of files or not...), OpenGL fail to render anything.
      Im pretty sure it has something to do with the rendering context (or maybe the window DC?). Here a snippet of my OpenGL class:
      bool CGLEngine::Initialize(HWND hWnd) { hDC = GetDC(hWnd); if(!SetupPixelFormatDescriptor(hDC)){ ReleaseDC(hWnd, hDC); return false; } hRC = wglCreateContext(hDC); wglMakeCurrent(hDC, hRC); // more code ... return true; } void CGLEngine::Shutdown() { // some code... if(hRC){wglDeleteContext(hRC);} if(hDC){ReleaseDC(hWnd, hDC);} hDC = hRC = NULL; }  
      The full source code is available here. The most relevant files are:
      -OpenGL class (header / source)
      -Main code (header / source)
       
      Thx in advance if anyone can help me.
    • By DiligentDev
      This article uses material originally posted on Diligent Graphics web site.
      Introduction
      Graphics APIs have come a long way from small set of basic commands allowing limited control of configurable stages of early 3D accelerators to very low-level programming interfaces exposing almost every aspect of the underlying graphics hardware. Next-generation APIs, Direct3D12 by Microsoft and Vulkan by Khronos are relatively new and have only started getting widespread adoption and support from hardware vendors, while Direct3D11 and OpenGL are still considered industry standard. New APIs can provide substantial performance and functional improvements, but may not be supported by older hardware. An application targeting wide range of platforms needs to support Direct3D11 and OpenGL. New APIs will not give any advantage when used with old paradigms. It is totally possible to add Direct3D12 support to an existing renderer by implementing Direct3D11 interface through Direct3D12, but this will give zero benefits. Instead, new approaches and rendering architectures that leverage flexibility provided by the next-generation APIs are expected to be developed.
      There are at least four APIs (Direct3D11, Direct3D12, OpenGL/GLES, Vulkan, plus Apple's Metal for iOS and osX platforms) that a cross-platform 3D application may need to support. Writing separate code paths for all APIs is clearly not an option for any real-world application and the need for a cross-platform graphics abstraction layer is evident. The following is the list of requirements that I believe such layer needs to satisfy:
      Lightweight abstractions: the API should be as close to the underlying native APIs as possible to allow an application leverage all available low-level functionality. In many cases this requirement is difficult to achieve because specific features exposed by different APIs may vary considerably. Low performance overhead: the abstraction layer needs to be efficient from performance point of view. If it introduces considerable amount of overhead, there is no point in using it. Convenience: the API needs to be convenient to use. It needs to assist developers in achieving their goals not limiting their control of the graphics hardware. Multithreading: ability to efficiently parallelize work is in the core of Direct3D12 and Vulkan and one of the main selling points of the new APIs. Support for multithreading in a cross-platform layer is a must. Extensibility: no matter how well the API is designed, it still introduces some level of abstraction. In some cases the most efficient way to implement certain functionality is to directly use native API. The abstraction layer needs to provide seamless interoperability with the underlying native APIs to provide a way for the app to add features that may be missing. Diligent Engine is designed to solve these problems. Its main goal is to take advantages of the next-generation APIs such as Direct3D12 and Vulkan, but at the same time provide support for older platforms via Direct3D11, OpenGL and OpenGLES. Diligent Engine exposes common C++ front-end for all supported platforms and provides interoperability with underlying native APIs. It also supports integration with Unity and is designed to be used as graphics subsystem in a standalone game engine, Unity native plugin or any other 3D application. Full source code is available for download at GitHub and is free to use.
      Overview
      Diligent Engine API takes some features from Direct3D11 and Direct3D12 as well as introduces new concepts to hide certain platform-specific details and make the system easy to use. It contains the following main components:
      Render device (IRenderDevice  interface) is responsible for creating all other objects (textures, buffers, shaders, pipeline states, etc.).
      Device context (IDeviceContext interface) is the main interface for recording rendering commands. Similar to Direct3D11, there are immediate context and deferred contexts (which in Direct3D11 implementation map directly to the corresponding context types). Immediate context combines command queue and command list recording functionality. It records commands and submits the command list for execution when it contains sufficient number of commands. Deferred contexts are designed to only record command lists that can be submitted for execution through the immediate context.
      An alternative way to design the API would be to expose command queue and command lists directly. This approach however does not map well to Direct3D11 and OpenGL. Besides, some functionality (such as dynamic descriptor allocation) can be much more efficiently implemented when it is known that a command list is recorded by a certain deferred context from some thread.
      The approach taken in the engine does not limit scalability as the application is expected to create one deferred context per thread, and internally every deferred context records a command list in lock-free fashion. At the same time this approach maps well to older APIs.
      In current implementation, only one immediate context that uses default graphics command queue is created. To support multiple GPUs or multiple command queue types (compute, copy, etc.), it is natural to have one immediate contexts per queue. Cross-context synchronization utilities will be necessary.
      Swap Chain (ISwapChain interface). Swap chain interface represents a chain of back buffers and is responsible for showing the final rendered image on the screen.
      Render device, device contexts and swap chain are created during the engine initialization.
      Resources (ITexture and IBuffer interfaces). There are two types of resources - textures and buffers. There are many different texture types (2D textures, 3D textures, texture array, cubmepas, etc.) that can all be represented by ITexture interface.
      Resources Views (ITextureView and IBufferView interfaces). While textures and buffers are mere data containers, texture views and buffer views describe how the data should be interpreted. For instance, a 2D texture can be used as a render target for rendering commands or as a shader resource.
      Pipeline State (IPipelineState interface). GPU pipeline contains many configurable stages (depth-stencil, rasterizer and blend states, different shader stage, etc.). Direct3D11 uses coarse-grain objects to set all stage parameters at once (for instance, a rasterizer object encompasses all rasterizer attributes), while OpenGL contains myriad functions to fine-grain control every individual attribute of every stage. Both methods do not map very well to modern graphics hardware that combines all states into one monolithic state under the hood. Direct3D12 directly exposes pipeline state object in the API, and Diligent Engine uses the same approach.
      Shader Resource Binding (IShaderResourceBinding interface). Shaders are programs that run on the GPU. Shaders may access various resources (textures and buffers), and setting correspondence between shader variables and actual resources is called resource binding. Resource binding implementation varies considerably between different API. Diligent Engine introduces a new object called shader resource binding that encompasses all resources needed by all shaders in a certain pipeline state.
      API Basics
      Creating Resources
      Device resources are created by the render device. The two main resource types are buffers, which represent linear memory, and textures, which use memory layouts optimized for fast filtering. Graphics APIs usually have a native object that represents linear buffer. Diligent Engine uses IBuffer interface as an abstraction for a native buffer. To create a buffer, one needs to populate BufferDesc structure and call IRenderDevice::CreateBuffer() method as in the following example:
      BufferDesc BuffDesc; BufferDesc.Name = "Uniform buffer"; BuffDesc.BindFlags = BIND_UNIFORM_BUFFER; BuffDesc.Usage = USAGE_DYNAMIC; BuffDesc.uiSizeInBytes = sizeof(ShaderConstants); BuffDesc.CPUAccessFlags = CPU_ACCESS_WRITE; m_pDevice->CreateBuffer( BuffDesc, BufferData(), &m_pConstantBuffer ); While there is usually just one buffer object, different APIs use very different approaches to represent textures. For instance, in Direct3D11, there are ID3D11Texture1D, ID3D11Texture2D, and ID3D11Texture3D objects. In OpenGL, there is individual object for every texture dimension (1D, 2D, 3D, Cube), which may be a texture array, which may also be multisampled (i.e. GL_TEXTURE_2D_MULTISAMPLE_ARRAY). As a result there are nine different GL texture types that Diligent Engine may create under the hood. In Direct3D12, there is only one resource interface. Diligent Engine hides all these details in ITexture interface. There is only one  IRenderDevice::CreateTexture() method that is capable of creating all texture types. Dimension, format, array size and all other parameters are specified by the members of the TextureDesc structure:
      TextureDesc TexDesc; TexDesc.Name = "My texture 2D"; TexDesc.Type = TEXTURE_TYPE_2D; TexDesc.Width = 1024; TexDesc.Height = 1024; TexDesc.Format = TEX_FORMAT_RGBA8_UNORM; TexDesc.Usage = USAGE_DEFAULT; TexDesc.BindFlags = BIND_SHADER_RESOURCE | BIND_RENDER_TARGET | BIND_UNORDERED_ACCESS; TexDesc.Name = "Sample 2D Texture"; m_pRenderDevice->CreateTexture( TexDesc, TextureData(), &m_pTestTex ); If native API supports multithreaded resource creation, textures and buffers can be created by multiple threads simultaneously.
      Interoperability with native API provides access to the native buffer/texture objects and also allows creating Diligent Engine objects from native handles. It allows applications seamlessly integrate native API-specific code with Diligent Engine.
      Next-generation APIs allow fine level-control over how resources are allocated. Diligent Engine does not currently expose this functionality, but it can be added by implementing IResourceAllocator interface that encapsulates specifics of resource allocation and providing this interface to CreateBuffer() or CreateTexture() methods. If null is provided, default allocator should be used.
      Initializing the Pipeline State
      As it was mentioned earlier, Diligent Engine follows next-gen APIs to configure the graphics/compute pipeline. One big Pipelines State Object (PSO) encompasses all required states (all shader stages, input layout description, depth stencil, rasterizer and blend state descriptions etc.). This approach maps directly to Direct3D12/Vulkan, but is also beneficial for older APIs as it eliminates pipeline misconfiguration errors. With many individual calls tweaking various GPU pipeline settings it is very easy to forget to set one of the states or assume the stage is already properly configured when in fact it is not. Using pipeline state object helps avoid these problems as all stages are configured at once.
      Creating Shaders
      While in earlier APIs shaders were bound separately, in the next-generation APIs as well as in Diligent Engine shaders are part of the pipeline state object. The biggest challenge when authoring shaders is that Direct3D and OpenGL/Vulkan use different shader languages (while Apple uses yet another language in their Metal API). Maintaining two versions of every shader is not an option for real applications and Diligent Engine implements shader source code converter that allows shaders authored in HLSL to be translated to GLSL. To create a shader, one needs to populate ShaderCreationAttribs structure. SourceLanguage member of this structure tells the system which language the shader is authored in:
      SHADER_SOURCE_LANGUAGE_DEFAULT - The shader source language matches the underlying graphics API: HLSL for Direct3D11/Direct3D12 mode, and GLSL for OpenGL and OpenGLES modes. SHADER_SOURCE_LANGUAGE_HLSL - The shader source is in HLSL. For OpenGL and OpenGLES modes, the source code will be converted to GLSL. SHADER_SOURCE_LANGUAGE_GLSL - The shader source is in GLSL. There is currently no GLSL to HLSL converter, so this value should only be used for OpenGL and OpenGLES modes. There are two ways to provide the shader source code. The first way is to use Source member. The second way is to provide a file path in FilePath member. Since the engine is entirely decoupled from the platform and the host file system is platform-dependent, the structure exposes pShaderSourceStreamFactory member that is intended to provide the engine access to the file system. If FilePath is provided, shader source factory must also be provided. If the shader source contains any #include directives, the source stream factory will also be used to load these files. The engine provides default implementation for every supported platform that should be sufficient in most cases. Custom implementation can be provided when needed.
      When sampling a texture in a shader, the texture sampler was traditionally specified as separate object that was bound to the pipeline at run time or set as part of the texture object itself. However, in most cases it is known beforehand what kind of sampler will be used in the shader. Next-generation APIs expose new type of sampler called static sampler that can be initialized directly in the pipeline state. Diligent Engine exposes this functionality: when creating a shader, textures can be assigned static samplers. If static sampler is assigned, it will always be used instead of the one initialized in the texture shader resource view. To initialize static samplers, prepare an array of StaticSamplerDesc structures and initialize StaticSamplers and NumStaticSamplers members. Static samplers are more efficient and it is highly recommended to use them whenever possible. On older APIs, static samplers are emulated via generic sampler objects.
      The following is an example of shader initialization:
      ShaderCreationAttribs Attrs; Attrs.Desc.Name = "MyPixelShader"; Attrs.FilePath = "MyShaderFile.fx"; Attrs.SearchDirectories = "shaders;shaders\\inc;"; Attrs.EntryPoint = "MyPixelShader"; Attrs.Desc.ShaderType = SHADER_TYPE_PIXEL; Attrs.SourceLanguage = SHADER_SOURCE_LANGUAGE_HLSL; BasicShaderSourceStreamFactory BasicSSSFactory(Attrs.SearchDirectories); Attrs.pShaderSourceStreamFactory = &BasicSSSFactory; ShaderVariableDesc ShaderVars[] = {     {"g_StaticTexture", SHADER_VARIABLE_TYPE_STATIC},     {"g_MutableTexture", SHADER_VARIABLE_TYPE_MUTABLE},     {"g_DynamicTexture", SHADER_VARIABLE_TYPE_DYNAMIC} }; Attrs.Desc.VariableDesc = ShaderVars; Attrs.Desc.NumVariables = _countof(ShaderVars); Attrs.Desc.DefaultVariableType = SHADER_VARIABLE_TYPE_STATIC; StaticSamplerDesc StaticSampler; StaticSampler.Desc.MinFilter = FILTER_TYPE_LINEAR; StaticSampler.Desc.MagFilter = FILTER_TYPE_LINEAR; StaticSampler.Desc.MipFilter = FILTER_TYPE_LINEAR; StaticSampler.TextureName = "g_MutableTexture"; Attrs.Desc.NumStaticSamplers = 1; Attrs.Desc.StaticSamplers = &StaticSampler; ShaderMacroHelper Macros; Macros.AddShaderMacro("USE_SHADOWS", 1); Macros.AddShaderMacro("NUM_SHADOW_SAMPLES", 4); Macros.Finalize(); Attrs.Macros = Macros; RefCntAutoPtr<IShader> pShader; m_pDevice->CreateShader( Attrs, &pShader );
      Creating the Pipeline State Object
      After all required shaders are created, the rest of the fields of the PipelineStateDesc structure provide depth-stencil, rasterizer, and blend state descriptions, the number and format of render targets, input layout format, etc. For instance, rasterizer state can be described as follows:
      PipelineStateDesc PSODesc; RasterizerStateDesc &RasterizerDesc = PSODesc.GraphicsPipeline.RasterizerDesc; RasterizerDesc.FillMode = FILL_MODE_SOLID; RasterizerDesc.CullMode = CULL_MODE_NONE; RasterizerDesc.FrontCounterClockwise = True; RasterizerDesc.ScissorEnable = True; RasterizerDesc.AntialiasedLineEnable = False; Depth-stencil and blend states are defined in a similar fashion.
      Another important thing that pipeline state object encompasses is the input layout description that defines how inputs to the vertex shader, which is the very first shader stage, should be read from the memory. Input layout may define several vertex streams that contain values of different formats and sizes:
      // Define input layout InputLayoutDesc &Layout = PSODesc.GraphicsPipeline.InputLayout; LayoutElement TextLayoutElems[] = {     LayoutElement( 0, 0, 3, VT_FLOAT32, False ),     LayoutElement( 1, 0, 4, VT_UINT8, True ),     LayoutElement( 2, 0, 2, VT_FLOAT32, False ), }; Layout.LayoutElements = TextLayoutElems; Layout.NumElements = _countof( TextLayoutElems ); Finally, pipeline state defines primitive topology type. When all required members are initialized, a pipeline state object can be created by IRenderDevice::CreatePipelineState() method:
      // Define shader and primitive topology PSODesc.GraphicsPipeline.PrimitiveTopologyType = PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE; PSODesc.GraphicsPipeline.pVS = pVertexShader; PSODesc.GraphicsPipeline.pPS = pPixelShader; PSODesc.Name = "My pipeline state"; m_pDev->CreatePipelineState(PSODesc, &m_pPSO); When PSO object is bound to the pipeline, the engine invokes all API-specific commands to set all states specified by the object. In case of Direct3D12 this maps directly to setting the D3D12 PSO object. In case of Direct3D11, this involves setting individual state objects (such as rasterizer and blend states), shaders, input layout etc. In case of OpenGL, this requires a number of fine-grain state tweaking calls. Diligent Engine keeps track of currently bound states and only calls functions to update these states that have actually changed.
      Binding Shader Resources
      Direct3D11 and OpenGL utilize fine-grain resource binding models, where an application binds individual buffers and textures to certain shader or program resource binding slots. Direct3D12 uses a very different approach, where resource descriptors are grouped into tables, and an application can bind all resources in the table at once by setting the table in the command list. Resource binding model in Diligent Engine is designed to leverage this new method. It introduces a new object called shader resource binding that encapsulates all resource bindings required for all shaders in a certain pipeline state. It also introduces the classification of shader variables based on the frequency of expected change that helps the engine group them into tables under the hood:
      Static variables (SHADER_VARIABLE_TYPE_STATIC) are variables that are expected to be set only once. They may not be changed once a resource is bound to the variable. Such variables are intended to hold global constants such as camera attributes or global light attributes constant buffers. Mutable variables (SHADER_VARIABLE_TYPE_MUTABLE) define resources that are expected to change on a per-material frequency. Examples may include diffuse textures, normal maps etc. Dynamic variables (SHADER_VARIABLE_TYPE_DYNAMIC) are expected to change frequently and randomly. Shader variable type must be specified during shader creation by populating an array of ShaderVariableDesc structures and initializing ShaderCreationAttribs::Desc::VariableDesc and ShaderCreationAttribs::Desc::NumVariables members (see example of shader creation above).
      Static variables cannot be changed once a resource is bound to the variable. They are bound directly to the shader object. For instance, a shadow map texture is not expected to change after it is created, so it can be bound directly to the shader:
      PixelShader->GetShaderVariable( "g_tex2DShadowMap" )->Set( pShadowMapSRV ); Mutable and dynamic variables are bound via a new Shader Resource Binding object (SRB) that is created by the pipeline state (IPipelineState::CreateShaderResourceBinding()):
      m_pPSO->CreateShaderResourceBinding(&m_pSRB); Note that an SRB is only compatible with the pipeline state it was created from. SRB object inherits all static bindings from shaders in the pipeline, but is not allowed to change them.
      Mutable resources can only be set once for every instance of a shader resource binding. Such resources are intended to define specific material properties. For instance, a diffuse texture for a specific material is not expected to change once the material is defined and can be set right after the SRB object has been created:
      m_pSRB->GetVariable(SHADER_TYPE_PIXEL, "tex2DDiffuse")->Set(pDiffuseTexSRV); In some cases it is necessary to bind a new resource to a variable every time a draw command is invoked. Such variables should be labeled as dynamic, which will allow setting them multiple times through the same SRB object:
      m_pSRB->GetVariable(SHADER_TYPE_VERTEX, "cbRandomAttribs")->Set(pRandomAttrsCB); Under the hood, the engine pre-allocates descriptor tables for static and mutable resources when an SRB objcet is created. Space for dynamic resources is dynamically allocated at run time. Static and mutable resources are thus more efficient and should be used whenever possible.
      As you can see, Diligent Engine does not expose low-level details of how resources are bound to shader variables. One reason for this is that these details are very different for various APIs. The other reason is that using low-level binding methods is extremely error-prone: it is very easy to forget to bind some resource, or bind incorrect resource such as bind a buffer to the variable that is in fact a texture, especially during shader development when everything changes fast. Diligent Engine instead relies on shader reflection system to automatically query the list of all shader variables. Grouping variables based on three types mentioned above allows the engine to create optimized layout and take heavy lifting of matching resources to API-specific resource location, register or descriptor in the table.
      This post gives more details about the resource binding model in Diligent Engine.
      Setting the Pipeline State and Committing Shader Resources
      Before any draw or compute command can be invoked, the pipeline state needs to be bound to the context:
      m_pContext->SetPipelineState(m_pPSO); Under the hood, the engine sets the internal PSO object in the command list or calls all the required native API functions to properly configure all pipeline stages.
      The next step is to bind all required shader resources to the GPU pipeline, which is accomplished by IDeviceContext::CommitShaderResources() method:
      m_pContext->CommitShaderResources(m_pSRB, COMMIT_SHADER_RESOURCES_FLAG_TRANSITION_RESOURCES); The method takes a pointer to the shader resource binding object and makes all resources the object holds available for the shaders. In the case of D3D12, this only requires setting appropriate descriptor tables in the command list. For older APIs, this typically requires setting all resources individually.
      Next-generation APIs require the application to track the state of every resource and explicitly inform the system about all state transitions. For instance, if a texture was used as render target before, while the next draw command is going to use it as shader resource, a transition barrier needs to be executed. Diligent Engine does the heavy lifting of state tracking.  When CommitShaderResources() method is called with COMMIT_SHADER_RESOURCES_FLAG_TRANSITION_RESOURCES flag, the engine commits and transitions resources to correct states at the same time. Note that transitioning resources does introduce some overhead. The engine tracks state of every resource and it will not issue the barrier if the state is already correct. But checking resource state is an overhead that can sometimes be avoided. The engine provides IDeviceContext::TransitionShaderResources() method that only transitions resources:
      m_pContext->TransitionShaderResources(m_pPSO, m_pSRB); In some scenarios it is more efficient to transition resources once and then only commit them.
      Invoking Draw Command
      The final step is to set states that are not part of the PSO, such as render targets, vertex and index buffers. Diligent Engine uses Direct3D11-syle API that is translated to other native API calls under the hood:
      ITextureView *pRTVs[] = {m_pRTV}; m_pContext->SetRenderTargets(_countof( pRTVs ), pRTVs, m_pDSV); // Clear render target and depth buffer const float zero[4] = {0, 0, 0, 0}; m_pContext->ClearRenderTarget(nullptr, zero); m_pContext->ClearDepthStencil(nullptr, CLEAR_DEPTH_FLAG, 1.f); // Set vertex and index buffers IBuffer *buffer[] = {m_pVertexBuffer}; Uint32 offsets[] = {0}; Uint32 strides[] = {sizeof(MyVertex)}; m_pContext->SetVertexBuffers(0, 1, buffer, strides, offsets, SET_VERTEX_BUFFERS_FLAG_RESET); m_pContext->SetIndexBuffer(m_pIndexBuffer, 0); Different native APIs use various set of function to execute draw commands depending on command details (if the command is indexed, instanced or both, what offsets in the source buffers are used etc.). For instance, there are 5 draw commands in Direct3D11 and more than 9 commands in OpenGL with something like glDrawElementsInstancedBaseVertexBaseInstance not uncommon. Diligent Engine hides all details with single IDeviceContext::Draw() method that takes takes DrawAttribs structure as an argument. The structure members define all attributes required to perform the command (primitive topology, number of vertices or indices, if draw call is indexed or not, if draw call is instanced or not, if draw call is indirect or not, etc.). For example:
      DrawAttribs attrs; attrs.IsIndexed = true; attrs.IndexType = VT_UINT16; attrs.NumIndices = 36; attrs.Topology = PRIMITIVE_TOPOLOGY_TRIANGLE_LIST; pContext->Draw(attrs); For compute commands, there is IDeviceContext::DispatchCompute() method that takes DispatchComputeAttribs structure that defines compute grid dimension.
      Source Code
      Full engine source code is available on GitHub and is free to use. The repository contains two samples, asteroids performance benchmark and example Unity project that uses Diligent Engine in native plugin.
      AntTweakBar sample is Diligent Engine’s “Hello World” example.

       
      Atmospheric scattering sample is a more advanced example. It demonstrates how Diligent Engine can be used to implement various rendering tasks: loading textures from files, using complex shaders, rendering to multiple render targets, using compute shaders and unordered access views, etc.

      Asteroids performance benchmark is based on this demo developed by Intel. It renders 50,000 unique textured asteroids and allows comparing performance of Direct3D11 and Direct3D12 implementations. Every asteroid is a combination of one of 1000 unique meshes and one of 10 unique textures.

      Finally, there is an example project that shows how Diligent Engine can be integrated with Unity.

      Future Work
      The engine is under active development. It currently supports Windows desktop, Universal Windows and Android platforms. Direct3D11, Direct3D12, OpenGL/GLES backends are now feature complete. Vulkan backend is coming next, and support for more platforms is planned.
    • By michaeldodis
      I've started building a small library, that can render pie menu GUI in legacy opengl, planning to add some traditional elements of course.
      It's interface is similar to something you'd see in IMGUI. It's written in C.
      Early version of the library
      I'd really love to hear anyone's thoughts on this, any suggestions on what features you'd want to see in a library like this? 
      Thanks in advance!
    • By Michael Aganier
      I have this 2D game which currently eats up to 200k draw calls per frame. The performance is acceptable, but I want a lot more than that. I need to batch my sprite drawing, but I'm not sure what's the best way in OpenGL 3.3 (to keep compatibility with older machines).
      Each individual sprite move independently almost every frame and their is a variety of textures and animations. What's the fastest way to render a lot of dynamic sprites? Should I map all my data to the GPU and update it all the time? Should I setup my data in the RAM and send it to the GPU all at once? Should I use one draw call per sprite and let the matrices apply the transformations or should I compute the transformations in a world vbo on the CPU so that they can be rendered by a single draw call?
  • Popular Now