Page 1 of 2 12 LastLast
Results 1 to 10 of 14

Thread: JEDI-Sdl + dglOpenGL crash on Windows

  1. #1

    JEDI-Sdl + dglOpenGL crash on Windows

    Hello, i have problem with my engine class. When i compile it on linux, all works fine, but on windows something crash application. I use FPC 2.0.4.

    Code:
    unit engine;
    
    interface
    
    uses
    	sdl,
    	dglOpenGL,
    	sysUtils;
    	
    var
    	oldGetTicks: uInt32;
    	frame: double;
    	frameRate: integer = 0;
    	frameCount: integer = 0;
    	timerTime: uInt32 = 0;
    	
    type
    	TEngine = class
    	private
    		quit: boolean;
    		event: tsdl_event;
    		mousePos: TPoint;
    
    		procedure keyDown(key: integer);
    		procedure keyUp(key: integer);
    		procedure mouseUp(key: integer);
    		procedure mouseDown(key: integer);
    		procedure update;
    		procedure render;
    		procedure start;
    	public
    		width, height, bpp: integer;
    		fullscreen: boolean;
    		fps, maxFps: integer;
    		title: string;
    		screen: psdl_surface;
    		constructor create;
    		procedure init;
    	end;
    	
    procedure initOpenGL(width, height, fps: integer);
    
    implementation
    	
    procedure initOpenGL(width, height, fps: integer);
    begin
    	glShadeModel(gl_smooth);
    	glClearColor(0.0, 0.0, 0.0, 0.0);
    	glDisable(gl_depth_test);
    	glHint(gl_perspective_correction_hint, gl_nicest);
    	
    	glViewport(0, 0, width , height);
    	
    	glMatrixMode(gl_projection);
    	
    	glLoadIdentity();
    	
    	glOrtho(0, width, height, 0, 0, fps);
    	glMatrixMode(gl_modelview);
    	glLoadIdentity();
    	glEnable(gl_texture_2d);
    	glBlendFunc(gl_src_alpha, gl_one_minus_src_alpha);
    end;
    	
    constructor TEngine.create;
    begin
    	quit := false;
    	fullscreen := false;
    	width := 800;
    	height := 600;
    	bpp := 32;
    	fps := 0;
    	maxFps := 100;
    	title := 'engine';
    end;
    
    procedure TEngine.init;
    var
    	videoInfo : psdl_videoInfo;
    	videoFlags: cardinal;
    begin
    	if sdl_init(sdl_init_video) = -1 then
    	begin
    		sdl_quit;
    		halt(1);
    	end;
    	
    	videoInfo := sdl_getVideoInfo;
    	
    	videoFlags := sdl_opengl;
    	videoFlags := videoFlags or sdl_doublebuf;
    	videoFlags := videoFlags or sdl_hwpalette;
    	
    	if fullscreen then videoFlags := videoFlags or sdl_fullscreen;
    		
    	if videoInfo.hw_available <> 0 then
    		videoFlags &#58;= videoFlags or sdl_hwsurface
    	else
    		videoFlags &#58;= videoFlags or sdl_swsurface;
    	
    	if  videoInfo.blit_hw <0>= timerTime + 1000 then
    	begin
    		fps &#58;= frameCount;
    		frameCount &#58;= 0;
    		timerTime &#58;= sdl_getTicks;
    	end;
    	
    	sdl_wm_setCaption&#40;PChar&#40;'FPS&#58; ' + intToStr&#40;fps&#41;&#41;, nil&#41;;
    end;
    	
    procedure TEngine.start;
    var
    	i&#58; integer;
    begin
    	oldGetTicks &#58;= sdl_getTicks;
    	frame &#58;= 0;
    	
    	while not quit do
    	begin
    		while sdl_pollEvent&#40;@event&#41; > 0 do
    		begin
    			if event.type_ = sdl_quitev then quit &#58;= true;
    			
    			if event.type_ = sdl_keydown then
    			begin
    				case event.key.keysym.sym of 
    					sdlk_escape&#58;
    						quit &#58;= true;
    				end;
    				
    				keyDown&#40;event.key.keysym.sym&#41;;
    			end;
    				
    			if event.type_ = sdl_keyup then
    			begin
    				keyUp&#40;event.key.keysym.sym&#41;;
    			end;
    			
    			if event.type_ = sdl_mousemotion then
    			begin
    				mousePos.x &#58;= event.button.x;
    				mousePos.y &#58;= event.button.y;
    			end;
    			
    			if event.type_ = sdl_mousebuttonup then
    			begin
    				if event.button.button = sdl_button_left then
    				begin
    					mouseUp&#40;1&#41;;
    				end;
    				if event.button.button = sdl_button_right then
    					mouseUp&#40;2&#41;;
    			end;
    			if event.type_ = sdl_mousebuttondown then
    			begin
    				if event.button.button = sdl_button_left then
    				begin
    					mouseDown&#40;1&#41;;
    				end;
    				if event.button.button = sdl_button_right then
    					mouseDown&#40;2&#41;;
    			end;
    		end;
    				
    		if sdl_getTicks - oldGetTicks > 0 then frame &#58;= frame + &#40;maxFps / &#40;1000 / &#40;sdl_getTicks - oldGetTicks&#41;&#41;&#41;;
    		oldGetTicks &#58;= sdl_getTicks;
    		
    		for i &#58;= 1 to trunc&#40;frame&#41; do
    		begin
    			update;
                    end;        
    
    		frame &#58;= frame - trunc&#40;frame&#41;;
                                 
    		render;
    		
    		sdl_flip&#40;screen&#41;;
    
    		sdl_delay&#40;1&#41;
    	end;
    end;
    		
    end.
    ttp://pordesign.eu/public_html/hax/opengl.rar - sample for windows.

  2. #2

    JEDI-Sdl + dglOpenGL crash on Windows

    have you remembered to call the dglOpengl init function before usgin opengl calls?
    I know I had some few headaches last time I used dglOpengl because I forgot it.
    Imagine I've written something clever here inspiring you to make something awesome. If that happens give me credits

  3. #3

    JEDI-Sdl + dglOpenGL crash on Windows

    Code:
    InitOpenGL;
    ReadExtensions;
    before you do anything

  4. #4

    JEDI-Sdl + dglOpenGL crash on Windows

    Doesn't change anything, crash only on windows. I am confused...

  5. #5

    JEDI-Sdl + dglOpenGL crash on Windows

    repost you code outside [C0de] tags,
    the board meshed your code
    From brazil (:

    Pascal pownz!

  6. #6

    JEDI-Sdl + dglOpenGL crash on Windows

    http://pordesign.eu/opengl.rar

    Well, here is the package with source code, posting code outside [c0de] tag is uber unreadable So, imho package is the best way :>

  7. #7

    JEDI-Sdl + dglOpenGL crash on Windows

    Wesz, edit your first post and check "Disable HTML in this post" and then repaste your code within the code tags--it'll work just fine then.

  8. #8

    JEDI-Sdl + dglOpenGL crash on Windows

    i found the problem, you are not calling InitOpenGL from dglOpenGL.

    as you are using this same procedure name for the engine, just use "dglOpenGl."

    put
    [pascal] dglOpenGL.InitOpenGL();
    dglOpenGL.ReadExtensions();[/pascal]
    at the beginning of the procedure
    procedure initOpenGL(width, height, fps: integer);
    From brazil (:

    Pascal pownz!

  9. #9

    JEDI-Sdl + dglOpenGL crash on Windows

    I have changed initOpenGL to initPorGL and added two calling lines.
    Code:
    procedure initPorGL&#40;width, height, fps&#58; integer&#41;;
    begin
    	dglOpenGL.InitOpenGL&#40;&#41;;
    	dglOpenGL.ReadExtensions&#40;&#41;;
    	glShadeModel&#40;gl_smooth&#41;;
    	glClearColor&#40;0.0, 0.0, 0.0, 0.0&#41;;
    	glDisable&#40;gl_depth_test&#41;;
    	glHint&#40;gl_perspective_correction_hint, gl_nicest&#41;;
    	
    	glViewport&#40;0, 0, width , height&#41;;
    	
    	glMatrixMode&#40;gl_projection&#41;;
    	
    	glLoadIdentity&#40;&#41;;
    	
    	glOrtho&#40;0, width, height, 0, 0, fps&#41;;
    	glMatrixMode&#40;gl_modelview&#41;;
    	glLoadIdentity&#40;&#41;;
    	glEnable&#40;gl_texture_2d&#41;;
    	glBlendFunc&#40;gl_src_alpha, gl_one_minus_src_alpha&#41;;
    end;
    Ofcourse problem with engine is only on windows. When i run application:
    Code:
    An unhandled exception occurred at $00000000 &#58;
    EAccessViolation &#58; Access violation
    $00000000
    http://pordesign.eu/public_html/hax/sdlgltest.rar Here is full source code and binaries for windows and linux.

    WTF?

  10. #10

    JEDI-Sdl + dglOpenGL crash on Windows

    replace

    Code:
    sdl_flip&#40;screen&#41;;
    with

    Code:
    SDL_GL_SwapBuffers;
    From brazil (:

    Pascal pownz!

Page 1 of 2 12 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •