Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 10 Apr 2010
Offline Last Active Dec 17 2012 02:42 PM

Topics I've Started

HTML Escape Sequences and Preview Post

28 September 2012 - 06:51 PM

I was typing a response that involved C++ template syntax in a code block, and discovered when I posted that the < and > symbols (and everything between them) had all been removed. I discovered that you could use escape codes to cause the characters to appear correctly and edited those into my post.

Unfortunately, hitting 'preview post' replaces escaped characters with unescaped characters. Thus, hitting 'preview post' twice in a row will result in two different-looking previews, as the second time the now-unescaped characters will be removed. 'preview post' changing what your post will look like upon submit is most certainly a bug.

Could you just automatically replace symbols like < with their escape sequences upon submit? I think the entire rest of your system would work well enough with just that. And it doesn't do anything a user couldn't do themselves, so it could not possibly be a security issue.

Including Normal Data in GLSL Vertex Buffers

19 April 2011 - 06:22 PM

I'm learning how to write GLSL shaders at the moment, and I'm having a few troubles. Mostly, I think my problem is that I don't understand how the stride for attributes is determined.

My vertex shader is like so:
uniform mat4 modelToProjectionMatrix;

in vec3 inputPosition;

void main(void)
   gl_Position = modelToProjectionMatrix* vec4(inputPosition,1.0);

Everything seems to work when I pump an array of these into my vertex buffer:

struct VertexPosition
      float x;
      float y;
      float z;

But when I try to add normals by using an array of these, I think they get interpreted as vertexes.

struct VertexPositionNormalTexture
      float x;
      float y;
      float z;
      float nx;
      float ny; 
      float nz; 
      float s0;
      float t0;

So, how do I increase the stride such that inputPosition always corresponds to x,y,z? I don't even care about using the normals and texture coordinates yet. I just want to ignore all but the first 12 bytes of each 32 byte set in my buffer.

I think it might be that I need to specify glVertexAttrib, but it's not clear to me if attribute locations do indeed map to the buffer in a way that makes sense. Do I need to add padding so Attribute 1 will start at float nx?

(My shader also might be somewhat wrong in how it handles a 12-byte input. It seems to work, but my transformations don't apply unless I add another vect4(0.0, 0.0, 0.0, 1.0). If it's obviously wrong in some way shape or form, that would be good to know.)

Finding and Reserving Open Ports for QUdpSocket

15 March 2011 - 01:24 PM

I'm having a little trouble figuring out how to create UDP sockets on open ports. I'll be running multiple instances of my application on the same computer at the same time, and so it cannot use hardcoded ports. Communication is 2-way, so I need two ports. One port for Component 1 and one port for Component 2. Both components are part of the same process, but are in different threads.

The problem is choosing the ports. As far as I know, you cannot find and reserve a free port without binding to it. So I bind 2 ports. Now I know what ports I can use. Both components need to know both ports in order to send and receive, though they only each really need to bind to the one they receive on. Unfortunately, after the first component binds 2 sockets and tells the second component what ports to use, the second component can't bind to the port it needs (since the first Component is still bound to it).

The preferred solution would be for Component 1 to be able to be able to reserve an open port for Component 2. Perhaps by binding but allowing a second socket on the same port to be bound. Or throwing the socket object across the thread boundary somehow.

I would love if this code printed "Success". (Using Qt 4.5)
void theProblem()
   QHostAddress udpHost("localhost");
   quint16 port = 0;

   QUdpSocket socket;
   socket.bind(udpHost, port);

   createSocketInNewThread(udpHost, socket.localPort());
   sendMessageToSocketInNewThread(udpHost, socket.localPort());

void createSocketInNewThread(const QHostAddress& udpHost, int port)
   // Pretend we're in a new thread.
   QUdpSocket secondSocket;
   bool successfullyBound = secondSocket.bind(udpHost, port);
   qDebug("%s", successfullyBound?"Success":"Failure");