• Advertisement

Matt328

Member
  • Content count

    148
  • Joined

  • Last visited

Community Reputation

272 Neutral

About Matt328

  • Rank
    GDNet+
  1. Lua with CML

    I got this figured out, I was really close, but missing the signature for a function pointer to member is different than a function pointer to a free function. .addFunction("__add", (Vector3&(Vector3::*)(const Vector3&))&Vector3::operator+=) I had * instead of Vector3::* in the middle of the function pointer type.
  2. Lua with CML

    That is what I hve been trying but poking around in the dark at the end of a very long day trying to guess the function signature had been less than effective. Even when I use auto, the compiler can't figure it out I guess because there are multiple overrides of the operator+= function. I think that is why .addFunction is complaining and making me explicitly cast to one of them. I've also tried using decltype to determine the signature, but with the same results. I was also unable to get operator[] to work and I now realize for the same reason. I am able to define a helper struct and delegate to the original object but I'd rather not have to do that especially if it is as trivial as figuring out what the compiler thinks the function signatures are. I'm using clang with C++14 support if that helps.
  3. I'm having trouble binding pretty much any classes from CML (configurable math library) to Lua. Due to them being such a tangled mess of templates and macros, I can't seem to find the function signatures for the overloaded operator functions.  I'm trying to use LuaBridge right now to register the cml::vector3f::operator+= function, and since there are so many overloads, I think I have to cast the address of the function to the function signature I want it to bind.  Currently I'm trying:  .addFunction("__add", (Vector3& (*)(const Vector3&))&Vector3::operator+=) (I have Vector3 typedef'ed to cml::vector3f) but that produces: Address of overloaded function 'operator+=' does not match required type 'cml::vector<float, cml::fixed<3, -1> > &(const cml::vector<float, cml::fixed<3, -1> > &)' I'm just about ready to punt on scripting altogether and just do everything in C++.
  4. OpenGL Interleaved Arrays

    Figured this out. In line 43 of my second code snip, notice anything wrong there? I bind the vertex buffer again, and give it the index data. No wonder nothing was getting rendered, and my vertex buffer was corrupted. What tipped me off, as I was just about to call it a night, i was staring at the Vertex Buffer Objects node in gDEBugger, and noticed VBO2 said something to the effect of 'not attached'. Not attached? And why is my index data showing up in VBO1 if I'm setting data in the vertex buffer first, I would think the index data would be in VBO2. Thanks to Neilo and Brother Bob though for pointing out VAOs. They are pretty slick.
  5. I believe that's what I'm trying to do. Coming from DirectX, you would define a structure for your vertices, pack up a position, normal, texturecoords, whatever else your shader needed, and bind an array of them to the api to be drawn using an index buffer. I'm trying to get that same thing going with OpenGL 4.2, and having a hard time getting anything rendered on the screen.   Here is my vertex structure: struct VertexPositionNormalTexture { float x, y, z; //Vertex float nx, ny, nz; //Normal float s0, t0; //Texcoord0 }; Here is creation of my buffer objects: BWResult create_cube_geometry(Geometry* geometry, VertexType type) { VertexPositionNormalTexture pvertex[3]; //VERTEX 0 pvertex[0].x = 0.0; pvertex[0].y = 0.0; pvertex[0].z = 0.0; pvertex[0].nx = 0.0; pvertex[0].ny = 0.0; pvertex[0].nz = 1.0; pvertex[0].s0 = 0.0; pvertex[0].t0 = 0.0; //VERTEX 1 pvertex[1].x = 1.0; pvertex[1].y = 0.0; pvertex[1].z = 0.0; pvertex[1].nx = 0.0; pvertex[1].ny = 0.0; pvertex[1].nz = 1.0; pvertex[1].s0 = 1.0; pvertex[1].t0 = 0.0; //VERTEX 2 pvertex[2].x = 0.0; pvertex[2].y = 1.0; pvertex[2].z = 0.0; pvertex[2].nx = 0.0; pvertex[2].ny = 0.0; pvertex[2].nz = 1.0; pvertex[2].s0 = 0.0; pvertex[2].t0 = 1.0; GLushort indices[3]; indices[0] = 0; indices[1] = 1; indices[2] = 2; GLuint vertexBuffer; glGenBuffers(1, &vertexBuffer); glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer); glBufferData(GL_ARRAY_BUFFER, sizeof(VertexPositionNormalTexture) * 4, pvertex, GL_STATIC_DRAW); GLuint indexBuffer; glGenBuffers(1, &indexBuffer); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vertexBuffer); glBufferData(GL_ELEMENT_ARRAY_BUFFER, 3 * sizeof(GLushort), indices, GL_STATIC_DRAW); geometry->indexBufferId = indexBuffer; geometry->vertexBufferId = vertexBuffer; geometry->vertexType = VERTEX_PNT; geometry->indexBufferSize = 6; geometry->vertexSize = sizeof(GLfloat) * 8; geometry->offset1 = sizeof(GLfloat) * 3; geometry->offset2 = geometry->offset1 + (sizeof(GLfloat) * 3); return BW_SUCCESS; } And here is the function that renders the object: void render_geometry(Geometry geometry, ShaderInfo shaderInfo) { glBindBuffer(GL_ARRAY_BUFFER, geometry.vertexBufferId); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, geometry.indexBufferId); // Set Position Pointer GLuint positionAttribute = glGetAttribLocation(shaderInfo.programId, "position"); glEnableVertexAttribArray(positionAttribute); glVertexAttribPointer(positionAttribute, 3, GL_FLOAT, GL_FALSE, geometry.vertexSize, BUFFER_OFFSET(0)); // Set Normal Pointer GLuint normalAttribute = glGetAttribLocation(shaderInfo.programId, "normal"); glEnableVertexAttribArray(normalAttribute); glVertexAttribPointer(normalAttribute, 3, GL_FLOAT, GL_FALSE, geometry.vertexSize, BUFFER_OFFSET(12)); // Set TexCoord Pointer GLuint texCoordAttribute = glGetAttribLocation(shaderInfo.programId, "texCoord"); glEnableVertexAttribArray(texCoordAttribute); glVertexAttribPointer(texCoordAttribute, 2, GL_FLOAT, GL_FALSE, geometry.vertexSize, BUFFER_OFFSET(24)); glDrawElements(GL_TRIANGLE_STRIP, 3, GL_UNSIGNED_SHORT, BUFFER_OFFSET(0)); glDisableVertexAttribArray(positionAttribute); glDisableVertexAttribArray(normalAttribute); glDisableVertexAttribArray(texCoordAttribute); } And in my main area for now, i'm doing this in my loop: glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); running = !glfwGetKey(GLFW_KEY_ESC) && glfwGetWindowParam(GLFW_OPENED); glUseProgram(shader_info.programId); GLuint matrixId = glGetUniformLocation(shader_info.programId, "MVP"); glUniformMatrix4fv(matrixId, 1, GL_FALSE, &mvp[0][0]); render_geometry(geo, shader_info); glUseProgram(0); glfwSwapBuffers(); One last piece that may be relevant, here is how I am creating my model-view-projection matrix: glm::mat4 projection = glm::perspective(45.0f, 16.0f / 9.0f, 0.1f, 100.0f); glm::mat4 view = glm::lookAt(glm::vec3(0, 0, 10), glm::vec3(0, 0, 0), glm::vec3(0, 1, 0)); glm::mat4 model = glm::mat4(1.0f); glm::mat4 mvp = projection * view * model; I lied, you may need to check out my vertex shader as well: #version 330 layout(location = 0) in vec3 position; layout(location = 1) in vec2 texCoord; out vec2 UV; uniform mat4 MVP; void main() { vec4 v = vec4(position, 1); gl_Position = MVP * v; UV = texCoord; } I have a fragment shader that just sets the color to white for now. Sorry for the code dumps, but I think that is all the main parts where I might have something messed up. With DX, I would fire up PIX and be able to look at the contents of a) the bound buffer, and b) debug the individual vertices through the shader stages to find out where something went wrong. With gDEBugger, in the 'Textures, Buffers, and Images viewer' when I click on my VBO that should contain my vertices, I get 'Unable to load Buffer'. I'm guessing that is indicating something is messed up with the way I'm binding my buffer, or specifying its data, but I can't for the life of me find a complete example using interleaved arrays with modern OpenGL.
  6. Horizon SkyDome Sun Shader

    Awhile back I started to come up with a 'close enough' approach to rendering the sun in the sky. [url="http://matt328.wordpress.com/category/xna/"]http://matt328.wordpress.com/category/xna/[/url] These two posts here try to detail what I've done. It's nowhere near the aforementioned models and pretty incomplete, but if you're just looking for somewhere to start your own implementation, you might find them interesting reads.
  7. Whats wrong with TinyXml++? Its a few source files you can drop into your project and code written with it is about as concise as parsing xml can be. The few times I've had to parse xml in C++ its worked pretty well for me. It might not be the fastest thing there is, but the decision to use xml pretty much admits that you favor human readability over performance anyway. Edit: Doh i see you were looking for something that validates against a schema which I don't think TinyXml++ does. I validation is something that you decide can fall off the cart, check out TinyXml++.
  8. The contents are contained in the 'table' member. However since the table is actually an array with the hash of the object used as the index in the array, it will may seem pretty sparsely populated, there will be alot of gaps between cells that actually have values. Personally, I always override toString() and print all my members' values nicely in there. The debugger displays the return value of toString() in the lower pane, if you don't override it, it falls back to Object.toString() which just prints the Object's class (if my memory is correct) plus the address the object is stored at, which is (usually) not very helpful. Edit: While I'm thinking of it, you should also always override .equals() and .hashCode(), especially if you're putting those objects into a Set.
  9. Is it wrong that I look down on Joe Blow?

    [quote name='SteveDeFacto' timestamp='1329754054' post='4914833'] These people don't even know what computer programming is and their inability to grasp simple concepts like if statements is mind baffling to me. [/quote] I would consider that your weakness, not theirs.
  10. How knackered is your code paste

    I had a hell of a time with it with a post the other day, if I put the lang="cpp" part in the source tag, it would chew it all up. Trying to edit the post to fix it just seemed to make it even worse. Finally I discovered that without lang="cpp" it at least put it in a code box with line numbers. I tried with both Chrome and Firefox, and had varying degrees of problems with each. Given that posting code is pretty common on this site, I hope they get it fixed ASAP.
  11. Boost.Python loading from script

    I have solved the problem, if you look at the error I posted, the line where I try to call [color=#282828][size=3][left]Core.Object.__init__self(id) should read [/left][/size][/color][color=#282828][size=3][left]Core.Object.__init__(self,id)[/left][/size][/color] [color=#282828][size=3][left]With that, I'm moving on for now, but still wondering if my approach here is valid, or if there is a better way. I'm thinking a possible strategy for controlling entities would be to have base classes defined in C++, for example a Controller class that receives events from an event system, and provides virtual methods for handling those events. I could then have classes defined in Python scripts that would inherit from this Controller class, and implement logic for different controllers in the Python scripts. It may also be possible to change a Controller's behavior at runtime by associating a different Python script with it to change it's behavior, or change an entity's controller altogether.[/left][/size][/color] [color=#282828][size=3][left]I'm still in the investigation stages of incorporating scripting, so some of that may be way off, but I do know it gets old incrementing a value by 10, recompiling and relaunching my program only to see it not have any effect, then rinsing and repeating a hundred times, so a scripting console is definitely a feature I'm after here as well.[/left][/size][/color]
  12. I'm investigating using Boost.Python for scripting in a game. After reading about all the documentation I can find on embedding Python using Boost.Python, I think a good strategy to pursue would to be have base classes defined in C++, and be able to create derived classes in Python scripts, and then call the base class methods on objects from my game, which would defer to the virtual methods defined in a Python script to execute some logic. Given the following code, the next step I would like to try to take would be to have the exec call be replaced with the exec_file call, but apparently there is alot I don't understand yet. [source]#include "stdafx.h" namespace py = boost::python; class Object { public: Object(int id) : id(id) { } virtual ~Object() { } int getId() const { return id; } virtual int f() { std::cout << "Object" << std::endl; return 0; } private: int id; }; struct Derived: Object { Derived(int i) : Object(i) { } virtual int f(void) { std::cout << "Derived\n"; return 0; } }; struct ObjectWrap: public Object, public py::wrapper<object> { ObjectWrap(int i) : Object(i) { } int f() { if (py::override f = this->get_override("f")) { return f(); } return Object::f(); } int default_f() { return this->Object::f(); } }; BOOST_PYTHON_MODULE(Core) { py::class_<object, boost::shared_ptr<object="">, boost::noncopyable>("__Object", "I'm an implementation detail, Pretend I don't exist", py::no_init) .add_property("id", &Object::getId) .def("f", &Object::f); py::class_<objectwrap, boost::shared_ptr<objectwrap="">, boost::noncopyable>("Object", py::init<int>()) .add_property("id", &Object::getId) .def("f", &Object::f, &ObjectWrap::default_f); } int _tmain(int argc, _TCHAR* argv[]) { Py_Initialize(); try { initCore(); py::object main_module = py::import("__main__"); py::object main_namespace = main_module.attr("__dict__"); py::object ignored3 = py::exec_file("CustomObject.py", main_namespace, main_namespace); py::object ignored = py::exec("import Core\n" "class CustomObject(Core.Object):\n" " def __init__(self,id):\n" " Core.Object.__init__(self,id)\n" " def f(self):\n" " print \"CustomObject\"\n" " return 0\n" "object = CustomObject(1337)\n", main_namespace, main_namespace); py::object object = main_namespace["object"]; object.attr("f")(); boost::shared_ptr<object> o = py::extract<boost::shared_ptr<object>>( object); o->f(); boost::shared_ptr<object> o2(new Derived(1337)); main_namespace["object"] = o2; py::object ignored2 = py::exec("object.f()\n", main_namespace, main_namespace); } catch (const py::error_already_set&) { PyErr_Print(); } Py_Finalize(); system("pause"); return 0; }[/source] When I uncomment the line with the exec_file call, and comment out the line with the exec call, I get the following error: [pre]Traceback (most recent call last): File "CustomObject.py", line 10, in <module> object = CustomObject(1337) File "CustomObject.py", line 5, in __init__ Core.Object.__init__self(id) AttributeError: type object 'Object' has no attribute '_CustomObject__init__self'[/pre] I am guessing this is happening because my base class, Object is not able to be imported into the main namespace, being that it is defined on the C++ side? Or not, I really have no clue and am just stabbing in the dark here. The code, as posted, works just fine, but isn't all that useful to me since it's executing a Python string defined in C++. I could read the .py files into a string, and use the exec call to execute them that way, but the exec_file seems much more elegant. Unfortunately, all the examples end at this point, and leave incorporating reading actual Python scripts as an exercise for the reader. Can anyone point me in the right direction, and at least verify that my approach is valid? Edit: There is definitely something wrong with the source tags, putting lang="cpp" in there caused it to seem to choke on the double less than symbol. At least all of the code is there now. If a mod wants to fix it or enlighten me on the subtleties of the new forum software, I'd appreciate it.
  13. You know you've been on the computer too long, when...

    You see the facebook icon in real life on like a bag of chips and get really angry that you can't adblock it.
  14. Recommend me a <$500 monitor

    Having used both a 24" widescreen, and 2 19" (regular?) screens, my personal preference is for the pair. I've been considering these for a while now: [url="http://www.newegg.com/Product/Product.aspx?Item=N82E16824260016"]http://www.newegg.com/Product/Product.aspx?Item=N82E16824260016[/url] A pair will run you $372 + shipping. Also, am I not looking in the right place, or do they just not make standard aspect ratio monitors with glossy screens, >1280x1024 resolution, and USB ports?
  15. Best Fast Food

    [quote name='NoisyApe' timestamp='1328831275' post='4911485'] Chipotle. [size=6][font=verdana,geneva,sans-serif][i][b]CHIPOTLE!!!![/b][/i][/font][/size] [/quote] Qdoba! It's like Chipotle but with queso. And burritos that could clog a wood chipper.
  • Advertisement