Members

19

252 Neutral

• Rank
Member
1. ## [glsl] converting screen coordinates to view coordinates and back again

It's working now. I used the method (poorly) described here and it magically worked: http://bassser.tumblr.com/post/11626074256/reconstructing-position-from-depth-buffer I'm still struggling a bit with the names of all the coordinate spaces, but I do know that I wasn't passing the correct coordinate space to the inverse projection matrix. I believe it wants NDC space coordinates and I was passing it screen space so I had to divide by w first or something like that, I'm stil looking into it.
2. ## [glsl] converting screen coordinates to view coordinates and back again

For the past 3 days I've been trying to get ssao working without much result. I've narrowed the problem down to the way I'm converting screen coordinates to view coordinates and back again. Below is the code I use to test the conversion.   Attached are the results of the shader and the depth buffer. [removed for now, please check back later]   Anyone able to point out what's going wrong here? Are the screenToViewSpace & viewToScreenSpace functions correct? #version 420 in vec2 vTexCoord; in vec3 vNormal; layout(binding = 0) uniform sampler2D uTexDiffuse; layout(binding = 2) uniform sampler2D uTexDepth; uniform mat4 projectionMatrix; uniform mat4 invProjectionMatrix; out vec4 out_fragColor; vec3 screenToViewSpace(in vec2 texCoord, in float depth) { vec4 position = vec4(texCoord, depth, 1.0); // unpack position.xyz = position.xyz * 2.0 - 1.0; // unproject position = invProjectionMatrix * position; position /= position.w; return position.xyz; } vec2 viewToScreenSpace(in vec3 unprojectedPosition) { vec4 position = vec4(unprojectedPosition, 0.0); // project position = projectionMatrix * position; position /= position.w; // pack position = position * 0.5 + 0.5; return position.xy; } void main() { float depth = texture(uTexDepth, vTexCoord).r; if(vTexCoord.x < 0.5) { // convert to view space, then back to screen space out_fragColor.xy = viewToScreenSpace(screenToViewSpace(vTexCoord, depth)); } else { out_fragColor.xy = vTexCoord; } }
3. ## OpenGL Are attributes shared between programs?

Hi GameDev,   I'm currently working on a game in OpenGL ES 2.0 (Android) and I've ran into a bit of an issue:   I have 2 meshes, both have their own shader object (code below). During initialization I upload the vertexdata (setPositionAttribute & setTextureAttribute). When it's time to draw though, I can only see the 2nd object. So I'm assuming the vertexdata from the 2nd object has replaced the vertexdata from the 1st.   Is this assumption (vertexdata is being shared by all program objects) correct? Is there a way to separate the vertexdata or do I have to upload it each frame?   Edit: problem solved. I forgot to use VBOs. More info here
4. ## Quick question about vertex arrays

works. Thank you
5. ## Quick question about vertex arrays

Is there any way of adding data into the vertice container as if it's an array? [code]struct CUSTOMVERTEX { FLOAT x, y, z; }; CUSTOMVERTEX Vertices[] = { { 0.0f, 0.0f, 0.0f}, { 1.0f, 0.0f, 0.0f}, { 0.0f, 0.0f, 1.0f}, { 1.0f, 0.0f, 1.0f}, }; d3ddev->CreateVertexBuffer(sizeof(Vertices) * sizeof(CUSTOMVERTEX), 0, CUSTOMFVF, D3DPOOL_MANAGED, &v_buffer, NULL); VOID* pVoid; v_buffer->Lock(0, 0, (void**)&pVoid, 0); memcpy(pVoid, Vertices, sizeof(Vertices)); v_buffer->Unlock();[/code] from that into something like this: [code]// NOTE: speudo code CUSTOMVERTEX Vertices[]; Vertices.add(0.0f, 0.0f, 0.0f); Vertices.add(1.0f, 0.0f, 0.0f); Vertices.add(0.0f, 0.0f, 1.0f); Vertices.add(1.0f, 0.0f, 1.0f); d3ddev->CreateVertexBuffer(sizeof(Vertices) * sizeof(CUSTOMVERTEX), 0, CUSTOMFVF, D3DPOOL_MANAGED, &v_buffer, NULL); VOID* pVoid; v_buffer->Lock(0, 0, (void**)&pVoid, 0); memcpy(pVoid, Vertices, sizeof(Vertices)); v_buffer->Unlock();[/code] If you're wondering, I'm planning on stuffing this into a for loop.
6. ## vertex array

Alternate tutorial for index buffers: http://www.directxtutorial.com/Tutorial9/B-Direct3DBasics/dx9B7.aspx
7. ## Question about cpp classes and objects

Something screwed up and removed my reply to your last [i]I think your WNDCLASSEX strucure should be zero initialised for safety.[/i] Like this right? WNDCLASSEX wcex = {0}; Why should I zero initialise it? the variable is local (right?), it gets destroyed after the class [s]initiator[/s] constructor ends. [quote]In dynamic languages it makes more sense because there is no static type checker, nor one definitive place you can go to find the type of a variable. Its a minor stylistic issue, don't sweat it if you prefer it. You might find [url="http://www.joelonsoftware.com/articles/Wrong.html"]this[/url] an interesting read though.[/quote] Makes sence, since the compiler will tell me if I have a type mismatch. It's better to note which kind of variable it is instead of which type. One thing though. What do you think of this line? _hInstance = hInstance; (line 12 of windows.h)
8. ## Question about cpp classes and objects

