Du bist nicht angemeldet.

Stilllegung des Forums
Das Forum wurde am 05.06.2023 nach über 20 Jahren stillgelegt (weitere Informationen und ein kleiner Rückblick).
Registrierungen, Anmeldungen und Postings sind nicht mehr möglich. Öffentliche Inhalte sind weiterhin zugänglich.
Das Team von spieleprogrammierer.de bedankt sich bei der Community für die vielen schönen Jahre.
Wenn du eine deutschsprachige Spieleentwickler-Community suchst, schau doch mal im Discord und auf ZFX vorbei!

Werbeanzeige

1

22.02.2014, 18:20

Keine Ausgabe der Punkte

Hallo Leute, ich habe versucht die Punkte auf dem Bildschirm auszugeben, stattdessen erscheint nur ein schwarzes Fenster, wo liegt das Problem? Ich bitte um Hilfe Danke!
IDE: Microsoft Visual C++ Express 2010

Ganzer Quellcode(sorry das er so lang ist):

#ifndef SCREEN_INTERFACE_H
#define SCREEN_INTERFACE_H

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



typedef unsigned char uchar;
typedef unsigned short ushort;
typedef unsigned long ulong;

void exit_error( char *message );
void exit_nofile( char *user, char *filename );
void exit_nomemory( char *user, char *array );
void message( char *title, char *message );

#define x_res screen_interface.get_xr()
#define y_res screen_interface.get_yr()

#define WIN32_LEAN_AND_MEAN

LRESULT CALLBACK main_window_procedure( HWND main_window_handle, UINT message, WPARAM wparam, LPARAM lparam )
{
if( message == WM_CLOSE ) { PostQuitMessage( 0 ); return 0; }

return DefWindowProc( main_window_handle, message, wparam, lparam );
}

class hardware_interface
{
private:
uchar enlarged;
long x_resolution, y_resolution;

HWND main_window_handle;
HDC device_context;
HGLRC rendering_context;
DEVMODE old_screen_settings;

void initialise_platform( void );

public:
void fullscreen( HINSTANCE hInstance, long xr, long yr );
void open_window( HINSTANCE hInst, long xr, long yr );
void close_window( void );

long get_xr( void ) { return x_resolution; }
long get_yr( void ) { return y_resolution; }

void swap_buffers( void ) { SwapBuffers( device_context ); }

hardware_interface( void ) : enlarged( 0 ), x_resolution( 0 ), y_resolution( 0 )
{
main_window_handle = NULL; device_context = NULL; rendering_context = NULL;
memset( &old_screen_settings, 0, sizeof( old_screen_settings ) );
}
~hardware_interface( void ) { close_window(); }
} screen_interface;

void hardware_interface::fullscreen( HINSTANCE hinst, long xr, long yr )
{
x_resolution = xr; y_resolution = yr;
enlarged = 1;

if( EnumDisplaySettings( NULL, ENUM_CURRENT_SETTINGS, &old_screen_settings ) != TRUE )
exit_error( "Fehler während der Ermittlung der aktuellen Bildschirmbetriebsart.\n" );

WNDCLASS winclass;

winclass.style = CS_OWNDC;
winclass.lpfnWndProc = main_window_procedure;
winclass.cbClsExtra = 0;
winclass.cbWndExtra = 0;
winclass.hInstance = hinst;
winclass.hIcon = LoadIcon( NULL, IDI_APPLICATION );
winclass.hCursor = LoadCursor( NULL, IDC_ARROW );
winclass.hbrBackground = (HBRUSH) GetStockObject( BLACK_BRUSH );
winclass.lpszMenuName = NULL;
winclass.lpszClassName = "Main Window";
RegisterClass( &winclass );

char window_name[] = "3D-Grafik Programmierung";

main_window_handle = CreateWindowEx
(
WS_EX_TOPMOST, "Main Window", window_name, WS_VISIBLE | WS_POPUP,
0,0, xr, yr, NULL, NULL, hinst, NULL
);

if( main_window_handle == 0 )
exit_error( "Fehler beim Öffnen des Programmfensters.\n" );

long bit_depth = 32;

DEVMODE new_screen_settings;

memset( &new_screen_settings, 0, sizeof( new_screen_settings ) );
new_screen_settings.dmSize = sizeof( new_screen_settings );
new_screen_settings.dmPelsWidth = xr;
new_screen_settings.dmPelsHeight = yr;
new_screen_settings.dmBitsPerPel = bit_depth;
new_screen_settings.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;

if( ChangeDisplaySettings( &new_screen_settings, 0 ) != DISP_CHANGE_SUCCESSFUL )
exit_error( "Fehler beim Einstellen der gewünschten Bildschirmbetriebsart.\n" );

ShowCursor( 0 );

initialise_platform();
}

