#### Archived

This topic is now archived and is closed to further replies.

# OpenGL About to say fuck it and switch back to opengl!

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

## Recommended Posts

Dynamic buffer, dynamic buffer, dynamic buffer... Such a pain in the ass!!! Did anyone of you guys are actually using dynamic buffers and are making them work flawlessly? I mean, I get individual effect running correctly (all the c++ code is absolutly bugless) but mixing indexed and non indexed rendering with dynamic buffer is simply not possible. I get mad at times... The freaking debugger tells me that my arrays and buffers are correct but the freakin directx render only the last primitive! It the third time a ask about dynamic buffer in this forum and no one reply anything... only reply given in this directx forum is about stupid DrawIndexedPrimitiveUP or freakin multitexturing... Comme on is there anybody that work on somethin a little more serious than a 3d version of pong??? I need a real awnser comming out the head of someone who as one! Sorry but I''m always felling the way my program does... this time its real bad !!

##### Share on other sites
Do you really expect a helpful reply to this thread?

##### Share on other sites
At least I got one... ! I want somebody to tell me that he is actually using dynamic buffers and he remarqued something tricky that anyone who is using it should be aware of... like do we discard buffer after each shader switch... or something like that... I read 2000 times the documentation and did what I think they say and its not working.. so I ask and ask again... Do anyone is capable of using dynamic buffers flawlessly?

##### Share on other sites
Checking your profile, I see one message about dynamic buffers in the last six months. Please don''t get upset because somebody doesn''t answer - sometimes people can''t tell from the code you provide, you''re not explicit enough, or somebody just doesn''t have the time/knowledge.

Going back to your original post:

* Never assume a value of 32 bytes (for the vertex size). Use sizeof(...) on your vertex structure. Compilers can do funny things sometimes to your structures.

* If you render enough vertices, get rid of the position tracking in the buffer and just dump the buffer each time.

* Count * 32 in the lock means you are locking # vertices * 32 (so if you are trying to locking 10 vertices, you are actually locking 320). Did you intend to do this?

* Are your lock flags Discard and Append? If so, those are non-standard and may be macros to something else. Check the values of those flags.

* Check your primitive count - it says you are drawing 20 polygons - is that correct?

* What''s your call to DrawIndexedPrimitive look like?

* Are you clearing the vertex source after rendering? Same with textures?

If all else fails, you might want to ftp your code somewhere and see if some kind soul can look at it.

##### Share on other sites
Oups the moderator... I should moderate my words...

------

quote:

* Never assume a value of 32 bytes (for the vertex size). Use sizeof(...) on your vertex structure. Compilers can do funny things sometimes to your structures.

struct OXDynamicVertex
{ float VertexData[8];
}
c/c++ standard -> float = 4bytes -> 4bytes * 8 = 32bytes
packing struct by dword, 32bytes fit into dword adress

------

quote:

Count * 32 in the lock means you are locking # vertices * 32 (so if you are trying to locking 10 vertices, you are actually locking 320). Did you intend to do this?

Second parameter of IDirect3DVertexBuffer8::Lock is sizeToLock not vertexCountToLock... so if I want 10 vertex I need to insert 320 bytes... no?

------

quote:

Are your lock flags Discard and Append? If so, those are non-standard and may be macros to something else. Check the values of those flags.

Buffers created with D3DUSAGE_DYNAMIC|D3DUSAGE_WRITEONLY
Append = D3DLOCK_NOOVERWRITE|D3DLOCK_NOSYSLOCK

------

quote:

What''s your call to DrawIndexedPrimitive look like?

OXRenderInfo::Render (void){    if (indexed)        dev->DrawIndexedPrimitive (PrimitiveType, MinIndex, NumVertices, StartIndex, PrimitiveCount);    else        dev->DrawPrimitive (PrimitiveType, StartVertex, PrimitiveCount);}

refer to this therad for detail about how I set the OXrenderInfo structure before rendering...
[url]
http://www.gamedev.net/community/forums/topic.asp?topic_id=105643
[/url]

##### Share on other sites
quote:

Comme on is there anybody that work on somethin a little more serious than a 3d version of pong???

John Carmack and rest of us...

quote:

only reply given in this directx forum is about stupid DrawIndexedPrimitiveUP

DrawIndexedPrimitiveUP...did you try it? try it, might solve your troubles temporarily...

Also can you explain why you have float[32] in your vertex structure...?

Also do you have your index buffer filled correctly?... i mean are you taking care of the vertex index offset whiled appending of vertices...?

set BaseVertexIndex to 0, if you are rendering the entire VB from start and your index values in the IB are correctly set.

##### Share on other sites
seems to me that you''re using 32-bit ibs. if that''s the case, you should definitely try 16-bit ones first, especially if your hardware has 0xffff for the maxindices caps.
quote:
Original post by Shnoutz
Dynamic buffer, dynamic buffer, dynamic buffer... Such a pain in the ass!!!

