Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Bumrang

Pages: [1]
1
Graphics / Re: Sprite not displaying when used in a class
« on: November 24, 2012, 09:01:27 am »
Quote
Though that doesn't explain why my OpenGL version doesn't draw, but since that is not SFML related I'd rather not discuss that here.

Try adding the push/popGLstates. It's a need to have those when you use both SFML and OpenGL. However I saw nothing drawn with OpenGL in the sources.

void Ball::Draw()
{

        glUseProgram (shader);
                glUniformMatrix4fv(MVPid, 1, GL_FALSE, &Camera.GetMVP()[0][0]); // Send MVP to shader

                glActiveTexture (GL_TEXTURE0); // bind the ball texture
                glBindTexture (GL_TEXTURE_2D, ballTex);
                glUniform1i (sampler , 0);
                        glEnableVertexAttribArray (coord); // sending the vertex data
                                glBindBuffer(GL_ARRAY_BUFFER, vertBuf);
                                        glVertexAttribPointer(
                                                coord, // The attribute we want to configure
                                                2,                  // size
                                                GL_FLOAT,           // type
                                                GL_FALSE,           // normalized?
                                                0,                  // stride
                                                (void*)0            // array buffer offset
                                                );

                        glEnableVertexAttribArray (uv);
                                glBindBuffer (GL_ARRAY_BUFFER , uvBuf);
                                        glVertexAttribPointer (uv, 2, GL_FLOAT, GL_FALSE, 0, (void*)0);

                // Draw the triangle !
                                glDrawArrays(GL_TRIANGLES, 0, ballVert.size());

                        glDisableVertexAttribArray(coord);
                        glDisableVertexAttribArray(uv);
}

?

2
Graphics / Re: Sprite not displaying when used in a class
« on: November 23, 2012, 08:29:18 am »
Wow, I'm completely shocked. How the hell did I miss that?

I'm completely ashamed of myself  :-[

Though that doesn't explain why my OpenGL version doesn't draw, but since that is not SFML related I'd rather not discuss that here.

Thank you!  ;D

(also I know what scope is, I'm not a complete beginner :D)

3
Graphics / Sprite not displaying when used in a class
« on: November 23, 2012, 06:07:02 am »
Hello!

I'm making a small pong-breakout crossover in pure OpenGL and in SFML, and I've hit a problem in both that has stopped my development for roughly a month already.

I first prototyped my ball entirely in main, so I had all of my updating and drawing in main. Everything worked perfectly so I created a Ball class and just copy pasted all of it with a few minor adjustments (I also did this for my OpenGL version of my game).

Suddenly, the ball wouldn't display. I added a sf::RectangleShape into my Ball class, and that did display, so I have narrowed it down to the texture not displaying. The same exact thing happened in my OpenGL program, and the StackOverflow thread has all of the information about that, if that would help.

Tthe source can be found here.

This is what it currently looks like:


note: that white square is the rectangle, not the ball

-warning, pagestretch-
Source:

Main.cpp
#include "Includes.hpp"

unsigned int Width = 800;
unsigned int Height = 600;

int main()
{    
         sf::RenderWindow Window (sf::VideoMode (Width, Height), "PongOut");
     
     sf::Font font;
     if (!font.loadFromFile("font.ttf"))
         return EXIT_FAILURE;
     sf::Text text("test", font, 12);
     text.setPosition (0 , Height - 15);
     
     Ball ball (&Window , Width, Height);
     
     
     sf::Clock clock;
     
     while (Window.isOpen())
     {
                 sf::Time DT = clock.restart();
                 float DeltaTime = DT.asSeconds();

                  // Process events
         sf::Event event;
         while (Window.pollEvent(event))
         {
             // Close window : exit
             if (sf::Keyboard::isKeyPressed (sf::Keyboard::Escape))
                 Window.close();
         }
         
         ball.Update(DeltaTime);
 
         // Clear screen
         Window.clear();
         
         Window.draw(text);
         
         ball.Draw();
         
         //display
         Window.display();
         }

         return EXIT_SUCCESS;
}
 

Ball.hpp:
#ifndef BALL
#define BALL

class Ball
{
        private:
        int x, y, vx, vy;
        sf::Texture texture;
        sf::Sprite sprite;

        sf::RectangleShape rect;

        sf::RenderWindow* Window_;

        unsigned int Width, Height;

        public:
        Ball(sf::RenderWindow* , unsigned int width, unsigned int height);
        void Update(float DeltaTime);
        void Draw();
};

#endif
 

Ball.cpp:
#include "Includes.hpp"

Ball::Ball(sf::RenderWindow* win , unsigned int width, unsigned int height)
{
        Window_ = win;

        Width = width; Height = height;

     if (!texture.loadFromFile("img/ball.png"))
         std::cout << "\nCould not load the ball texture.";
     sprite.setTexture (texture);
     
     float x = Width / 2;
     float y = Height / 2;
     
     int vx = 200;
     int vy = 200;
     
     rect.setSize (sf::Vector2f (50 , 50));
     rect.setPosition (0 , 0);
}

void Ball::Update(float DeltaTime)
{
                 sprite.setPosition (x , y);
}

void Ball::Draw()
{
             // Draw the sprite
         Window_->draw(sprite);
         Window_->draw(rect);
}
 

If this is too much of a page stretch just say so and I will link it instead  :)

Some general information:
  • Arch Linux 64-bit
  • I am using SFML 2 release candidate, straight from the Arch AUR.

Thank you for reading!

Pages: [1]
anything