Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

My OpenGL setup is somehow configured to work like so:

(-1, 1) (0, 1) (1, 1)
(-1, 0) (0, 0) (1, 0)
(-1, -1) (0, -1) (1, -1)

How do I configure it so that it works like so:

(0, 0) (SW/2, 0) (SW, 0)
(0, SH/2) (SW/2, SH/2) (SW, SH/2)
(0, SH) (SW/2, SH) (SW/2, SH)

SW as Screen Width. SH as Screen Height.

This solution would have to fix the problem of I can't translate significantly(>1) on the Z axis. Depth doesn't seem to be working either. The Perspective code I'm using is that of my WORKING GLUT OpenGL code which has a cool 3d grid and camera system etc. But my OpenGL setup doesn't seem to work with SFML.

Help me guys. :(

Thanks in advance. :)

#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>
#include <SFML/Audio.hpp>
#include <SFML/Network.hpp>
#include <SFML/OpenGL.hpp>
#include "ResourcePath.hpp" //Mac-only

#define _USE_MATH_DEFINES
#include <cmath>

double screen_width = 640.f;
double screen_height = 480.f;

int main (int argc, const char **argv) {
    sf::ContextSettings settings;
    settings.depthBits         = 24;
    settings.stencilBits       = 8;
    settings.antialiasingLevel = 2;
    sf::Window window(sf::VideoMode(screen_width, screen_height, 32), "SFML OpenGL", sf::Style::Close, settings);

    window.setActive();

    glEnable(GL_DEPTH_TEST);
    glEnable(GL_LIGHTING);
    glEnable(GL_LIGHT0);
    glEnable(GL_NORMALIZE);
    glEnable(GL_COLOR_MATERIAL);

    glShadeModel(GL_SMOOTH);

    glViewport(0, 0, screen_width, screen_height);

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();

    //glOrtho(0.0f, screen_width, screen_height, 0.0f, -100.0f, 100.0f);
    gluPerspective(45.0f, (double) screen_width / (double) screen_height , 0.f, 100.f);

    glClearColor(0.f, 0.f, 1.f, 0.f); //blue

    while (window.isOpen()) {
        sf::Event event;
        while (window.pollEvent(event)) {
            switch (event.type) {
                case sf::Event::Closed:
                    window.close();
                    break;

            }

            switch (event.key.code) {
                case sf::Keyboard::Escape:
                    window.close();
                    break;
                case 'W':
                    break;
                case 'S':
                    break;
                case 'A':
                    break;
                case 'D':
                    break;
            }
        }

        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();

        glTranslatef(0.f, 0.f, 0.f);

        glPushMatrix();

        glBegin(GL_QUADS);

        glColor3f(1.f, 0.f, 0.f);
        glVertex3f(-1.f, 1.f, 0.f);

        glColor3f(0.f, 1.f, 0.f);
        glVertex3f(1.f, 1.f, 0.f);

        glColor3f(1.f, 0.f, 1.f);
        glVertex3f(1.f, -1.f, 0.f);

        glColor3f(0.f, 0.f, 1.f);
        glVertex3f(-1.f, -1.f, 0.f);

        glEnd();

        glPopMatrix();

        window.display();
    }

    return EXIT_SUCCESS;
}
share|improve this question
    
Hum, sorry but you should tell us what problem you're trying to fix exactly. And what is this "OpenGL setup" you're giving? Maybe illustrate your question with a picture or two? –  Laurent Couvidou Jun 14 '12 at 19:57
    
The OpenGL setup is the code. –  Marc Alexander Reed Jun 15 '12 at 6:51
add comment

1 Answer

This might help you...

You'll need to change the camera's projection view. Normally, I don't think you use pixel values with a 3D view- unless I'm mistaken. But you can do it fairly easily in 2D:

glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
glOrtho (0, XSize, YSize, 0, 0, 1);
glMatrixMode (GL_MODELVIEW);

where XSize and YSize are the screen width/heights. Check here for more on 2D drawing. If you want 3D drawing, you'll probably want to mess around with the gluPerspective method (GLU, not the standard GL)

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.