Values specified by glClearColor are clamped to the range [0,1] FYI.
Oops, not sure why I have that as 2.0f...
[editline]10:22AM[/editline]
Alright, so I made it so that it would only render the objects once, while continuing to call app->Display(), and, as I thought, it now flashes back forth between black nothing and the rendered scene. I'm assuming sfml has some double buffer or something going on, I guess I can avoid it, but this seems like something I should deal with.
Well if it helps. In OpenGL there's glfwSwapBuffers() that you call when you switch them. Maybe look for that.
It doesn't seem like the normal gl display commands work when using sfml. In any case, I think I "solved" the "problem", although "made sense" of the "strangeness" is a more correct way to put it.
There are two different buffers I'm rendering to, and every time I call display, it flips them. If I want the area outside the viewport to render the same color every swap, I just have to clear both buffers to the specified color. It wasn't really a problem, and therefore I didn't really fix it, but now I know how to fix it if a problem does arise.
[QUOTE=Darwin226;22305296]Well if it helps. In OpenGL there's glfwSwapBuffers() that you call when you switch them. Maybe look for that.[/QUOTE]
OpenGL does not have a native swap buffers function. It must be provided by the container of the context.
glfw is a window wrapper for opengl.
I would normally try harder to find this on my own, but my internet is going insane, so my question is this: If I have a bunch of classes inheriting from a base class, and I pass a list of these as the base class, is there a way to determine whether they belong to one of the child classes?
[code]class A
class a: class A
class b: class A
if( class A object== class a)[/code]
^Something like that.
I ask because I saw someone do something like that in c#, if I'm not mistaken.
if (someInstanceofAChildClass is ChildClass) {}
Oops, forgot to say I meant in c++, I realize how the c# reference was misleading.
I think you can use dynamic_cast and check if it returns null, but I could be thinking of something else. Perhaps it's reinstate_cast or static_cast. I've never really used these so I get them mixed up.
[QUOTE=jmanmc;22309975]I think you can use dynamic_cast and check if it returns null, but I could be thinking of something else. Perhaps it's [b]reinstate_cast[/b] or static_cast. I've never really used these so I get them mixed up.[/QUOTE]
You mean reinterpret_cast?
[QUOTE=jmanmc;22309975]I think you can use dynamic_cast and check if it returns null, but I could be thinking of something else. Perhaps it's reinstate_cast or static_cast. I've never really used these so I get them mixed up.[/QUOTE]
Yeah, it's dynamic_cast. (Also, it's "reinterpret_cast")
But in most cases, a situation where dynamic_cast is applicable is a sign of bad design, you should really think twice if you really need to do this.
Obviously it's a valid technique if it's there, what situation would you say dynamic_cast could be used without being considered badly-designed?
[QUOTE=jmanmc;22310300]Obviously it's a valid technique if it's there[/QUOTE]
I never said it was never useful.
[QUOTE=jmanmc;22310300]what situation would you say dynamic_cast could be used without being considered badly-designed?[/QUOTE]
The problem with that question is that dynamic_cast can be (wrongfully or not) applied to so many different situations, the area where it is just fine is also quite large. The most obvious problem with dynamic_cast is that it's terribly slow, so you shouldn't put it in any performance-critical code. Another problem is that you don't get to know what the class really was if it failed, making it impossible to handle such an error in most cases. This is fine if you [I]only[/I] need to know if it's a safe cast or not, which is what dynamic_cast is for. But these situations are rare.
Example of one situation where dynamic_cast is a terrible solution is selecting a piece of code based on the type of subclass you're dealing with. You could use a dynamic_cast with if statements (or try-catch for references, further decreasing performance) to select the code to run. In this situation, you should be using a virtual function instead.
[QUOTE=ryandaniels;22309082]I would normally try harder to find this on my own, but my internet is going insane, so my question is this: If I have a bunch of classes inheriting from a base class, and I pass a list of these as the base class, is there a way to determine whether they belong to one of the child classes?
[code]class A
class a: class A
class b: class A
if( class A object== class a)[/code]
^Something like that.
I ask because I saw someone do something like that in c#, if I'm not mistaken.[/QUOTE]
This is probably a horrible solution, but apparently it works. Include the header <typeinfo>, have at least one virtual function in your class, and then use typeid()==.
Example:
[code]#include <iostream>
#include <typeinfo>
using namespace std;
class A
{
public:
void virtual print() { cout << "A" << endl; }
};
class a: public A
{
public:
void print() { cout << "a" << endl; }
};
class b: public A
{
public:
void print() { cout << "b" << endl; }
};
void testFunc(A& test);
int main()
{
A testA;
a testa;
b testb;
testFunc(testA);
testFunc(testa);
testFunc(testb);
return 0;
}
void testFunc(A& test)
{
if (typeid(test) == typeid(a)) {
cout << "it is a" << endl;
} else {
cout << "it is not a" << endl;
}
}
[/code]
I have a lot of functions (about 20 or 30) and I want to have a universal command that, when input, couts a variable, and then goes back the the function you were in. How do I do that?
C++, by the way.
Wait, misread your post, gimme a second to re-write...
[editline]04:51PM[/editline]
Functions do fundamentally different jobs, so it doesn't make sense for 30 different functions to do the same thing on a certain input. What it sounds like is those 30 functions should be one function. Post code.
Just started learning C# and my first problem I can't seem to fix is:
[code] {
double dblForce;
double dblMass;
double dblAccel;
dblMass = Convert.ToDouble(txtMass.Text);
dblAccel = Convert.ToDouble(txtAccel.Text);
/*The 2 converts give "Input string was not in a correct format." if I don't enter any info into the textbox*/
if (dblMass == null)
{
MessageBox.Show("You forgot to insert a Mass!");
}
else if (dblAccel == null)
{
MessageBox.Show("You forgot to insert the Acceleration!");
}
else if (dblMass < 0)
{
MessageBox.Show("Need a positive Mass!");
}
else
{
dblForce = dblMass * dblAccel;
txtForce.Text = Convert.ToString(dblForce);
}
}[/code]
The 2 converts give "Input string was not in a correct format." if I don't enter any info into the textbox.
Works perfectly if both Textboxes are filled.
Well, you can either catch the exception (FormatException), or if you're a beginner and don't know how to handle exceptions, use [url=http://msdn.microsoft.com/en-us/library/system.double.tryparse.aspx]Double.TryParse[/url] instead, and that will return true if it was able to parse the number, or false otherwise.
edit:
I'm not experienced in C#, being a C++ person, but I suspect that no bulit-in method will ever leave the return value null, without throwing an exception.
[code] double dblForce;
double dblMass;
double dblAccel;
try
{
dblMass = Convert.ToDouble(txtMass.Text);
dblAccel = Convert.ToDouble(txtAccel.Text);
}
catch
{
MessageBox.Show("Invailid Inputs!");
}
if (dblMass < 0)
{
MessageBox.Show("Need a positive Mass!");
}
else
{
dblForce = dblMass * dblAccel;
txtForce.Text = Convert.ToString(dblForce);
}
}
}
}[/code]
Use of unassigned local variable 'dblMass'
says same for dblAccel also.
My knowledge of C# is limited, but I'm pretty sure you need to define them with a default value, so:
[cpp]double dblForce = 0;
double dblMass = 0;
double dblAccel = 0;[/cpp]
Nah, it should come with 0. Post the whole listing, please. Also, prefixing a variable with its type is generally frowned up now: use force, mass and accel as names.
Accel and Mass is user input.
[code]using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace ForceCalc
{
public partial class fmaForm : Form
{
public fmaForm()
{
InitializeComponent();
}
private void fmaForm_Load(object sender, EventArgs e)
{
}
private void btnCalc_Click(object sender, EventArgs e)
{
double dblForce;
double dblMass;
double dblAccel;
try
{
dblMass = Convert.ToDouble(txtMass.Text);
dblAccel = Convert.ToDouble(txtAccel.Text);
}
catch
{
MessageBox.Show("Invailid Inputs!");
}
if (dblMass < 0)
{
MessageBox.Show("Need a positive Mass!");
}
else
{
dblForce = dblMass * dblAccel;
txtForce.Text = Convert.ToString(dblForce);
}
}
}
}
[/code]
[cpp]namespace ForceCalc
{
public partial class fmaForm : Form
{
public fmaForm()
{
InitializeComponent();
}
private void fmaForm_Load(object sender, EventArgs e)
{
}
private void btnCalc_Click(object sender, EventArgs e)
{
double dblForce;
double dblMass;
double dblAccel; //all 3 are yet unassigned
try
{
dblMass = Convert.ToDouble(txtMass.Text); //lets presume this one throws an exception
dblAccel = Convert.ToDouble(txtAccel.Text);
}
catch
{
MessageBox.Show("Invailid Inputs!"); //exception caught, dblMass and dblAccel not set
}
if (dblMass < 0) //use of unassigned variable dblMass D:
{
MessageBox.Show("Need a positive Mass!");
}
else
{
dblForce = dblMass * dblAccel;
txtForce.Text = Convert.ToString(dblForce);
}
}
}
}[/cpp]
[QUOTE=TheBoff;22330821]Nah, it should come with 0. Post the whole listing, please. Also, prefixing a variable with its type is generally frowned up now: use force, mass and accel as names.[/QUOTE]
Hungarian notation was originally used for specifying things that are [b]not[/b] obvious from the type, so instead of dblAccel, you might use mAccel for acceleration in metric units, or impAccel for imperial units. That wrong usage of Hungarian notation was always frowned upon by the originator of it.
Thanks for the tip.
Seems try and catch stop it from recognizing:
[code]dblMass = Convert.ToDouble(txtMass.Text);
dblAccel = Convert.ToDouble(txtAccel.Text);[/code]
Any ideas on how to fix? Do I just not use try and catch? lol
Initialize it to something like 0 in the catch {}
Or return.
Ok so, I wrote a small bit of code (noob here) after watching a video about mentos and coke.
Here's the code:
[CODE]
#include <iostream>
using namespace std;
int main()
{
int a, b;
cout << "How far do you want to go? (In Feet): ";
cin >> a;
cout << endl;
if (a < 5)
{
cout << "You must enter a number higher than 5." << endl << endl;
return main();
}
else
{
cout << a << " divided by 2.04629 equals " << a / 2.04629 << "." << endl << endl;
b = a / 2.04629;
cout << "It would take approximately " << b << " Coke Bottles to reach " << a << " Feet." << endl << endl;
}
return main();
}
[/CODE]
Everything is working fine until I wanted to see how many coke bottles it'd take to reach the Sun. The sun is 491040000000 Feet away. When I type that into my bit of code here, the entire thing spazzes out. It can't handle big numbers. Any idea why?
[QUOTE=slayer20;22340891]Ok so, I wrote a small bit of code (noob here) after watching a video about mentos and coke.
Here's the code:
[CODE]
#include <iostream>
using namespace std;
int main()
{
int a, b;
cout << "How far do you want to go? (In Feet): ";
cin >> a;
cout << endl;
if (a < 5)
{
cout << "You must enter a number higher than 5." << endl << endl;
return main();
}
else
{
cout << a << " divided by 2.04629 equals " << a / 2.04629 << "." << endl << endl;
b = a / 2.04629;
cout << "It would take approximately " << b << " Coke Bottles to reach " << a << " Feet." << endl << endl;
}
return main();
}
[/CODE]
Everything is working fine until I wanted to see how many coke bottles it'd take to reach the Sun. The sun is 491040000000 Feet away. When I type that into my bit of code here, the entire thing spazzes out. It can't handle big numbers. Any idea why?[/QUOTE]
A int can only go up to 2147483647, a unsigned int can only go up to 4294967295, so 491040000000 cannot be stored in an int variable, I suggest using a "long long"
or int64.
I'm getting the "Attempted to read or write protected memory." error when trying to use Gl.glCreateShader( Gl.GL_FRAGMENT_SHADER ).
How can I fix it? I've tried Googling it but no luck.
Sorry, you need to Log In to post a reply to this thread.