void hardware_interface::open_window( HINSTANCE hInst, long xr, long yr )
{
x_resolution = xr; y_resolution = yr;
long bit_depth = 32;

WNDCLASS winclass;

winclass.style = CS_OWNDC;
winclass.lpfnWndProc = main_window_procedure;
winclass.cbClsExtra = 0;
winclass.cbWndExtra = 0;
winclass.hInstance = hInst;
winclass.hIcon = LoadIcon( NULL, IDI_APPLICATION );
winclass.hCursor = LoadCursor( NULL, IDC_ARROW );
winclass.hbrBackground = (HBRUSH) GetStockObject( BLACK_BRUSH );
winclass.lpszMenuName = NULL;
winclass.lpszClassName = "Main Window";
RegisterClass( &winclass );


int x_add = 2 * (GetSystemMetrics( SM_CXBORDER ) + GetSystemMetrics( SM_CXEDGE ));
int y_add = 2 * (GetSystemMetrics( SM_CYBORDER ) + GetSystemMetrics( SM_CYEDGE )) + GetSystemMetrics( SM_CYCAPTION );

char window_name[] = "Grafikprogrammierung mit OpenGL";

main_window_handle = CreateWindow
(
"Main Window", window_name, WS_CAPTION | WS_POPUPWINDOW | WS_VISIBLE,
0, 0, xr + x_add, yr + y_add, NULL, NULL, hInst, NULL
);

if( main_window_handle == 0 )
exit_error( "Fehler beim Öffnen des Programmfensters.\n" );

initialise_platform();

}

void hardware_interface::initialise_platform( void )
{
PIXELFORMATDESCRIPTOR pfd;
int format;
device_context = GetDC( main_window_handle );
memset( &pfd, 0, sizeof( pfd ) );
pfd.nSize = sizeof( PIXELFORMATDESCRIPTOR );
pfd.nVersion = 1;
pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL; // | PFD_DOUBLEBUFFER;
pfd.iPixelType = PFD_TYPE_RGBA;
pfd.cColorBits = 24;
pfd.cDepthBits = 16;
pfd.cAlphaBits = 8;
pfd.iLayerType = PFD_MAIN_PLANE;


format = ChoosePixelFormat( device_context, &pfd );
SetPixelFormat( device_context, format, &pfd );

rendering_context = wglCreateContext( device_context );
wglMakeCurrent( device_context, rendering_context );

glMatrixMode( GL_PROJECTION ); glLoadIdentity();
gluOrtho2D( 0, x_resolution, 0, y_resolution );
glMatrixMode( GL_MODELVIEW );

}

void hardware_interface::close_window( void )
{
if( enlarged )
if( ChangeDisplaySettings( &old_screen_settings, 0 ) != DISP_CHANGE_SUCCESSFUL )
exit_error( "Fehler beim Einstellen der ursprünglichen Bildschirmbetriebsart.\n" );

wglMakeCurrent( NULL, NULL );
wglDeleteContext( rendering_context );
ReleaseDC( main_window_handle, device_context );

DestroyWindow( main_window_handle );
}

void exit_error( char *message )
{
screen_interface.close_window();

ShowCursor( 1 );
MessageBox( NULL, message, "Programmabbruch nach einem schwerwiegenden Fehler", MB_OK );

exit( 1 );
}

void exit_error( char *message, char *title )
{
screen_interface.close_window();

ShowCursor( 1 );
MessageBox( NULL, message, title, MB_OK );

exit( 1 );
}

void exit_nofile( char *user, char *filename )
{
char string[ 500 ];
sprintf( string, "%s: Fehler beim Öffnen der Datei '%s'.\n", user, filename );

exit_error( string );
}

void exit_nomemory( char *user, char *array )
{
char string[ 500 ];
sprintf( string, "%s: Fehler während der Reservierung von Arbeitsspeicher für das Array '%s'.\n", user, array );

exit_error( string );
}

void message( char *title, char *message )
{
MessageBox( NULL, message, title, MB_OK );
}

#endif

// main.cpp:

#include <Windows.h>
#include <gl\gl.h>
#include <gl\glu.h>

#include "screen_interface.h"

MSG msg;
unsigned char key_pressed( void );

int WINAPI WinMain( HINSTANCE hinst, HINSTANCE pinst, LPSTR cmdl, int cmds )
{
screen_interface.open_window(hinst, 640, 480);


while( 1 )
{
if( key_pressed() ) break;


glBegin( GL_POINTS );


GLubyte c = rand() % 256;
GLdouble sx = rand() % 640;
GLdouble sy = rand() % 480;

glColor3f(c,c,c);
glVertex2d(sx,sy);

glEnd();
}

return msg.wParam;
}

unsigned char key_pressed( void )
{
if( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) )
{
if( msg.message == WM_QUIT || msg.message == WM_KEYDOWN ) return 1;

TranslateMessage( &msg );
DispatchMessage( &msg );
}

return 0;
}

2

22.02.2014, 20:07

1. Wen du einen Fehler hast, beschreibe was genau du bereits versucht hast.
2. [cpp]-Tags
3. Doku lesen
4. Wie schnell ist dein Auge?
"Theory is when you know something, but it doesn’t work. Practice is when something works, but you don’t know why. Programmers combine theory and practice: Nothing works and they don’t know why." - Anon

3

22.02.2014, 20:30

Der Compiler kann den Code compellieren, nur was entsteht ist ein schwarzes Fenster ohne den Punkten in ihm drin.

Außerdem habe ich mit dem Code unterhalb probiert, weiße Farbe zu erzeugen aber es geht auch nicht...

glBegin(GL_POINTS);
glColor3f(1.0f,1.0f,1.0f); (weiße Farbe)
...

Werbeanzeige