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.


Topics - sludge

Pages: [1]
1
Window / mouse input not always registering
« on: August 22, 2010, 02:09:18 am »
The title says everything.

In my gameloop, the following variable is checked for a left mouse clicked every iteration.

const sf::Input& input = editorWindow.GetInput();

I noticed that sometimes the mouse does not seem to respond as anticipated.  After adding a simple cout statement after

if(input.IsMouseButtonDown(sf::Mouse::Left))

I learned that the condition is not returning true after every time I press the left mouse button.  I know that the input class is used to gather real-time input.  Are some of the mouse clicks not being registered simply because of a lag in between calls to GetInput()?

I imagine that things will function as expected if I check for a mouse event instead?  Is this the case?

2
Graphics / partially transparent sprites
« on: August 20, 2010, 02:33:14 am »
I want to be able to display a sprite on the screen and have certain parts of that sprite be transparent.

Let me explain by example.  Suppose that I have a picture of a stick figure.  If I were to load this picture into sfml as an image, set it to sprite, define its subrect, and then display the resulting sprite, I would see a white box with a stick figure in it above my background.

I want the white areas of the sprite to be transparent so that only the stick-figure part of the subrect is rendered.  The background will then appear where the white parts were previously.

I'm sure there is a simple solution to this problem... Any ideas?

3
Graphics / glClear
« on: July 23, 2010, 07:18:58 pm »
Will glClear() act on all objects that have been drawn to the buffer using drawing functions native to SFML as well as those drawn using openGL functions? Or is it only the latter?

My guess is both because, at its core, SFML is an tool through which one can interact with OpenGL, among other interfaces.   I suppose if the latter is the case, then SFML and OpenGL functions draw to separate buffers before display.  How exactly do things work under the hood?

Also, if I call window::clear(), does this clear everything I have drawn with OpenGL as well?  I imagine the answer to this question is based on the answer to the first.

4
Graphics / Combining OpenGL and SFML graphics
« on: July 23, 2010, 05:20:53 pm »
I suppose that this question is more related to my lack of understanding of OpenGL than anything else, but I figured I'd ask away.  

So I have a program that draws some things using functions native SFML, and I am trying to draw a three dimensional shape in the same window using OpenGL.

I am able to get both APIs to render their images independently but not concurrently.

When I initialize and draw the graphics from OpenGL to the window, the entire screen appears back, and then a few lines that I defined are drawn in the lower-left corner (where I set the viewport).

My guess is that the entire OpenGL buffer is being rendered to the entire screen, as opposed to the few lines that I would like to draw, and in the process prints over the images drawn by SFML.  I suspect that I need to render the buffer to only a small section of the window instead.

Let me post a couple snip-its of code that include the rendering and initialization of OpenGL and the rendering of the SFML and OpenGL graphics.

Code: [Select]

bool Simulation::Initialize()
{
    // Allows us to render both SFML and OpenGL functions
    MainWindow.PreserveOpenGLStates(true);  

    glEnable(GL_DEPTH_TEST);
    glDepthMask(GL_TRUE);
    glClearDepth(1.f);

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(45.f, 1.f, 1.f, 500.f);

    glViewport(0, 0, MainWindow.GetWidth()/2, MainWindow.GetHeight()/2);

//more stuff
}

void Simulation::Render()
{
        // These functions draw to the MainWindow using SFML
DrawVariableLabelValues();
DrawTextNames();
DrawTextCursor();

// This is function draws using OpenGL functions
DrawGraph();

    // Render the graphics drawn onto the MainWindow
    MainWindow.Display();
}

//Below I try to simply draw the coordinate system on which I will display a dynamics plotting system
void Simulation::DrawGraph()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    glTranslatef(0.f, 0.f, -1.f);

    // Draw the axes of the graph
    glBegin(GL_LINES);

// x-axis
        glVertex3f(0.0f, 0.0f, 0.0f);
glVertex3f(200.0f, 0.0f, 0.0f);

