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.
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.
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();
}
std::string(text.GetText()).erase(std::string(text.GetText()).length() - 1);
#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;
};
#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;
sf::String& GetText()
{ return text; }
mass.GetText().SetText("mass");
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.