flat assembler
Message board for the users of flat assembler.

Index > Tutorials and Examples > fun opengl game (3D) + guassian blur shader example

Goto page Previous  1, 2, 3, 4  Next
Author
Thread Post new topic Reply to topic
gens



Joined: 18 Feb 2013
Posts: 161
gens 16 Nov 2013, 16:28
havent gotten to multitexturing yet, so i cant give you an example on that

thing with opengl is that there is old opengl and there is modern opengl
in modern you would probably use glActiveTexture to set it up
http://www.opengl.org/sdk/docs/man3/
i am speaking about 3.3 core
that is what i picked to learn
you can use calls from any version with any version

from what i got so far modern works kinda like this:

the driver is a state machine
it keeps track of all the vertices, pixels and shaders
like when you make a buffer using glGenBuffers it returns to you a handle (more like an ID)
you say you want to use that thing in later calls by making it current, by binding it
then when you fill it using glBufferData, that handle points to that data internally
note that it dosent care what is in the buffer, and you can use that data in shaders as you wish

the driver also keeps track in what memory that data is
it also compiles shaders as programs for the gpu to execute
then when tell it to actually draw something it starts the current active program on the gpu (glUseProgram)

modern shader based gpus are basically a bunch of compute units (they call em shaders in opegl context, or whatever)
so ye its a bunch of math processors grouped together in packs so they can share some cache memory
http://www.stanford.edu/~yifanz/images/research/GPUarchitecture_large.png
that is the compute part, there are couple parts to process vertices before it
kinda like http://www.techarp.com/article/NVIDIA/GeForce_8800_TR/8800_architecture.jpg
i remember reading a pdf from nvidia about the 8800
ofc it was full of catchphrases but it did give an overview so it may be worth finding it online

i think texture units are still on a special part of a gpu, but i might be wrong
(why would they still recommend n^2 texture sizes if it was using main memory, idk)

i found this also, intel 4k overview
http://www.ozone3d.net/public/jegx/201204/intel-ivy-bridge-hd4000-diagram-architecture.jpg
also some in depth http://people.freedesktop.org/~marcheu/linuxgraphicsdrivers.pdf (chapter 8 is about opengl)

so shaders are basically compute kernels for massively parallel execution
and you should look at them as just parallel data processors, not dedicated 3D processors
ofc opengl makes it easier to use them for 3D to 2D processing

bdw shaders dont know what you call the buffers you send them

http://pastebin.com/Qf4gfiuD
heres the small program i patched up
it uses the shaders from last post, named " fragmentshader.frag " and " vertexshader.vert "
and they have to be in the same directory as the program (had trouble embedding normal text in C)
fun thing is you can change the shader without recompiling the program itself

if you run windows you need to change usleep() to sleep(10) and maybe clock_gettime() (or just delete it, its to calculate fps)
if i remember GLFW can handle timings too, but i like clock_gettime since its a VDSO in linux glibc

compile with CC -lGL -lglfw -lSOIL
needs soil for loading pictures to RGB
and GLFW 3 for everything else
GLFW has excellent documentation and can do lots of things
Post 16 Nov 2013, 16:28
View user's profile Send private message Reply with quote
randall



Joined: 03 Dec 2011
Posts: 155
Location: Poland
randall 18 Nov 2013, 07:28
Multitexturing in modern OpenGL:

Code:
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, texture0);
// ... create texture 0

glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, texture1);
// ... create texture 1
    


Fragment shader:

Code:
#version 420 core

in Invocation {
  vec2 texcoord;
} fs_in;

layout(location = 0) out vec4 fs_out_color;

layout(binding = 0) uniform sampler2D g_texture0; // tex unit 0
layout(binding = 1) uniform sampler2D g_texture1; // tex unit 1

void main() {
  vec4 s0 = texture(g_texture0, fs_in.texcoord);
  vec4 s1 = texture(g_texture1, fs_in.texcoord);
  fs_out_color = mix(s0, s1, 0.5);
}
    


I am using OpenGL everyday at work for more than 6 years now, so feel free to ask if you have any questions about this API.

BTW, very nice game!
Post 18 Nov 2013, 07:28
View user's profile Send private message Visit poster's website Reply with quote
tthsqe