// y-axis
glVertex3f(0.0f, 0.0f, 0.0f);
glVertex3f(0.0f, 200.0f, 0.0f);

// z-axis
glVertex3f(0.0f, 0.0f, 0.0f);
glVertex3f(0.0f, 0.0f, 200.0f);
    glEnd();
}




Another thing I would like to mention is that when I try to call glTranslate using x and y arguments other than 0, the lines that I want to draw disappear.  Can anyone give me a hand here.  I just starting using OpenGL for the first time today.

Lastly, do I need to call clear on the MainWindow anymore?  It seems that like that clears out everything that I have told OpenGL to draw.

Thank you

5
General / Linking OpenGL
« on: July 22, 2010, 10:06:13 pm »
While trying to integrate some of the initialization code from the OpenGL tutorial with my current program, VS 2010 told me

1>Main.obj : error LNK2019: unresolved external symbol _gluPerspective@32 referenced in function _main
1>C:\Users\Nick\Documents\Visual Studio 2010\Projects\Basebal sim\Debug\Basebal sim.exe : fatal error LNK1120: 1 unresolved externals

In another thread, Laurent suggested that sfml-main.lib was never linked.  At the moment, all of my libraries are linked statically.  I quickly discovered that sfml-main-s-d.lib does not exist.  I instead tried

sfml-system-s-d.lib
sfml-window-s-d.lib
sfml-graphics-s-d.lib
sfml-main-d.lib

After linking this library, the compiler still produces the same error.

6
General / Compiler warnings
« on: July 14, 2010, 06:41:47 pm »
The compiler is giving me a warning that I believe may be causing some issues at a specific point during execution.  I'm not quite sure what the compiler is telling me, however.  Whatever be the case, I'm nearly positive that SFML is causing the problem.  Note that the only library I am using besides those in the standard library is SFML/Graphics.hpp

Here is what the error says:
1>LINK : warning LNK4098: defaultlib 'LIBCMT' conflicts with use of other libs; use /NODEFAULTLIB:library

Note that I'm compiling using the debugger; however, the same error occurs when I compile a release version as well.

Another user suggested that I have a mismatch of runtimes.  I went to Google for help, but I find anything that specifically references what this means.

7
Graphics / A cursor for typing
« on: July 14, 2010, 06:19:21 pm »
In my program, there are several boxes that a user can click on.  When he clicks on these boxes, he should be able to input text, which will be stored and displayed on screen from within the confines of these boxes.

In just about every program that requires keyboard input, there is that blinking, black cursor to indicate where the next letter will be printed.  I need to create one of these.

I noticed the mention of a function in the tutorials that returns in the position of a letter inside a string; it further reads that this might be useful for cursor display.  Should i try to use this function to create my cursor, or is there a more appropriate strategy I should follow?

8
Graphics / Returning sf:String reference from member function
« on: July 12, 2010, 05:12:26 pm »
I have a class that returns an sf::String member variable as a reference like so:

Code: [Select]

sf::String& GetText()
{ return text; }


I call the function in the following way:

Code: [Select]

mass.GetText().SetText("mass");


The function properly returns the text variable, but I receive a runtime error when SetText() is called during variable assignment.

Unhandled exception at 0x002f4716 in Basebal sim.exe: 0xC0000005: Access violation writing location 0xcccccccc.

Clearly I'm trying to access an memory location that I'm not allowed to touch.

EDIT:: So I realized that the class really should be handling the manipulation of its own variables independently... I figure that I will just create a SetText function inside the class.  I am still curious, however, why this routine won't working properly.

EDIT 2: So I still recieve the same error when I try to perform a similar operation within a class member function:

Code: [Select]
void SetText(std::string word)
{ text.SetText(word); }

The documentation says that the SetText function takes the type (const Unicode::Text &Text).  I'm note exactly sure how to replicate this type.  I imagine that my problem stems from this specification.

9
Graphics / Rendering shapes
« on: July 12, 2010, 04:35:08 pm »
I suppose this is a very simple question.  I'm just trying to make a rectangle with a black outline.