they are easy if you spend some time reading the docs and available code samples. there are a couple of classes at developer.nvidia.com that show how to properly use static/dynamic vertex/index buffers, take a look at them.
quote:

Did anyone of you guys are actually using dynamic buffers and are making them work flawlessly?

yes, i''m using dynamic index and vertex buffers for my md3 rendering, and they work flawlessly.
quote:

never assume your code is correct. read the docs, read the samples, compare your code to sample code, put your data in the samples and sample code into your app, etc. etc. nobody said debugging was easy, get used to it.
quote:

I need a real awnser comming out the head of someone who as one!

i hate to tell you this, but i really can''t read others'' code, especially if it''s not formatted nicely and doesn''t have comments. you are asking someone to look at a piece of code from your program, guess what it does, guess what''s wrong with it, and tell you that information. now for someone that may be very obvious, and in those cases you usually get a fast reply, but for others it''s not obvious at all. and in those cases people don''t bother to debug your code because they have their own code to debug. this is the sad truth, unfortunately.
quote:

Sorry but I''m always felling the way my program does... this time its real bad !!

some bugs take long time to fix, accept this and get back to the debugger.

and if you are really clueless as to why the problem occurs, simplify your code to the point where you can compare it with sdk sample code and do a line-by-line comparisons, also exchange code and data as i said above.

---
Come to #directxdev IRC channel on AfterNET

##### Share on other sites
quote:

Second parameter of IDirect3DVertexBuffer8::Lock is sizeToLock not vertexCountToLock... so if I want 10 vertex I need to insert 320 bytes... no?

You''re write - that''s what I get for responding at 1:30 in the morning

quote:

struct OXDynamicVertex
{ float VertexData[8];
}
c/c++ standard -> float = 4bytes -> 4bytes * 8 = 32bytes
packing struct by dword, 32bytes fit into dword adress

I mentioned it, as hardcoding values is a bad thing. Say you add something to the structure later on - you''ll have to search for every instance of the 32 instead of just using sizeof.

