Jump to content
  • Advertisement
Sign in to follow this  
Joseph Duchesne

OpenGL OpenGL not drawing full screen

This topic is 4855 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I'm porting my SDL/openGL app to Windows and for some reason the OpenGL only draws 640x480 of the bottom left corner. I am wondering why this is not filling the window/screen when the same code does so when compiled in GCC on a Mac. Here is a stripped down version with just enough to run a starfield and FPS counter: www.staronesw.com/MadTakTest.zip This is compiled in Microsoft Visual C++. Here is main.c: prefVal(SCREEN_WIDTH) is 1024 prefVal(SCREEN_HEIGHT is 768
extern char RootPath[2048];

#if defined(__APPLE_CC__)
#include "SDL.h"
#include <OpenGL/OpenGL.h>
#include "SDL_opengl.h"
#else
#include <windows.h>               // Header File For Windows
#include <gl\gl.h>                 // Header File For The OpenGL32 Library
#include <gl\glu.h>				// Header File For The GLu32 Library
//#include <gl\glaux.h>
#include "SDL/SDL.h"
#endif

#ifndef PLATFORM_DEP
#include "platform_dep.h"
#endif

#ifndef CORE
#include "core.h"
#endif

#ifndef CAMERA
#include "camera.h"
#endif

#ifndef KEYBOARD
#include "keyboard.h"
#endif

#ifndef PREFS_H
#include "prefs.h"
#endif

#ifndef STARFIELD_H
#include "starfield.h"
#endif

#ifndef TEXT_H
#include "text.h"
#endif

#ifndef MUSIC_H
#include "music.h"
#endif

#include <stdio.h> 
#include <stdlib.h>
#include <math.h>
#include <string.h>

#define MAX_FPS 1.0f/60.0f

extern int gameSegment;
int gameSegment=1;
int lastFrameTime = 0;
extern float elapsedTime;
float elapsedTime;
extern int currentMenu;
int currentMenu; //not supposed to be here
extern int thisLoaded;
int thisLoaded; //not supposed to be here
float now;
extern int showFPS;
int showFPS;


void mainLoop()
{
	elapsedTime=0;
	while(elapsedTime<=MAX_FPS)
		elapsedTime = (float)((float)SDL_GetTicks() - (float)lastFrameTime) / 1000.0f;
	lastFrameTime = SDL_GetTicks();
	//if(consoleOn==1) elapsedTime=0;

	runCamera();

	glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();


	//game modes
	/*
	    if (gameSegment==1){
        loadEverything();
    }
    
    if (gameSegment==0){
        tarena(0);
    }
    
    if (gameSegment==2){
        levelEditor();
    }
    
    if (gameSegment==3){
        game();
    }
    
    if (gameSegment==4){
        Menu();
        show_mouse();
    }
	
	if(gameSegment==5){
		luaMenu();
		show_mouse();
	}
	*/
	glViewport (0, 0, prefVal(SCREEN_WIDTH),prefVal(SCREEN_HEIGHT) ); 
	glMatrixMode (GL_PROJECTION);                                // Select The Projection Matrix
	glLoadIdentity ();                                           // Reset The Projection Matrix
	glOrtho(0, 1024, 0, 768, -1024, 1024);

	//console();   //run the console functions
	//luaMain();  //run lua
    
    if(showFPS==1)
     {
        glColor4f(1.0,1.0,0.5,0.5);
        char ttbp[1024];
        int tempint = (int)(1.0f/elapsedTime);
        sprintf(ttbp, "%d FPS",tempint);
        drawText(20.0,20.0,ttbp);
        glColor4f(1.0,1.0,1.0,1.0);
     }

	drawStars();
    
    SDL_GL_SwapBuffers( );
    if(isKey(27)==1)  //dirty hack
	{
		setKey(27,0);
		if(gameSegment==4 && currentMenu==0) quit_game(0);
		gameSegment=4;
		currentMenu=0;
		thisLoaded=0;
	}
}