Joined: 20 May 2009
Posts: 767
tthsqe 19 Nov 2013, 00:23
randall,
thanks for the multitexturing sample. We can assume that GL_TEXTURE0 is active by default? I wanted to try some bump mapping in a hex game (different thread), but it looks like I will only need one texture since the actually look of the pieces is computed by the uv coordinates of the triangle.
I just uploaded a tuned version of this game that I think looks the best. It does a small radius gaussian blur followed by a large radius gassian blur on each of the two layers, and each layers is render at 4 times its display resolution.
I get about 1000fps (the top number in the lower left) on a gtx 850, However, I noticed that once the frame buffers hit a certain size, the performance on a i5-3320 with integrated graphics takes a huge hit.
Post 19 Nov 2013, 00:23
View user's profile Send private message Reply with quote
randall



Joined: 03 Dec 2011
Posts: 155
Location: Poland
randall 19 Nov 2013, 07:00
Yes, GL_TEXTURE0 is active by default (this is required by the OpenGL specification).
Post 19 Nov 2013, 07:00
View user's profile Send private message Visit poster's website Reply with quote
KevinN



Joined: 09 Oct 2012
Posts: 160
KevinN 09 Feb 2014, 00:07
getting out of memory error compiling it. looks cool, hope to learn something from it and perhaps become more valuable!
Post 09 Feb 2014, 00:07
View user's profile Send private message Reply with quote
tthsqe



Joined: 20 May 2009
Posts: 767
tthsqe 09 Feb 2014, 01:04
In the options>compiler setup you will have to increase the memory.
Let me know if it works for you. I didn't optimize either of the two Gaussian blurs, so if your graphics card can't handle the resolution, try changing as
Code:
WINDOW_WIDTH      fix 600
WINDOW_HEIGHT     fix 400
WINDOW_WIDTH_FP   fix '600.0'
WINDOW_HEIGHT_FP  fix '400.0'    

Also, the particles and grid background require quite a bit a processing, so it is triple threaded.
Post 09 Feb 2014, 01:04
View user's profile Send private message Reply with quote
KevinN



Joined: 09 Oct 2012
Posts: 160
KevinN 09 Feb 2014, 01:35
You know, I just upgraded to latest FASM and compiled it with no problem. Not sure if replacing the old fasm version with this new one adjusted memory size. I forgot about that option though. Thanks for reminding me.
Post 09 Feb 2014, 01:35
View user's profile Send private message Reply with quote
sid123



Joined: 30 Jul 2013
Posts: 338
Location: Asia, Singapore
sid123 11 Feb 2014, 12:10
Wh.....a..t..? Seems I have to learn a lot. I'm way behind I guess.
This looks amazing! Better than GTA 5 Smile. FASM is future. Assembly is future. This will tell C
Fanboys what asm can achieve. Cool
I will try it when I'm home.
i3-2370M, 64 bit, 8 GB RAM,Intel HD 9000, nVIDIA GT400. Should that be enough?
Post 11 Feb 2014, 12:10
View user's profile Send private message Reply with quote
tthsqe



Joined: 20 May 2009
Posts: 767
tthsqe 11 Feb 2014, 13:46
I would like to clean up the code a bit, possibly optimize the graphics, and know where it crashed. Kevin, could you tell me where it crashed for you?
Post 11 Feb 2014, 13:46
View user's profile Send private message Reply with quote
KevinN



Joined: 09 Oct 2012
Posts: 160
KevinN 11 Feb 2014, 19:04
tthsqe wrote:
Kevin, could you tell me where it crashed for you?


One exe was crashing when I tried to launch/run it with fasm. Not sure what was up. I deleted it and reassembled and now there is no problem like that.
Post 11 Feb 2014, 19:04
View user's profile Send private message Reply with quote
m3ntal