As niyaw says, you might want to make sure you aren''t using 32-but indices. Also, set the base index to 0 if you are specifying a start index in the call to DrawIndexedPrimitive (also increase the number of accessed vertices by start+# indices used).

362-3865

##### Share on other sites
quote:

Second parameter of IDirect3DVertexBuffer8::Lock is sizeToLock not vertexCountToLock... so if I want 10 vertex I need to insert 320 bytes... no?

You''re write - that''s what I get for responding at 1:30 in the morning

quote:

struct OXDynamicVertex
{ float VertexData[8];
}
c/c++ standard -> float = 4bytes -> 4bytes * 8 = 32bytes
packing struct by dword, 32bytes fit into dword adress

I mentioned it, as hardcoding values is a bad thing. Say you add something to the structure later on - you''ll have to search for every instance of the 32 instead of just using sizeof.

As niyaw says, you might want to make sure you aren''t using 32-but indices. Also, set the base index to 0 if you are specifying a start index in the call to DrawIndexedPrimitive (also increase the number of accessed vertices by start+# indices used).

##### Share on other sites
Hidden
I don`t see what you mean:

quote:

As niyaw says, you might want to make sure you aren''t using 32-bit indices. Also, set the base index to 0 if you are specifying a start index in the call to DrawIndexedPrimitive (also increase the number of accessed vertices by start+# indices used).

nVidia as a dynamic index buffer class using 32-bits indices... Also, why should I set BaseVertexIndex to 0 if i''m not adressing vertices from 0? I tried using the nvidia dynamic buffers classes and it give me the same result... Wich are : the first effect is working with dynamic vertex and index but the other effects are not working probably because of the cursors in the buffers that are not equal to zero anymore...

• 12
• 10
• 11
• 18
• 13
• ### Similar Content

• Good Evening,
I want to make a 2D game which involves displaying some debug information. Especially for collision, enemy sights and so on ...
First of I was thinking about all those shapes which I need will need for debugging purposes: circles, rectangles, lines, polygons.
I am really stucked right now because of the fundamental question:
Where do I store my vertices positions for each line (object)? Currently I am not using a model matrix because I am using orthographic projection and set the final position within the VBO. That means that if I add a new line I would have to expand the "points" array and re-upload (recall glBufferData) it every time. The other method would be to use a model matrix and a fixed vbo for a line but it would be also messy to exactly create a line from (0,0) to (100,20) calculating the rotation and scale to make it fit.
If I proceed with option 1 "updating the array each frame" I was thinking of having 4 draw calls every frame for the lines vao, polygons vao and so on.
In addition to that I am planning to use some sort of ECS based architecture. So the other question would be:
Should I treat those debug objects as entities/components?
For me it would make sense to treat them as entities but that's creates a new issue with the previous array approach because it would have for example a transform and render component. A special render component for debug objects (no texture etc) ... For me the transform component is also just a matrix but how would I then define a line?
Treating them as components would'nt be a good idea in my eyes because then I would always need an entity. Well entity is just an id !? So maybe its a component?
Regards,
LifeArtist
• By QQemka
Hello. I am coding a small thingy in my spare time. All i want to achieve is to load a heightmap (as the lowest possible walking terrain), some static meshes (elements of the environment) and a dynamic character (meaning i can move, collide with heightmap/static meshes and hold a varying item in a hand ). Got a bunch of questions, or rather problems i can't find solution to myself. Nearly all are deal with graphics/gpu, not the coding part. My c++ is on high enough level.
Let's go:
Heightmap - i obviously want it to be textured, size is hardcoded to 256x256 squares. I can't have one huge texture stretched over entire terrain cause every pixel would be enormous. Thats why i decided to use 2 specified textures. First will be a tileset consisting of 16 square tiles (u v range from 0 to 0.25 for first tile and so on) and second a 256x256 buffer with 0-15 value representing index of the tile from tileset for every heigtmap square. Problem is, how do i blend the edges nicely and make some computationally cheap changes so its not obvious there are only 16 tiles? Is it possible to generate such terrain with some existing program?
Collisions - i want to use bounding sphere and aabb. But should i store them for a model or entity instance? Meaning i have 20 same trees spawned using the same tree model, but every entity got its own transformation (position, scale etc). Storing collision component per instance grats faster access + is precalculated and transformed (takes additional memory, but who cares?), so i stick with this, right? What should i do if object is dynamically rotated? The aabb is no longer aligned and calculating per vertex min/max everytime object rotates/scales is pretty expensive, right?
Drawing aabb - problem similar to above (storing aabb data per instance or model). This time in my opinion per model is enough since every instance also does not have own vertex buffer but uses the shared one (so 20 trees share reference to one tree model). So rendering aabb is about taking the model's aabb, transforming with instance matrix and voila. What about aabb vertex buffer (this is more of a cosmetic question, just curious, bumped onto it in time of writing this). Is it better to make it as 8 points and index buffer (12 lines), or only 2 vertices with min/max x/y/z and having the shaders dynamically generate 6 other vertices and draw the box? Or maybe there should be just ONE 1x1x1 cube box template moved/scaled per entity?
What if one model got a diffuse texture and a normal map, and other has only diffuse? Should i pass some bool flag to shader with that info, or just assume that my game supports only diffuse maps without fancy stuff?
There were several more but i forgot/solved them at time of writing
• By RenanRR
Hi All,
I'm reading the tutorials from learnOpengl site (nice site) and I'm having a question on the camera (https://learnopengl.com/Getting-started/Camera).
I always saw the camera being manipulated with the lookat, but in tutorial I saw the camera being changed through the MVP arrays, which do not seem to be camera, but rather the scene that changes:
#version 330 core layout (location = 0) in vec3 aPos; layout (location = 1) in vec2 aTexCoord; out vec2 TexCoord; uniform mat4 model; uniform mat4 view; uniform mat4 projection; void main() { gl_Position = projection * view * model * vec4(aPos, 1.0f); TexCoord = vec2(aTexCoord.x, aTexCoord.y); } then, the matrix manipulated:
..... glm::mat4 projection = glm::perspective(glm::radians(fov), (float)SCR_WIDTH / (float)SCR_HEIGHT, 0.1f, 100.0f); ourShader.setMat4("projection", projection); .... glm::mat4 view = glm::lookAt(cameraPos, cameraPos + cameraFront, cameraUp); ourShader.setMat4("view", view); .... model = glm::rotate(model, glm::radians(angle), glm::vec3(1.0f, 0.3f, 0.5f)); ourShader.setMat4("model", model);
So, some doubts:
- Why use it like that?
- Is it okay to manipulate the camera that way?
-in this way, are not the vertex's positions that changes instead of the camera?
- I need to pass MVP to all shaders of object in my scenes ?

What it seems, is that the camera stands still and the scenery that changes...
it's right?

Thank you

• Sampling a floating point texture where the alpha channel holds 4-bytes of packed data into the float. I don't know how to cast the raw memory to treat it as an integer so I can perform bit-shifting operations.

int rgbValue = int(textureSample.w);//4 bytes of data packed as color
// algorithm might not be correct and endianness might need switching.
vec3 extractedData = vec3(  rgbValue & 0xFF000000,  (rgbValue << 8) & 0xFF000000, (rgbValue << 16) & 0xFF000000);
extractedData /= 255.0f;

• While writing a simple renderer using OpenGL, I faced an issue with the glGetUniformLocation function. For some reason, the location is coming to be -1.
Anyone has any idea .. what should I do?