The following line peculiarly produces nothing:
Code: [Select]

MainWindow.Draw(sf::Shape::Rectangle(600, sprite_ball.GetPosition().y, 770, sprite_ball.GetPosition().y + 80,
sf::Color::White, 20.f, sf::Color(0, 0, 0)));


EDIT:  Solved the problem.  I was printing the background after the shapes

10
Graphics / sprites aren't properly changing their member variables
« on: July 09, 2010, 03:44:21 pm »
I have several sprites that I am trying to print to the screen.  These sprites are members of the class VariableLabel and are all of the same image.  VariableLabel's initialize function sets each new sprite to this static image.

Several VariableLabel objects are private members of my simulation class.  When I try to modify the SubRect or apply move or do something else that alters the properties of the sprites, nothing happens.  They are drawn the same way, regardless of how I choose to alter the sprites.  In essence, each sprite is drawn simply on top of the one before it.

I was thinking there might be scoping issues, but the problem isn't apparent to me.

Here is a little code to help:
Code: [Select]


bool Simulation::Initialize()
{
// Load images from the data files
if (!img_background.LoadFromFile("Resources/Background.png") ||
!img_variableLabel.LoadFromFile("Resources/VariableLabel.png"))
return EXIT_FAILURE;

// Set images to sprites
sprite_background.SetImage(img_background);
sprite_trajectory.SetImage(img_variableLabel);

// Set sprite properties
sprite_trajectory.SetSubRect(sf::IntRect(13, 21, 164, 60));
sprite_trajectory.SetScaleX(1.5);
sprite_trajectory.SetPosition(500.f, 10.f);
sprite_trajectory.SetScale(1.f, 1.f);

posX.GetSprite().SetSubRect(sf::IntRect(13, 21, 164, 60));
posX.GetSprite().SetPosition(250.f, 250.f);
posX.GetSprite().SetScale(1.f, 1.f);

posY.GetSprite().SetSubRect(sf::IntRect(13, 21, 164, 60));
posY.GetSprite().SetPosition(350.f, 250.f);
posY.GetSprite().SetScale(1.f, 1.f);

posZ.GetSprite().SetSubRect(sf::IntRect(13, 21, 164, 60));
posZ.GetSprite().SetPosition(300.f, 250.f);
posZ.GetSprite().SetScale(1.f, 1.f);
return true;
}
 
void Simulation::Render()
{
    MainWindow.Clear();
MainWindow.Draw(sprite_background);
MainWindow.Draw(posX.GetSprite());
MainWindow.Draw(posY.GetSprite());
MainWindow.Draw(posZ.GetSprite());
MainWindow.Draw(sprite_trajectory);
    MainWindow.Display();
}
 
void Simulation::HandleEvents()
{
     const sf::Input& input = MainWindow.GetInput();
 
     if(event.Type == sf::Event::Closed )
          MainWindow.Close();
 
     if((event.Type == sf::Event::KeyPressed) && (event.Key.Code == sf::Key::Escape))
          MainWindow.Close();

// Move the sprite
if (input.IsKeyDown(sf::Key::Left))  posZ.GetSprite().Move(-100 * .1, 0);]
}

void Simulation::Run()
{
    while(MainWindow.IsOpened())
    {
        while(MainWindow.GetEvent(event))
        {
            HandleEvents();
        }
        Update();
        Render();
    }
}


Note that sprite_trajectory and sprite_background are working well
Thank you

-Nick

11
Graphics / Sprites and loading images
« on: July 06, 2010, 07:52:07 pm »
In my program, I have a single image that will be displayed multiple times.  In the tutorials, I read that a good way to handle such a situation is to make a static image that every sprite accesses.  I took the code from the tutorial, and now I'm trying to use it, but I'm getting a few issues.

first let me post the code:
Code: [Select]


////////////VariableLabel.h
#include "headers.h"

#pragma once
class VariableLabel
{
public:
VariableLabel();
static bool Initialize(const std::string& ImageFile);

private:
    static sf::Image image;      // Each sprite object shares this single image
    sf::Sprite Sprite;           // But there is one sprite per variable label
double value;
};