void process_events( void )
{
    // Our SDL event placeholder
    SDL_Event event;
    
    // Grab all events off the cue
    while( SDL_PollEvent(&event))
     {
        switch (event.type)
         {
            case SDL_KEYDOWN:
                handle_key_down( &event.key.keysym );
                break;
            case SDL_KEYUP:
                handle_key_up( &event.key.keysym );
                break;
            case SDL_MOUSEBUTTONDOWN:
                handle_mouse_down();
                break;
            case SDL_MOUSEBUTTONUP:
                handle_mouse_up();
                break; 
            case SDL_MOUSEMOTION:
                handle_mouse_motion( event.motion.x, event.motion.y);
                break;
            case SDL_QUIT:
                quit_game( 0 );
                break;
            default:
                break;
         }
     }
}


 void setup_opengl ( int width, int height )
{
    glEnable(GL_ALPHA_TEST);
    glEnable (GL_BLEND);
    glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    glHint (GL_POINT_SMOOTH_HINT, GL_DONT_CARE);
    glHint (GL_LINE_SMOOTH_HINT, GL_DONT_CARE);
    
    glViewport(0, 0, width, height);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(0, 1024, 0, 768, -1024, 1024);
    gluPerspective(60, width/height, width, width); 
    glMatrixMode(GL_MODELVIEW);
}


int main( int argc, char* argv[] )
{
    
	loadPlatformDep();
	readPrefs();
	// info on the current video settings
	const SDL_VideoInfo* info = NULL;
	// Dimensions of our window
	int width=prefVal(SCREEN_WIDTH);
	int height=prefVal(SCREEN_HEIGHT);
	int bpp=32;
	// lets init SDL's video subsystem
	if( SDL_Init( SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0 )
	 {
		//failed, exit
		fprintf( stderr, "video/audio init failed: %s\n", SDL_GetError() );
		quit_game( 1 );
	 }
	if( SDL_Init( SDL_INIT_TIMER ) < 0 )
	 {
		//failed, exit
		fprintf( stderr, "timer init failed: %s\n", SDL_GetError() );
		quit_game( 1 );
	 }

	info = SDL_GetVideoInfo();
	if(!info)
	 {
		fprintf( stderr, "Video query failed: %s\n", SDL_GetError() );
		quit_game( 1 );
	 }
    
	bpp = info->vfmt->BitsPerPixel;
	SDL_GL_SetAttribute( SDL_GL_RED_SIZE, 8);
	SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, 8);
	SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, 8);
	SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 32);
	SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1);
    
    if(prefVal(IS_FULLSCREEN)==1){
        if (SDL_SetVideoMode(width, height, bpp, SDL_OPENGL | SDL_FULLSCREEN)==0)
        {
            fprintf( stderr, "Video mode change failed: %s\n", SDL_GetError() );
            quit_game( 1 );
        }
    }else{
        if (SDL_SetVideoMode(width, height, bpp, SDL_OPENGL|SDL_HWSURFACE|SDL_DOUBLEBUF|SDL_RLEACCEL)==0)
         {
            fprintf( stderr, "Video mode change failed: %s\n", SDL_GetError() );
            quit_game( 1 );
         }
    }

    loadKeys();
    setup_opengl(width,height);
    
#ifdef __APPLE__
    long VBL = 1;
    CGLSetParameter(CGLGetCurrentContext(),  kCGLCPSwapInterval, &VBL);
#endif
    
    //hide_mouse();

	loadFonts();
	camera[3]=200.0f;
	starfieldInit(1000);
    
    while( 1 )
     {
        process_events();
        mainLoop();
     }
    return 1;
}

[Edited by - _the_phantom_ on August 5, 2005 2:48:00 PM]

Share this post


Link to post
Share on other sites
Advertisement
no, use the source tags when posting alot of source like that, code should only be used for short sections of code, see the FAQ for details.

For now I'm going to fix the first post...

Share this post


Link to post
Share on other sites
I'm not sure precisely why it isn't working but one thing that strikes me as odd is that you use glViewport in the main loop. If the values of prefVal(...) change between setup_opengl and the mainLoop then you could have problems. Normally you only call glViewport when the window/resolution changes. If the window size/resolution never changes then just use it once in setup_opengl().

Edit:

Also, in setup_opengl you don't cast width and height when calculating aspect ratio. Consequently this will be 1 rather than 1.333

Share this post


Link to post
Share on other sites
Yes, I suppose the GLViewport is odd in my main loop, but this is because portions of the game are drawn in different viewport areas. Setting that resets the previous viewport stuff (I presume). Prefval stuff does not change at all during the loop.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!