Thank you [i]- Consider using typedef rather than #define for BUTTON though.[/i] Sorted [i]- Type names are generally written in CamelCase. ALL_CAPS is mostly reserved for constants and preprocessor defines such as include guards.[/i] Sorted, but why are all the win32 types in upper case? [i]- Many people consider hungarian notation to be pointless and verbose, but that is just a stylistic issue.[/i] It worked fine on all my php projects. I like the hungarian notation because I distinguish variables from definitions better. (visual studio doesn't highlight them) [i]- You have little or no error checking. Consider exceptions for errors during object construction.[/i] Yea, I am going to do that after I finish this class. I'm planning on making a custom window template for it, since I don't like the standard MessageBox() function.
9. ## Need advices to get started

You didn't break any rules, FAQ = Frequently Asked Questions... and you just happen to ask one. You can find a link to the FAQ above the first post in a topic or by clicking [url="http://www.gamedev.net/index.php?app=forums&module=forums&section=rules&f=31"]here[/url] /helped
10. ## Question about cpp classes and objects

[quote]I'm not really sure what you are asking. The code you've posted isn't C++. Are you posting psuedo code? Are they supposed to be declarations or definitions?[/quote] 1 It's pseudo code because I wasn't sure how to write it in cpp. I'm used to php's method of defining a class (though I haven't tried anything like this in php either). 2 they're declarations. Thank you for your responce, I'll try it right away. Edit: ok, so how am I doing? (in otherwords, do you see anything that should have been coded in another way or might cause problems later on? [b]main.cpp[/b] [source lang="cpp"]#include <windows.h> #include <tchar.h> //build this into an error class later void error(LPCWSTR text){ //MessageBox(NULL, text, "Error", MB_OK | MB_ICONWARNING); } #include "window.h" int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { window window("title", hInstance); Button button = window.createButton("Submit", 10, 10, 100, 20); //next: add event listener to the button. //The message loop MSG msg = {0}; while(msg.message != WM_QUIT){ if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)){ TranslateMessage(&msg); DispatchMessage(&msg); } } return (int)msg.wParam; }[/source] [b]window.h[/b] [source lang="cpp"]typedef HWND Button; class window { public: int _iWidth, _iHeight; HWND _hWnd; HINSTANCE _hInstance; window(LPCTSTR sName, HINSTANCE hInstance) { _iWidth = 800; _iHeight = 600; _hInstance = hInstance; //Fill in the Window class and register it WNDCLASSEX wcex = {0}; wcex.cbSize = sizeof(WNDCLASSEX); wcex.style = CS_HREDRAW | CS_VREDRAW; wcex.lpfnWndProc = WndProc; wcex.cbClsExtra = 0; wcex.cbWndExtra = 0; wcex.hInstance = _hInstance; wcex.hIcon = NULL; wcex.hIconSm = NULL; wcex.hCursor = LoadCursor(NULL, IDC_ARROW); wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); wcex.lpszMenuName = NULL; wcex.lpszClassName = sName; RegisterClassEx(&wcex); //Create the window _hWnd = CreateWindow(sName, sName, WS_OVERLAPPEDWINDOW | WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, _iWidth, _iHeight, NULL, NULL, _hInstance, NULL); if(!_hWnd){ return; } } ////////////////////////////////////////////////////////// // Create Button // Button createButton(LPCTSTR text, int iX, int iY, int iWidth, int iHeight) { return CreateWindow("BUTTON", text, BS_PUSHBUTTON | WS_CHILD | WS_VISIBLE, iX, iY, iWidth, iHeight, _hWnd, NULL, _hInstance, NULL); } ////////////////////////////////////////////////////////// // Window Procedure // private: static LRESULT CALLBACK WndProc(HWND _hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam){ switch(uMsg){ case WM_DESTROY: PostQuitMessage(0); break; } return DefWindowProc(_hWnd, uMsg, wParam, lParam); } };[/source]
11. ## Question about cpp classes and objects

2 Quick questions; Is it possible for a cpp class to stack like so? [code]WINDOW Window("title"); CHILDWINDOW Window.Child("child title"); BUTTON Window.child.Button("Submit", 10, 10, 100, 20);[/code] And is it possible for an object to access a variable from it's parent? (the child window needs to access hInstance and hWnd from the main window) Thank you.
12. ## Need a bit of help finding a bug

Quote:Original post by yewbie IDirect3DSurface9 *surface; IDirect3DSurface9* surface; They function the same.but what does the asteric do? (I know, noob question right >_>) @noidwright Although a bit puzzling for a noob like me, thank you for your feedback. Here's what I changed the notify function to: bool V_RETURN(HRESULT hResult){ if(FAILED(hResult)){ MessageBox(hWnd,DXGetErrorDescription(hResult), DXGetErrorString(hResult), MB_OK | MB_ICONWARNING); return false; } } I'll see if I can implement the safe release later.