////////////VariableLabel.cpp
#include "VariableLabel.h"

VariableLabel::VariableLabel()
{
Sprite.SetImage(image); // Every sprite uses the same image
}

bool VariableLabel::Initialize(const std::string& ImageFile)
{
return image.LoadFromFile(ImageFile);
}



My questions concerns the implementation of the constructor.  If I declare an instance of VariableLabel before calling the static function "static bool Initialize(const std::string& ImageFile)", when I try to draw the sprite that the VariableLabel contains, nothing is drawn.  I assume that this is because image is not initialized when the constructor of VariableLabel is called, so the sprite is never assigned an image.  

If I modify my code a bit and create an instance of VariableLabel after calling the initialize function, things work properly.  Is there anyway to modify the class so that the constructor is still able properly assign images to the sprites before calling the initialize function.  I only ask because I would like the call the initialize function inside a function of a class that contains VariableClass objects as its members.

Thank you.

-Nick

12
Graphics / loading images
« on: July 06, 2010, 08:50:48 am »
Whenever I display a sprite that I read from a file, instead of only displaying the small part of the image file I care about (my drawing), the contents of the entire file, including the whitespace, are displayed.

In essence, when I load an image, how can I choose to only read part of the image file as opposed to the entire thing?  How do I specify the range of pixels are of importance?

13
General discussions / Application won't start
« on: July 04, 2010, 09:50:46 pm »
I am looking through the sfml tutorials right now, but I am having trouble because after compiling the program, it will not run properly.  Visual Studio 2010 tells me that "The application was unable to start correctly(0xc015002).  Note that I am running it through the debugger.

The last line in the debug prompt reads
"'Basebal sim.exe': Loaded 'C:\Users\Nick\Documents\Visual Studio 2010\Projects\Basebal sim\Basebal sim\sfml-window-d.dll', Cannot find or open the PDB file"

I already linked the following three libraries, and their appropriate .dll files are included in the application directory as well.
sfml-system-d.lib
sfml-window-d.lib
sfml-graphics-d.lib

I next tried to use the release version of the libraries instead (but still ran the program through the debugger), and the program started.  Unfortunately, it wasn't long before I received a runtime error,  whose cause I believe resulted from not having included the debug files, at the line sim.Clear();

I'll post my code below:
Code: [Select]

#include <SFML/System.hpp>
#include <SFML/Graphics.hpp>

int main ()
{

sf::RenderWindow sim(sf::VideoMode(800, 600, 32), "Sandlot");

while (sim.IsOpened())
{
//Store any encountered events
sf::Event event;
while (sim.GetEvent(event))
{
//Close program
if (event.Type == sf::Event::Closed)
sim.Close();
}

sim.Clear();

        // Build a custom convex shape
        sf::Shape Polygon;
        Polygon.AddPoint(0, -50,  sf::Color(255, 0, 0),     sf::Color(0, 128, 128));
        Polygon.AddPoint(50, 0,   sf::Color(255, 85, 85),   sf::Color(0, 128, 128));
        Polygon.AddPoint(50, 50,  sf::Color(255, 170, 170), sf::Color(0, 128, 128));
        Polygon.AddPoint(0, 100,  sf::Color(255, 255, 255), sf::Color(0, 128, 128));
        Polygon.AddPoint(-50, 50, sf::Color(255, 170, 170), sf::Color(0, 128, 128));
        Polygon.AddPoint(-50, 0,  sf::Color(255, 85, 85),   sf::Color(0, 128, 128));

        // Define an outline width
        Polygon.SetOutlineWidth(10);

        // Disable filling and enable the outline
        Polygon.EnableFill(false);
        Polygon.EnableOutline(true);

        // Draw it
        sim.Draw(Polygon);

//Display new screen contents
sim.Display();
}


return EXIT_SUCCESS;

}

Does anyone see the problem?

Pages: [1]
anything