Joined: 08 Dec 2013
Posts: 296
m3ntal 11 Feb 2014, 23:17
tthsqe: One of the best game examples written in FASM. It works on my roomates PC, but it crashes on my PCs (laptop+itx) on Win7 32BIT. On startup, "C000001Dh: Illegal instruction" (just from this, I would suspect that esp became unbalanced or eip didn't return correctly or some jmp [table+ecx*4]).
Post 11 Feb 2014, 23:17
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4623
Location: Argentina
LocoDelAssembly 11 Feb 2014, 23:43
Wow, this is a super mega example! I'd say it would be better categorized as a whole project rather than example.

m3ntal, maybe your computers don't support SSE4.1? Check with CPU-Z. Or run this program and make sure it terminates without crashing:
Code:
format pe gui 4.0

mpsadbw xmm0, xmm0, 0
ret    
Post 11 Feb 2014, 23:43
View user's profile Send private message Reply with quote
m3ntal



Joined: 08 Dec 2013
Posts: 296
m3ntal 11 Feb 2014, 23:56
Loco: That was it! My CPU doesn't support SSE4.1. VC6 debugger displayed exactly the same error and address.
Post 11 Feb 2014, 23:56
View user's profile Send private message Reply with quote
tthsqe



Joined: 20 May 2009
Posts: 767
tthsqe 12 Feb 2014, 01:00
ok - I am in the process of cleaning up the code. It really does not need sse 4.1 dpps, so am I definitely replacing it. I'm also trying to speed up the graphics, as I am getting very poor results even on haswell GPU. Of course, gtx 580 just plows through it, but this is probably because they have a better driver.
Post 12 Feb 2014, 01:00
View user's profile Send private message Reply with quote
HaHaAnonymous



Joined: 02 Dec 2012
Posts: 1178
Location: Unknown
HaHaAnonymous 12 Feb 2014, 01:06
[ Post removed by author. ]


Last edited by HaHaAnonymous on 28 Feb 2015, 18:14; edited 1 time in total
Post 12 Feb 2014, 01:06
View user's profile Send private message Reply with quote
catafest



Joined: 05 Aug 2010
Posts: 131
catafest 17 Feb 2014, 22:15
... about SSE 4.1 you can find something useful here :
http://software.intel.com/sites/default/files/m/a/9/b/7/b/1000-SSE.pdf
and I have a question about your source code :
what is and where can be found :
call GLCleanup
and this
invoke GetClientRect,[hwnd],rc !!
tthsqe wrote:
ok - I am in the process of cleaning up the code. It really does not need sse 4.1 dpps, so am I definitely replacing it. I'm also trying to speed up the graphics, as I am getting very poor results even on haswell GPU. Of course, gtx 580 just plows through it, but this is probably because they have a better driver.
Post 17 Feb 2014, 22:15
View user's profile Send private message Visit poster's website Yahoo Messenger Reply with quote
tthsqe



Joined: 20 May 2009
Posts: 767
tthsqe 18 Feb 2014, 02:46
call GLCleanup: misc.inc line 380
invoke GetClientRect,[hwnd],rc: I don't think I use this. Instead I have
CorrectMainWindowSize: misc.inc line 879

Now that I look back at the cleanup function, I think I am missing some frame buffers and the shader programs. I;ll have to add clean up code for those as well.
Post 18 Feb 2014, 02:46
View user's profile Send private message Reply with quote
catafest



Joined: 05 Aug 2010
Posts: 131
catafest 18 Feb 2014, 10:01
I take a look ... also why don't use glFlush and OpenGL.GL.ARB
Maybe one video tutorial about how you codding this into real time will help, the code seam clear , just is to big Smile
tthsqe wrote:
call GLCleanup: misc.inc line 380
invoke GetClientRect,[hwnd],rc: I don't think I use this. Instead I have
CorrectMainWindowSize: misc.inc line 879

Now that I look back at the cleanup function, I think I am missing some frame buffers and the shader programs. I;ll have to add clean up code for those as well.
Post 18 Feb 2014, 10:01
View user's profile Send private message Visit poster's website Yahoo Messenger Reply with quote
catafest



Joined: 05 Aug 2010
Posts: 131
catafest 20 Feb 2014, 13:27
@tthsqe : take a look at olly , can help you ...
Post 20 Feb 2014, 13:27
View user's profile Send private message Visit poster's website Yahoo Messenger Reply with quote
tthsqe



Joined: 20 May 2009
Posts: 767
tthsqe 20 Feb 2014, 23:52
@catafest: With what can ollydbg help me? Things seem to be working fine in this example, except that I might not be cleaning everything at the end.
Post 20 Feb 2014, 23:52
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page Previous  1, 2, 3, 4  Next

< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.