Show Posts
|
|
Pages: [1]
|
|
2
|
Java Game APIs & Engines / OpenGL Development / GLSL Multitexturing and Texture Units (glActiveTexture )
|
on: 2012-08-05 19:43:13
|
My game world is rendered into a framebuffer and another texture gets multiplied on top by using a GLSL shader. That works perfectly fine. Now I tried rendering another quad on top of that with a separate shader but had some difficulties getting that to work. In the end I noticed in debug mode that the first frame looks fine and after that the whole screen turns black (except the second quad). After adding "glActiveTexture(GL_TEXTURE1);" to the last line suddenly both quads and both shaders showed up and are working fine. But I have no idea why? Any ideas why I have to change the active Texture Unit back to one? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
| glBindTexture(GL_TEXTURE_2D, 0); glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, worldColor.framebufferID);
glClearColor (1.0f, 1.0f, 1.0f, 1.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
glMatrixMode(GL_PROJECTION); glLoadIdentity();
glOrtho(Player.xPosition-resolution.width/2*camScale, Player.xPosition+resolution.width/2*camScale, Player.yPosition+resolution.height/2*camScale, Player.yPosition-resolution.height/2*camScale, 1, -1); cameraRender = (int)getTime();
glMatrixMode(GL_MODELVIEW); glLoadIdentity();
glActiveTexture(GL_TEXTURE0); sky.render(); skyRender = (int)getTime(); world.render(); worldRender = (int)getTime(); player.render(); playerRender = (int)getTime(); Inventory.render(); inventoryRender = (int)getTime(); Menu.render(); Cursor.render(); DebugScreen.render();
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
glClearColor (1.0f, 1.0f, 1.0f, 1.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
glMatrixMode(GL_PROJECTION); glLoadIdentity();
GL11.glOrtho(0, resolution.width, 0, resolution.height, 1, -1);
glMatrixMode(GL_MODELVIEW); glLoadIdentity();
Color.white.bind();
glUseProgram(light.shaderProgram);
glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, worldColor.colorTextureID); glUniform1i(light.the_location0, 0);
glActiveTexture(GL_TEXTURE1); Tiles.vignette.bind(); glUniform1i(light.the_location1, 1);
glBegin(GL_QUADS); glTexCoord2f(0, 0); glVertex2f(0, 0); glTexCoord2f(1, 0); glVertex2f(resolution.width, 0); glTexCoord2f(1, 1); glVertex2f(resolution.width, resolution.height); glTexCoord2f(0, 1); glVertex2f(0, resolution.height); glEnd();
glUseProgram(0);
glUseProgram(diffuse.shaderProgram);
glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, Tiles.characters1.getTextureID()); glUniform1i(diffuse.the_location0, 0);
glBegin(GL_QUADS); glTexCoord2f(0, 0); glVertex2f(0, 0); glTexCoord2f(1, 0); glVertex2f(200, 0); glTexCoord2f(1, 1); glVertex2f(200, 200); glTexCoord2f(0, 1); glVertex2f(0, 200); glEnd();
glUseProgram(0);
glActiveTexture(GL_TEXTURE1); |
|
|
|
|
|
4
|
Games Center / Showcase / Re: Blasted Crates
|
on: 2012-08-04 17:16:53
|
Great game! But level 8 stage 2 killed it for me. And will not try again.  It kinda seemed while jumping over the second crate that the one on top always exploded a few pixels before I would touch it, which was kinda annoying.
|
|
|
|
|
5
|
Game Development / Newbie & Debugging Questions / Re: How to determine game performance?
|
on: 2012-07-27 07:36:50
|
|
Ok, I did a quick test with a 1024x1024 texture and it seems I will gain around 500 fps. So a bit better but still a lot of room for improvement. Also I haven't tried yet to offset the texture coordinates for each different tile.
I guess my next step is to write a better debug screen to check all the ms, I already have one but it's kinda crap. I'm not really sure if I want to use up all of the 16.67 ms, my system is fairly good and I would like it to be able to run on older machines too. But probably I should move on after implementing the texture atlas and start with the other stuff. Also sound logical that improving stuff will make more sense later on.
Another thing is, I tried using VBOs and Display Lists and didn't really get any performance increase. The performance got even worse. Will it cost more to use those for each tile than just drawing the 4 vertices and texture coordinates directly? If there should be an increase in performance not matter what I will go back and try to fix those.
Anyway thanks for all the great help so far!
|
|
|
|
|
6
|
Game Development / Newbie & Debugging Questions / Re: How to determine game performance?
|
on: 2012-07-27 06:42:51
|
The number of tiles to render is a whole other story anyway, first I want to have a framework with a decent performance before I start working on anything else. If each texture sheet for each material is 64x128 (giving me 128 different tiles for each material) and lets say I want 128 different materials. Making 16,384 individual tiles. That would be 1,048,576 pixels in a 1024x1024 texture. If I'm not mistaken that really doesn't seem so bad. The last time I did this calculation I had a completely different result. Must have been late at night...  So back to the texture atlas again! (and I know the number of different tiles is high, but I would really like to have a system where this is possible) Oh yes, I'm working with LWJGL.
|
|
|
|
|
7
|
Game Development / Newbie & Debugging Questions / Re: How to determine game performance?
|
on: 2012-07-27 06:13:24
|
Yeah your rough guess is pretty close.  Only I'm using 1280x720. Another reason for me to improve performance is that I actually want to render even more at some point. I tried different stuff with texture sheets and without, never changed much in performance. Each tile texture is only 8x8 but I have a lot of them. For example for grass: top, bottom, right, left, all the outer corners, inner corners, single double sided and so on. Plus variations. I was thinking to use an automated texture atlas to bind one big texture with all tiles before drawing the tiles but soon noticed that that would have to be a gigantic texture if I will have a lot of different tile IDs (rock, grass, stone, ...) This code runs for every block: (in this case without texture sheet and textures 8x8 pixels) 1 2 3 4 5 6 7 8 9 10 11
| glBindTexture(GL_TEXTURE_2D, textureID); glBegin(GL_QUADS); glTexCoord2f(0, 0); glVertex2f(x * Tiles.blockScale, y * Tiles.blockScale); glTexCoord2f(1, 0); glVertex2f(x * Tiles.blockScale + Tiles.blockScale, y * Tiles.blockScale); glTexCoord2f(1, 1); glVertex2f(x * Tiles.blockScale + Tiles.blockScale, y * Tiles.blockScale + Tiles.blockScale); glTexCoord2f(0, 1); glVertex2f(x * Tiles.blockScale, y * Tiles.blockScale + Tiles.blockScale); glEnd(); |
I was wondering if there is any better way to draw textures than this.
|
|
|
|
|
8
|
Game Development / Newbie & Debugging Questions / How to determine game performance?
|
on: 2012-07-27 05:03:14
|
I'm fairly new to game programming and I was wondering how to know what a "good" game performance is. My 2D Game consist out of a lot of tiles. With my current camera scale it would be 1400 textured tiles on screen, if the whole screen is covered in them. When that's the case my frames per second drop from 4300 (no tiles on screen) to 1500 (screen covered in tiles). And that's only the terrain. I'm planning to add lighting, more sprites for trees, enemies etc and all the game logic. And I'm wondering if I already lost too much performance on the terrain rendering. I know it always depends on what kind of game, but can you say for example about 50% of the resources go to sprite rendering, 30% go to lighting and 10% each go to game logic and sound? Any advice on performance testing / resource budgeting appreciated! 
|
|
|
|
|
|
Add your game by posting it in the WIP section,
or publish it in Showcase.
The first screenshot will be displayed as a thumbnail.
|
|