you draw your trig to a z of 0, this is incorrect, as the camea's clip space won't draw it since its too close , at least try a 20 (or -20 depending on your setup) on the z axis
Thanks for the advice. I have done a little bit of openGL, but things like this are helpful.
I wonder if it's something wrong with my window?
#include <SFML/Graphics.hpp>
#include <iostream>
#include <ios>
#include <SFML/Window.hpp>
#include <SFML/OpenGL.hpp>
#include "main.h"
using namespace std;
//Hardcoded in.
bool running = true, runningSecondary = true;
const int XSize = 800, YSize = 600;
double countX = 0;
double countY = 0;
using sf::Thread;
//Draws the ball and returns the circle object back.
sf::CircleShape drawCircle(sf::RenderWindow* window2, sf::CircleShape circle = sf::CircleShape(100.f))
{
circle.setFillColor(sf::Color::Green);
window2->clear();
window2->draw(circle);
window2->display();
return circle;
}
//Changes the position of the ball.
void changePos(bool reverse, char choice)
{
if(reverse)
{
switch (choice)
{
case 'b':
countX -= .05;
countY -= .05;
break;
case 'x':
countX -= .05;
break;
case 'y':
countY -= .05;
break;
}
}
else
{
switch (choice)
{
case 'b':
countX += .05;
countY += .05;
break;
case 'x':
countX += .05;
break;
case 'y':
countY += .05;
break;
}
}
}
//Animates the moving of the ball.
void animate(animateThread& at)
{
sf::CircleShape circle = at.circle;
sf::RenderWindow* window2 = at.renderWindow;
int circleDiameter = circle.getRadius() * 2;
while(runningSecondary)
{
if(countX >= 799 - circleDiameter)
{
cout << circle.getPosition().x << " XXXXXX" << endl;
changePos(true, 'x');
}
else if(countY >= 599 - circleDiameter)
{
cout << circle.getPosition().y << " YYYYYYYYY" << endl;
changePos(true, 'y');
}
else if((countX >= 799 - circleDiameter) && (countY >= 599 - circleDiameter))
{
changePos(true, 'b');
}
else{changePos(false, 'b'); }
circle.setPosition(countX,countY);
drawCircle(window2, circle);
}
}
int main()
{
sf::Window window(sf::VideoMode(XSize, YSize), "OpenGL", sf::Style::Default, sf::ContextSettings(32)); //OpenGl Window
sf::RenderWindow window2(sf::VideoMode(XSize,YSize), "Graphics"); //SFML Graphics Window
window.setVerticalSyncEnabled(true);
glDisable(GL_DEPTH_TEST);
sf::CircleShape circle = drawCircle(&window2); //Draw the circle in the origin.
//Main event loops.
while (running)
{
// handle events
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
{
// end the program
running = false;
}
else if (event.type == sf::Event::Resized)
{
// adjust the viewport when the window is resized
glViewport(0, 0, event.size.width, event.size.height);
}
}
sf::Event Event_Window2;
while(window2.pollEvent(Event_Window2))
{
if(Event_Window2.type == sf::Event::Closed)
{
running = false;
}
else if(Event_Window2.type == sf::Event::KeyPressed)
{
if(Event_Window2.key.code == sf::Keyboard::P)
{
runningSecondary = false;
}
}
else if (Event_Window2.type == sf::Event::Resized)
{
// adjust the viewport when the window is resized
glViewport(0, 0, Event_Window2.size.width, Event_Window2.size.height);
}
}
//Creates a struct containing the initial circle object and the window.
animateThread at;
at.circle = circle;
at.renderWindow = &window2;
//Threads the animation so it doesn't interfere with the Event catching.
//animate is the name of the method, at is the struct object.
//Thread animationThread(&animate, at);
//animationThread.launch();
//OpenGL Implementation Attempt.
// clear the buffers
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// draw...
glBegin(GL_TRIANGLES);
glVertex3f(100.0f, 100.0f, 20.0f);
glVertex3f(150.0f, 100.0f, 20.0f);
glVertex3f(125.0f, 50.0f, 20.0f);
glEnd();
// end the current frame (internally swaps the front and back buffers)
window.display();
}
// release resources...
return 0;
}