• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.

Mariusz Pilipczuk

  • Content count

  • Joined

  • Last visited

Community Reputation

174 Neutral

About Mariusz Pilipczuk

  • Rank
  1. OpenGL

    I think so too, but that shouldn't stop the model from being rendered.
  2. OpenGL

    I have changed it now and it still does not work. I'm sure the matrices are correct because it worked before.
  3. Hello, I was trying to solve this problem for the past 2 days and I really don't understand what's going on.   I have a Model class, which loads a list of vertices including their positions, texture coordinates, and normals (the normals are not used yet). The constructor for the class is as follows: Model::Model(const Model::Vertex *vertices, const int count) : vertexCount(count) { if (count == 0) { ApocFail("Empty model specified!"); }; if ((count % 3) != 0) { ApocFail("The specified model is not triangulated!"); }; GLint attrVertex, attrTexCoords, attrNormal; apocRenderHandler->getAttrLocations(attrVertex, attrTexCoords, attrNormal); glGenBuffers(1, &vbo); glBindBuffer(GL_ARRAY_BUFFER, vbo); glBufferData(GL_ARRAY_BUFFER, sizeof(Model::Vertex)*count, vertices, GL_DYNAMIC_DRAW); glGenVertexArrays(1, &vao); glBindVertexArray(vao); glEnableVertexAttribArray(attrVertex); glEnableVertexAttribArray(attrTexCoords); //glEnableVertexAttribArray(attrNormal); glVertexAttribPointer(attrVertex, 4, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*) offsetof(Model::Vertex, pos)); glVertexAttribPointer(attrTexCoords, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*) offsetof(Model::Vertex, texCoords)); //glVertexAttribPointer(attrNormal, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*) offsetof(Model::Vertex, normal)); glBindBuffer(GL_ARRAY_BUFFER, 0); glBindVertexArray(0); cout << "GL error: " << glGetError() << endl; }; It also has a draw() function, which looks like this: void Model::draw() { glBindBuffer(GL_ARRAY_BUFFER, vbo); glBindVertexArray(vao); glDrawArrays(GL_TRIANGLES, 0, vertexCount); glBindBuffer(GL_ARRAY_BUFFER, 0); glBindVertexArray(0); }; When the class is constructed, "GL error" is GL_NO_ERROR, but if i uncomment the line that loads normals, it is GL_INVALID_VALUE (I don't know if that should happen). Drawing also generates no error. However, the model (which is of a cube), does not appear on the screen. It has worked before, but stopped after I tried implementing an entity system, and I'm not sure why.   draw() is called between a glClear(), a texture binding, and a glFlush() (followed by swap windows). The context is created with SDL and GLEW.   The vertex shader: #version 150 uniform mat4 uModelMatrix; uniform mat4 uViewMatrix; uniform mat4 uProjectionMatrix; in vec4 inVertex; in vec2 inTexCoords; in vec3 inNormal; out vec2 passTexCoords; out vec3 passNormal; void main() { passTexCoords = inTexCoords; passNormal = inNormal; gl_Position = uProjectionMatrix * uViewMatrix * uModelMatrix * inVertex; }; The fragment shader: #version 150 uniform sampler2D uSampler; in vec2 passTexCoords; in vec3 passNormal; out vec4 outColor; void main() { outColor = texture(uSampler, passTexCoords); //outColor = vec4(1.0, 0.0, 0.0, 1.0); }; I am completely confused. All help appreciated :)
  4. OpenGL

    Thank you, that answers everything   EDIT: Do I have to bind both the VBO and VAO before calling glDrawArray()? Or do I just need to bind the VAO?
  5. OpenGL

    Thanks for the replies. I don't fully understand this though. If I create a VAO, and set up the vertex attributes with glVertexAttribPointer(), it tkaes the data from the currently-bound VBO, right? And before I call glDrawArrays(), do I have to bind into the VAO, or the VBO as well? And if I update the VBO, using glBufferData() or OpenCL, do those changes automatically affect the VAO, or do I have to create the VAO again?
  6. I have done a lot of programming in OpenGL before, but somehow I am now unable to draw a triangle...   Here's the code (this is a one-file program). I have no idea which part of the code is failing so I'm posting all of it. All help appreaciated.   This code displays a blank, black window. #include <MaddCompute.h> #include <SDL2/SDL.h> #include <iostream> #include <GL/glew.h> #include <string> #include <fstream> #include <stdlib.h> using namespace std; struct Vertex { float pos[2]; float color[3]; }; Vertex vertices[3] = { {{0.0, -1.0}, {1.0, 0.0, 0.0}}, {{-1.0, 1.0}, {0.0, 1.0, 0.0}}, {{1.0, 1.0}, {0.0, 0.0, 1.0}} }; GLuint CompileShader(GLuint type, string filename) { string code = ""; ifstream ifs(filename.c_str()); string line; while (getline(ifs, line)) { code += line + '\n'; }; ifs.close(); //cout << code << endl; //exit(1); GLuint shader = glCreateShader(type); char *str = (char*) code.c_str(); glShaderSource(shader, 1, (const GLchar**)&str, NULL); glCompileShader(shader); #if 0 int len, ignore; glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &len); char *buffer = new char[len+1]; glGetShaderInfoLog(shader, len, &ignore, buffer); string log = buffer; delete buffer; ofstream ofs((filename + ".log").c_str()); ofs << log << endl; ofs.close(); #endif return shader; }; int main() { if (SDL_Init(SDL_INIT_VIDEO) < 0) { cerr << "SDL_Init: " << SDL_GetError() << endl; return 1; }; SDL_Window *win = SDL_CreateWindow("MaddCompute OpenGL Shared Context", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 640, 480, SDL_WINDOW_OPENGL); if (win == NULL) { cerr << "SDL_CreateWindow: " << SDL_GetError() << endl; return 1; }; SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3); SDL_GLContext glcontext = SDL_GL_CreateContext(win); if (glcontext == NULL) { cerr << "SDL_GL_CreateContext: " << SDL_GetError() << endl; return 1; }; if (glewInit() != GLEW_OK) { cerr << "glewInit fail" << endl; return 1; }; if (!glewIsSupported("GL_VERSION_3_0")) { cerr << "OpenGL 3.0 not supported!" << endl; return 1; }; while (glGetError() != GL_NO_ERROR); GLuint vshader = CompileShader(GL_VERTEX_SHADER, "vertex.glsl"); GLuint fshader = CompileShader(GL_FRAGMENT_SHADER, "fragment.glsl"); GLuint prog = glCreateProgram(); glAttachShader(prog, vshader); glAttachShader(prog, fshader); glLinkProgram(prog); #if 0 int len, ignore; glGetProgramiv(prog, GL_INFO_LOG_LENGTH, &len); char *buffer = new char[len+1]; glGetProgramInfoLog(prog, len, &ignore, buffer); string log = buffer; delete buffer; ofstream ofs("link.log"); ofs << log << endl; ofs.close(); #endif glUseProgram(prog); if (glGetError() != GL_NO_ERROR) { cerr << "Something went wrong in shader compilation." << endl; return 1; }; GLint attrPos = glGetAttribLocation(prog, "pos"); if (attrPos == -1) { cerr << "couldn't find 'pos' !" << endl; return 1; }; GLint attrColor = glGetAttribLocation(prog, "color"); if (attrColor == -1) { cerr << "couldn't find 'color' !" << endl; return 1; }; GLuint vbo; glEnableVertexAttribArray(attrPos); glEnableVertexAttribArray(attrColor); glGenBuffers(1, &vbo); glBindBuffer(GL_ARRAY_BUFFER, vbo); glBufferData(GL_ARRAY_BUFFER, 3*sizeof(Vertex), vertices, GL_STATIC_DRAW); glVertexAttribPointer(attrPos, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*) 0); glVertexAttribPointer(attrColor, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*) offsetof(Vertex, color)); MC::Context *context = NULL; try { context = new MC::Context(MC::Context::OPENGL); } catch (MC::Error e) { cerr << "MC::Error: " << e.what() << endl; return 1; }; bool quit = false; unsigned long time = SDL_GetTicks(); while (!quit) { SDL_Event ev; while (SDL_PollEvent(&ev)) { if (ev.type == SDL_QUIT) { quit = true; }; }; if ((SDL_GetTicks()-time) >= 33) { time = SDL_GetTicks(); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glDrawArrays(GL_TRIANGLES, 0, 3); SDL_GL_SwapWindow(win); }; }; delete context; SDL_GL_DeleteContext(glcontext); SDL_DestroyWindow(win); SDL_Quit(); return 0; };
  7. I'm sorry, I tried upvoting your post and accidentally clicked the wrong thing and now i don't know how to reverse it -.- Unfortunately, votes are final immediately. I would definitely like to see some grace period though so silly mistakes like that can be corrected. I'll bump him up a step so the post doesn't show a -1 at least.   You use custom out variables in the fragment shader, just like the inputs to the vertex shader are custom in variables. The variable on location 0 goes to the primary render target, the variable on location 1 goes to the second render target, and so on. If you're not working with multiple render targets, then just define an out variable in the fragment shader and write to it.   Aaah, thanks, that makes sense. Thank you to everyone who helped :)
  8. Thanks. That solved the problem.   I'm sorry, I tried upvoting your post and accidentally clicked the wrong thing and now i don't know how to reverse it -.-   If gl_FragColor is deprecated, then how do I tell the GPU what color the pixel should be??
  9. I know about the coordinates. I just wanted to see if I'm sending more than one attribute properly.   I changed the last argument of glDrawArrays() to 3, but it still draws nothing :(
  10. Thank you for helping guys. I attempted to use VBOs, but something doesn't work. I was attempting to (for now) draw a red triangle in orthographic mode on the screen. Here's the buffer creating code: int xValues[3] = {100, 40, 140}; int yValues[3] = {50, 70, 70}; GLuint vao; glGenVertexArrays(1, &vao); glBindVertexArray(vao); GLuint vbo[2]; glGenBuffers(2, vbo); glBindBuffer(GL_ARRAY_BUFFER, vbo[0]); glBufferData(GL_ARRAY_BUFFER, 3 * sizeof(int), xValues, GL_STATIC_DRAW); glVertexAttribPointer((GLuint)0, 1, GL_INT, GL_FALSE, 0, 0); glBindBuffer(GL_ARRAY_BUFFER, vbo[1]); glBufferData(GL_ARRAY_BUFFER, 3 * sizeof(int), yValues, GL_STATIC_DRAW); glVertexAttribPointer((GLuint)1, 1, GL_INT, GL_FALSE, 0, 0); glEnableVertexAttribArray(0); glEnableVertexAttribArray(1); glBindVertexArray(0); Then I draw as follows: glBindVertexArray(vao); glDrawArrays(GL_TRIANGLES, 0, 1); glBindVertexArray(0); My vertex shader: // gui.vert // The GUI vertex shader. // This software, including the source code, is release under the terms of // the License. #version 150 // vertex input in int in_x; in int in_y; void main() { float x = (float(in_x) / 320) - 1; float y = (float(in_y) / 240) - 1; gl_Position = vec4(x, y, 0.0, 1.0); }; My fragment shader: // gui.frag // The GUI fragment shader. // This software, including the source code, is release under the terms of // the License. #version 150 void main() { gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0); }; But the only thing I get is a black screen. Does anyone know what I'm doing wrong here?
  11. Thank you, but I cannot seem to find any tutorial which shows how to use VBOs (yes, I'm trying to completely migrate to the new API). I did see somewhere on this forum that a person made a struct for holding each vertex and I believe this struct was treated as the only attribute. If I want to use this approach, can someone please post some example code for how I would create a VBO with this data and then draw? Thank you.
  12. Hello.   In my old game, I used GLSL 1.2 in my shaders, and I could still call glColor*(), glTexCoord*(), etc. to pass info about vertices, and my vertex shader was still able to read it.   Now I'm trying to use GLSL 1.5, and I know that I cannot use glColor*() etc to pass such information any more, but it doesn't matter since I can use vertex attributes. However, gl_Vertex was also removed. This means that calling glVertex*() does not make sense anymore, so how do I send the vertices to the GPU?   Do I have to use VBOs? If so, is there any good tutorial with a nice example on how to do this?   Thank you.
  13. You can use the WinAPI if you want your engine to work only on Windows. If you want to port it to other platforms, you will have to use some cross-platform libraries, such as SDL.   Really there is no standard way to design a game engine. It all depends on your needs. If you want a place to start, you could check out other game engines.
  14. Thank you SiCrane, I changed python26.dll to 32-bit and it is now working. :)