• Advertisement


  • Content count

  • Joined

  • Last visited

Community Reputation

122 Neutral

About Esentiel

  • Rank

Personal Information

  • Interests
  1. OpenGL Loading texture from dds file

    The problem was I created in a separate file another buffer and vertex array object. Here in texture I haven't created such object. So I need to move this code to the place where vertex array object is bound.
  2. OpenGL Loading texture from dds file

    Ok, I got an idea. It seems something wrong with uv coordinates. Because, when I changed one row in vertex shader to UV = vertexPosition_modelspace.xy; I got ugly stretched texture on my triangle. Maybe I filled buffer in a wrong way.
  3. Hello everyone! I'm trying to complete OpenGL tutorial http://www.opengl-tutorial.org/beginners-tutorials/tutorial-5-a-textured-cube/ And I faced a problem when loading texture from dds file to my triangle. Here is my code (basically from the tutorial): Load DDS from file(Texture.cpp): https://pastebin.com/Y5TKPvue Vertex shader: https://pastebin.com/2pPXQkS9 Fragment shader: https://pastebin.com/4nF2jVMy dds file: https://drive.google.com/open?id=1yYF2oyLbqn-OMB_QxZKyzKwBwxl_9sCb rendered window: https://imgur.com/a/1pP92 In main file I call drawing triangle, I call texture.Bind(); Also I tried to manually set uv points in fragment shader, and it seems working(color might be changed based on coordinates). If you have any idea, will be really appreciated. Regards, Esentiel
  4. hi guys!   thank you for your assistance. Well, I thought about side-to-side movements in Tetris game for a while. And I guess it will be better to have 1 click = 1 movement(1 cell). But I'm so excited about vectors! I read a bit about it and I'm going to use vectors in my next 2D game - "The Legend of Kage"(give it a try if you have missed it in a childhood :) ). As far as I understand, working with vectors is a basic knowledge/skill you should posses. It is used even in 3D games! So I decided to practice with it in a more difficult game.   Thanks, Artem
  5. Well, guys, I suspect, it's all about vectors. Going to read this stuff after work.
  6. Hello!   First of all, sorry for my bad English, it's not my native language, nevertheless I'm trying to master it.   Currently I'm trying to code simple Tetris game. I implemented Time to make shapes falling smooth and cute. But what about movements of these shapes? I mean the idea of Time is: S = t * v, where t - time, v - speed, S - distance to travel. So by calculating time and defining some constant speed we are getting smooth movement of an object. That's cool. But what if I know the distance? I mean I have a grid with exact positions where a shape can be placed. so when I hit Right button I do expect a shape will be moved to 32 pixels(it's size of cell in my grid). How can I use time here to control movement speed?    Movements 1: I used to have Keyboard::IsKeyPressed() into my Events catching code. It means when I hit Right button I will have to wait for a bit before a shape going to start moving. Nevertheless movement speed was almost OK for me. but this time before shape starts moving is so annoying...   Movements 2: So I decided to move Keyboard::IsKeyPressed() outside of events catching code(according to post from sfml forum). And it's works perfectly fine: now there is no spoontimeout. But I faced another issue: now shape is moving with the lightning speed!   Well, I took a break and start thinking, and I found a solution: I have to have another speed value for moving shape from side to side! Thus I'm confused with the question: how can I move a shape to exact distance with a desired animation speed using Time.   Will be glad to have any help, guys! Can read, but can't find what to read to solve my problem.   thank you in advance, Artem   pS: How do I calculate time: Time elapsed1 = clock.restart(); float time = elapsed1.asSeconds(); How do I move a shape: if (Keyboard::isKeyPressed(Keyboard::Right))  {  if (myVeryShape.x4 != 417 - 32 && !onGround)  {   myVeryShape.x1 += 32;   myVeryShape.x2 += 32;   myVeryShape.x3 += 32;   myVeryShape.x4 += 32;  } } How is shape falling: void fallMyShape(float dist) { if (!onGround) { myVeryShape.y1 += dist; myVeryShape.y2 += dist; myVeryShape.y3 += dist; myVeryShape.y4 += dist; } } TheShape.fallMyShape(speed * time); ? ? ? ? ? ? ? ? ? ? ?
  7.   Yes I included sfml-main.lib. It works great when you have no "entry point" set in projects settings. I tested it: with entry point = main - the program stays working in background; with empty entry point - the program is closed like it should be. Don't know the root cause of such behavior but it is the reason of my issue.   PS: that break; was created in a desperation of mine :) I tried everything I could find in google. and it was one of that things. After your explanation I got it.   Thanks.
  8. Thank you for your advice related to pointers in rendering I decided to get rid of them in my code. Also I purge int const(width, height) to be sure it's not related to the problem. here is my current code: [spoiler] #include <SFML/Graphics.hpp> using namespace sf; class Ball { public: float dx, dy; FloatRect rect; Sprite sprite; Ball(Texture &image) { dx = -10; dy = -10; sprite.setTexture(image); rect = FloatRect(800, (rand() % 500) * 10, 10, 10); } void update() { rect.top += dy; rect.left += dx; sprite.setPosition(rect.left, rect.top); } }; class Player { public: float dy; FloatRect rect; Sprite sprite; bool isMoveUp; bool isMoveDown; Player(Texture &image) { sprite.setTexture(image); rect = FloatRect(0, 600 / 2, 32, 128); dy = 10; isMoveUp = false; isMoveDown = false; } void update() { sprite.setPosition(rect.left, rect.top); } void movePlayer(char direction) { if (direction == 'U') { if (rect.top>0) rect.top -= dy; } else if (direction == 'D') { if (rect.top + rect.height < 600) rect.top += dy; } } }; int main() { Texture playerTexture; if (!playerTexture.loadFromFile("player.png")) { return 1; } Texture ballTexture; if (!ballTexture.loadFromFile("ball.png")) { return 1; } Player player(playerTexture); Ball ball(ballTexture); RenderWindow window(VideoMode(800, 600), "The Pong game"); window.setFramerateLimit(60); while (window.isOpen()) { Event event; while (window.pollEvent(event)) { if (event.type == Event::Closed) { window.close(); { break; } } if (event.type == Event::KeyPressed) { if (event.key.code == Keyboard::Down) { player.isMoveDown = true; player.isMoveUp = false; } if (event.key.code == Keyboard::Up) { player.isMoveUp = true; player.isMoveDown = false; } } if (event.type == Event::KeyReleased) { if (event.key.code == Keyboard::Down) player.isMoveDown = false; if (event.key.code == Keyboard::Up) player.isMoveUp = false; } } if (player.isMoveDown) { player.dy = 10; player.movePlayer('D'); } if (player.isMoveUp) { player.dy = 10; player.movePlayer('U'); } if (ball.rect.intersects(player.rect)) { ball.dx = 10; } if (ball.rect.left >= 800) { ball.dx = -10; } if (ball.rect.top >= 600) { ball.dy = -10; } if (ball.rect.top <= 0) { ball.dy = 10; } window.clear(Color::Black); ball.update(); player.update(); window.draw(player.sprite); window.draw(ball.sprite); window.display(); } return 0; } [/spoiler]     I double-checked libs and it seems there is no issue with that: debug libs for debug and common libs for release. Also I checked warning during building the program. 1. is related to row: rect = FloatRect(800, (rand() % 500) * 10, 10, 10); //conversation from int to float 2. LNK4210: .CRT section exists; there may be unhandled static initializers or terminators E:\Documents\Visual Studio 2013\Projects\2D Games\ThePong\main.obj ThePong 3. LNK4210: .CRT section exists; there may be unhandled static initializers or terminators E:\Documents\Visual Studio 2013\Projects\2D Games\ThePong\MSVCRT.lib(atonexit.obj) ThePong   First one isn't seem to be a big deal. 2nd and 3rd I googled and it was related to [Config -> Linker -> Advanced -> Entry Point]. I set "main" there for a some reason. And after  I blank this field the problem wasn't reproduced. As you mentioned in the first post: the root-cause was in the debug information   Thank you for help and useful advices!   PS: that's why I hate VS. it's like a space ship: can be powerful if you are familiar with it, or can ruin your day with a wrong property set.  
  9. Hi,   Thanks for the answer. By "process remains running" I mean I can see Pong.exe in the windows task manager while the only window is closed. I waited for awhile but it won't despair.
  10. Hello gentlemen   I'm faced with an annoying issue which drives so mad, that came here to ask an advice. First of all, English is not my native language, so apologize if I messed up Here is my code of a simple Pong game: [spoiler] #include <SFML/Graphics.hpp> using namespace sf; int const w = 800; int const h = 600; class Ball { public:  float dx, dy;  FloatRect rect;  Sprite sprite;  Ball(Texture &image)  {   dx, dy = -10;   sprite.setTexture(image);   rect = FloatRect(w, (rand() % 500) * 10, 10, 10);  }  void update()  {   rect.top += dy;   rect.left += dx;   sprite.setPosition(rect.left, rect.top);  } }; class Player { public:  float dy;  FloatRect rect;  Sprite sprite;  bool isMoveUp;  bool isMoveDown;  Player(Texture &image)  {   sprite.setTexture(image);   rect = FloatRect(0, h / 2, 32, 128);   dy = 10;   isMoveUp = false;   isMoveDown = false;  }  void update()  {   sprite.setPosition(rect.left, rect.top);  }  void movePlayer(char direction)  {   if (direction == 'U')   {    if (rect.top>0)     rect.top -= dy;   }   else if (direction == 'D')   {    if (rect.top + rect.height < h)     rect.top += dy;   }  } }; int main() {  Texture playerTexture;  if (!playerTexture.loadFromFile("player.png"))  {   return 1;  }  Texture ballTexture;  if (!ballTexture.loadFromFile("ball.png"))  {   return 1;  }  Player * player = new Player(playerTexture);  Ball * ball = new Ball(ballTexture);  RenderWindow window(VideoMode(w, h), "The Pong game");  window.setFramerateLimit(60);  while (window.isOpen())  {   Event event;   while (window.pollEvent(event))   {    if (event.type == Event::Closed)    {     window.close();     {      delete[] ball, player;      break;     }    }    if (event.type == Event::KeyPressed)    {     if (event.key.code == Keyboard::Down)     {      player->isMoveDown = true;      player->isMoveUp = false;     }     if (event.key.code == Keyboard::Up)     {      player->isMoveUp = true;      player->isMoveDown = false;     }    }    if (event.type == Event::KeyReleased)    {     if (event.key.code == Keyboard::Down)      player->isMoveDown = false;     if (event.key.code == Keyboard::Up)      player->isMoveUp = false;    }   }   if (player->isMoveDown)   {    player->dy = 10;    player->movePlayer('D');   }   if (player->isMoveUp)   {    player->dy = 10;    player->movePlayer('U');   }   if (ball->rect.intersects(player->rect))   {    ball->dx = 10;   }   if (ball->rect.left >= w)   {    ball->dx = -10;   }   if (ball->rect.top >= h)   {    ball->dy = -10;   }   if (ball->rect.top <= 0)   {    ball->dy = 10;   }     window.clear(Color::Black);   ball->update();   player->update();   window.draw(player->sprite);   window.draw(ball->sprite);   window.display();  }  return 0; }   [/spoiler]   Issues: 1. Before I created both player and ball in heap and delete[] them after window closed, program process remains running in system. I'm not sure why do I have to have these objects in heap instead of stack.. and why the program behaves like that?  2. I'm trying to test the program in case images(textures) were not found. And you'll not believe me, the program remains running every single time I launch it. Why return 1; hasn't killed the process?..   I'm a newbie to c++ and especially to c++ windows programming in visual studio[burn in hell VS!!! jk]. Spent much time googling, but it seems I can't even manage to perform a proper request.   PS: if it's possible, I would be very appreciate if you guys will be able to review my code and point me to weak parts.   Thank you in advance!
  • Advertisement