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 - sludge

Pages: [1] 2
1
Window / mouse input not always registering
« on: August 25, 2010, 06:43:30 am »
Ah ha.  I figured it out.  After you mentioned that input and events are essentially the same thing, it all clicked.

2
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?

3
Graphics / partially transparent sprites
« on: August 20, 2010, 09:50:00 am »
that worked like a charm.  Thank you

4
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?

5
Graphics / glClear
« on: July 28, 2010, 06:36:53 pm »
Does this mean that any OpenGL setting I make could also affect drawing of graphics using SFML commands?  For example, could I accidentally adjust where I draw a box if I were to have set the viewport before calling said draw command?

6
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.

7
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

8
General / Linking OpenGL
« on: July 22, 2010, 10:48:46 pm »
awesome. thank you.

9
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.

10
Graphics / A cursor for typing
« on: July 15, 2010, 04:16:40 pm »
I suppose that I want to do the latter.  In essence, whenever a number is pressed, I want to add it to the text member inside an sf::String.

The only member of a sf::Event::TextEvent is a public unicode member.  Is there an example of how I can use this input?

Also, suppose I have a class with a member sf::String.  If the delete key is pressed, I want to delete the last character of the text member inside this string. I'm sure there is an easier way to do this than what I was trying to do:


Code: [Select]
std::string(text.GetText()).erase(std::string(text.GetText()).length() - 1);

11
Graphics / A cursor for typing
« on: July 14, 2010, 10:04:28 pm »
Alright. That sounds good.

My next question regards input.  I looked in the documentation for a bool function that returns if an input event is a standard letter or number.  If this is the case, I can essentially return this key and append it to a string.  Does such a function exist?

Otherwise I am going to need to do something along the lines of
if the input == 'a' or input == 'b' and so on.

Thank you

12
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.

13
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?

14
Graphics / Returning sf:String reference from member function
« on: July 13, 2010, 04:43:12 pm »
of course I can

Here is the .h file
Code: [Select]


#include "headers.h"

#pragma once
class VariableLabel
{
public:
VariableLabel(void);                                         // Will set the sprite of each label instance
static bool Initialize(const std::string& ImageFile);        // The image is loaded only once
sf::Sprite& GetSprite()
{ return sprite; }
sf::String GetText() const
{ return text; }
double GetValue() const
{ return value; }
void SetText(std::string word)
{ text.SetText(word); }
void SetPosition(float x, float y)
{ text.SetPosition(x, y); }
void SetValue(double value)
{ value = value; }

private:
    static sf::Image image;           // Each sprite object shares this single image
    sf::Sprite sprite;                // But there is one sprite per variable label
static bool initializationState;  // Ensure initialization occurs only once
double value;
sf::String text;
};



And here is the .cpp file
Code: [Select]

#include "VariableLabel.h"

VariableLabel::VariableLabel(void)
{
//We only want to load the image once
if (!initializationState)
{
Initialize("Resources/VariableLabel.png");
initializationState = true;
}

// Every sprite uses the same image
sprite.SetImage(image);
}

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

sf::Image VariableLabel::image;
bool VariableLabel::initializationState = false;

15
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.

Pages: [1] 2