amiga-news DEUTSCHE VERSION
.
Links| Forums| Comments| Report news
.
Chat| Polls| Newsticker| Archive
.

amiga-news.de Forum > Programmierung > BitMap und Farbe setzen [ - Search - New posts - Register - Login - ]

-1- [ - Post reply - ]

2009-09-10, 16:11 h

eliotmc
Posts: 925
User
Hallo,

ich probiere mich gerade ein wenig in die System Grafikfunktionen
einzuarbeiten und hände irgendwie fest.

Hier einfach mal mein Beispiel Code:
C code:
#include <exec/types.h>
#include <clib/alib_protos.h>
#include <graphics/rpattr.h>
#include <intuition/intuitionbase.h>
#include <graphics/gfxbase.h>
#include <graphics/gfxmacros.h>
#include <graphics/gfx.h>
#include <cybergraphx/cybergraphics.h>
#include <stdio.h>

#include <proto/muimaster.h>
#include <proto/graphics.h>
#include <proto/intuition.h>
#include <proto/exec.h>
#include <proto/dos.h>
#include <proto/utility.h>

/***********************************************************************************/

struct GfxBase 		 *GfxBase;
struct IntuitionBase *IntuitionBase;

/***********************************************************************************/

enum{
	MSG_ERROR_NOERROR = 0,
	MSG_ERROR_GRAPHICS,
	MSG_ERROR_INTUITION,
	MSG_ERROR_SCREEN,
};

STRPTR TAB_ERRORS[] = {
	"",
	"Unable to open 'graphics.library'!",
	"Unable to open 'intuition.library'!",
	"Unable to open screen!",
};

ULONG colortable[]=
{
16L<<16,
0x00000000,0x00000000,0x00000000,
0xAAAAAAAA,0xAAAAAAAA,0xAAAAAAAA,
0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,
0x66666666,0x88888888,0xBBBBBBBB,
0x00000000,0xFFFFFFFF,0xFFFFFFFF,
0xFFFFFFFF,0xFFFFFFFF,0x00000000,
0xFFFFFFFF,0x00000000,0x00000000,
0x00000000,0xFFFFFFFF,0x00000000,
0xFFFFFFFF,0x00000000,0xFFFFFFFF,
0xAAAAAAAA,0x55555555,0x00000000,
0xEEEEEEEE,0x77777777,0x44444444,
0x44444444,0x55555555,0xAAAAAAAA,
0x77777777,0x44444444,0xFFFFFFFF,
0xEEEEEEEE,0x11111111,0x66666666,
0x11111111,0x99999999,0x33333333,
0xFFFFFFFF,0x00000000,0x00000000,
0x00000000};


/***********************************************************************************/

//50 ticks=second

LONG getBestPen(const struct Screen* screen, int r, int g, int b){
    return ObtainBestPen(screen->ViewPort.ColorMap, r,g,b,OBP_Precision, PRECISION_EXACT,TAG_DONE);
}

int main( void )
{
	struct Screen *screen;
    struct RastPort *rp=NULL;
	int result;
    LONG pen=1L;
    struct BitMap *myBitMap;
    struct RastPort myRp;

   // int resultPixel=88;
   // int i=0;

	result = MSG_ERROR_GRAPHICS;
	if( (GfxBase = (struct GfxBase *) OpenLibrary( "graphics.library", 39 ) ) ) {
		result = MSG_ERROR_INTUITION;
		if( (IntuitionBase = (struct IntuitionBase *) OpenLibrary( "intuition.library", 39 ) ) ) {
			result = MSG_ERROR_SCREEN;
			if( (screen = (struct Screen*) OpenScreenTags( NULL,
            											SA_Width, 320,
                                                        SA_Height, 240,
                                                        SA_Depth, 16,
                                                        SA_Title, "Test",
                                                        SA_ShowTitle,FALSE,
                                                        SA_Colors32,colortable,
                                                        TAG_DONE )
                                                        ) ) {

				VPrintf("Okn",&result);
                rp=&screen->RastPort;
                SetDrMd(rp,JAM1);
                //Farbe setzen
                SetAPen(rp,2L);
                //Bildschirm füllen mit Pen
 				SetRast(rp,2L);

                pen = ObtainBestPen(screen->ViewPort.ColorMap, 0xFFFFFFFF,0x00000000,0x00000000,
                OBP_Precision, PRECISION_EXACT,TAG_DONE);
              
           
                printf("Pen: %lin",pen);
                SetAPen(rp,pen);
                //SetBPen(rp,1L);
                SetOPen(rp,pen);
                //Rect malen
                RectFill(rp,10,10,20,20);

                
                //Malt einen Pixel
                
               WritePixel(rp,200,150);
              

                //Bewegt den Cursor zur Position
                Move(rp, 0,50);
                //Zeichnet eine Linie
                Draw(rp,320,50);

                //Zeichnet eine Ellipse
                DrawEllipse(rp,100,100,10,20);

                //Zeichnet einen Kreis
                DrawCircle(rp, 70,70,20);

                //Füllt eine Fläche
                Flood(rp,1,100,100);

				Delay( 5 * 50 );

                //Und jetzt mit einer BitMap
                myBitMap= AllocBitMap(320,
        					        240,
                                    32,
                                    BMF_CLEAR|BMF_DISPLAYABLE|SHIFT_PIXFMT(PIXFMT_ARGB32)|BMF_SPECIALFMT,
                                    NULL);
				InitRastPort(&myRp);
                myRp.BitMap = myBitMap;
                SetRGB4(&screen->ViewPort,
                				7,
                				0xFFFFFFFF,
                				0x00000000,
                                0x00000000);
                pen = ObtainBestPen(screen->ViewPort.ColorMap, 0xFFFFFFFF,0x00000000,0x00000000,OBP_Precision, PRECISION_IMAGE,TAG_DONE);
                printf("Pen: %lin",pen);
                SetAPen(&myRp, 15);
                RectFill(&myRp,10,10,50,50);

                BltBitMapRastPort(myBitMap,
                                    0,
                                    0,
                                    rp,
                                    0,
                                    0,
                                    320,
                                    240,
                                    0xc0);
                Delay( 5 * 50 );

				result = MSG_ERROR_NOERROR;
				CloseScreen( screen );
                FreeBitMap(myBitMap);
               
			}
			CloseLibrary( &IntuitionBase->LibNode );
		}
		CloseLibrary( &GfxBase->LibNode );
	}
	if( result ) {
		VPrintf( TAB_ERRORS[ result ], &result );
		result = 20;
	}
	return( result );
}



Mein Problem ist folgendes: ObtainBestPen liefert mir immer den
Pen 0, obwohl der genwünschte Pen exisitert!

Und wie kann ich bei einem BitMap den Pen setzen?

Vieln Dank für eure Hilfe!

--
regards
eliot
http://www.exception-dev.de

[ - Answer - Quote - Direct link - ]

2009-09-10, 16:18 h

AGSzabo
Posts: 1663
User
ich kenn mich mit c nicht aus aber kann es sein dass du statt setrgb4 eine funktion mit mehr bits brauchst?

den pen setzen kannst du nur mit einem rastport.

und probiers evtl mal mit PRECISION_EXACT

--
Sam mini os4.1 -- e-uae 39bb2 -- A4000D 3.0 - 2mbchip/8mbfast - Ariadne_II - ide DVD und HD -- A500 3.1 (mkick) adide 50mb -- Duron 1600mhz Ubuntu Linux / WinXP -- BenQ FP93G TFT - 1048 like CRT - HP psc1110


[ Dieser Beitrag wurde von AGSzabo am 10.09.2009 um 16:21 Uhr geändert. ]

[ - Answer - Quote - Direct link - ]

2009-09-10, 19:15 h

eliotmc
Posts: 925
User
So,

hier das ganze nochmal ein wenig aufgeräumter:
C code:
#include <exec/types.h>
#include <clib/alib_protos.h>
#include <graphics/rpattr.h>
#include <intuition/intuitionbase.h>
#include <graphics/gfxbase.h>
#include <graphics/gfxmacros.h>
#include <graphics/gfx.h>
#include <cybergraphx/cybergraphics.h>
#include <stdio.h>

#include <proto/muimaster.h>
#include <proto/graphics.h>
#include <proto/intuition.h>
#include <proto/exec.h>
#include <proto/dos.h>
#include <proto/utility.h>

/***********************************************************************************/

struct GfxBase 		 *GfxBase;
struct IntuitionBase *IntuitionBase;
/***********************************************************************************/

enum{
	MSG_ERROR_NOERROR = 0,
	MSG_ERROR_GRAPHICS,
	MSG_ERROR_INTUITION,
	MSG_ERROR_SCREEN,
};

STRPTR TAB_ERRORS[] = {
	"",
	"Unable to open 'graphics.library'!",
	"Unable to open 'intuition.library'!",
	"Unable to open screen!",
};

/***********************************************************************************/

//50 ticks=second

int main( void )
{
	struct Screen *screen;
    struct RastPort *rp=NULL;
	int result;
    LONG pen=1L;

    struct BitMap *myBitMap;
    struct RastPort myRp;

	result = MSG_ERROR_GRAPHICS;
	if( (GfxBase = (struct GfxBase *) OpenLibrary( "graphics.library", 39 ) ) ) {
		result = MSG_ERROR_INTUITION;
		if( (IntuitionBase = (struct IntuitionBase *) OpenLibrary( "intuition.library", 39 ) ) ) {
			result = MSG_ERROR_SCREEN;

			if( (screen = (struct Screen*) OpenScreenTags( NULL,
            											SA_Width, 320,
                                                        SA_Height, 240,
                                                        SA_Depth, 16,
                                                        SA_Title, "Test",
                                                        SA_ShowTitle,FALSE,
                                                        TAG_DONE )
                                                        ) ) {
              
				VPrintf("Okn",&result);
                rp=&screen->RastPort;

                //Farbe setzen
                pen = ObtainBestPen(screen->ViewPort.ColorMap,
                					0x00000000,
                                    0x00000000,
                                    0x00000000,
                                    OBP_Precision, PRECISION_EXACT,TAG_DONE);
                printf("pen: %lin",pen);

                SetRGB32(&screen->ViewPort,pen,0x00000000,0x00000000,0x00000000);
                SetAPen(rp,pen);
                SetOPen(rp,pen);
                
                //Bildschirm füllen mit Pen
 				SetRast(rp,pen);
              
                //Zeichnet Rect
                SetRGB32(&screen->ViewPort,pen,0xFFFFFFFF,0x00000000,0x00000000);
                RectFill(rp,10,10,20,20);
    
                //Zeichnet einen Pixel
                WritePixel(rp,200,150);

                //Bewegt den Cursor zur Position
                Move(rp, 0,50);
                //Zeichnet eine Linie
                Draw(rp,320,50);

                //Zeichnet eine Ellipse
                DrawEllipse(rp,100,100,10,20);

                //Zeichnet einen Kreis
                DrawCircle(rp, 70,70,20);

                //Füllt eine Fläche
                Flood(rp,1,100,100);

				Delay( 5 * 50 );


                //Und jetzt mit einer BitMap
                myBitMap= AllocBitMap(320,
        					        240,
                                    32,
                                    BMF_CLEAR|BMF_DISPLAYABLE|SHIFT_PIXFMT(PIXFMT_ARGB32)|BMF_SPECIALFMT,
                                    screen->RastPort.BitMap);
				InitRastPort(&myRp);
                myRp.BitMap = myBitMap;

                RectFill(&myRp,10,10,50,50);
              
                BltBitMapRastPort(myBitMap,
                                    0,
                                    0,
                                    rp,
                                    0,
                                    0,
                                    320,
                                    240,
                                    0xc0);
                Delay( 5 * 50 );
                FreeBitMap(myBitMap);

                ReleasePen(screen->ViewPort.ColorMap, pen);
               
				result = MSG_ERROR_NOERROR;
				CloseScreen( screen );
                
               
			}
			CloseLibrary( &IntuitionBase->LibNode );
		}
		CloseLibrary( &GfxBase->LibNode );
	}
	if( result ) {
		VPrintf( TAB_ERRORS[ result ], &result );
		result = 20;
	}
	return( result );
}



Mien konkretes Problem: Wie kann ich den Pen oder die Farbe bei mienem BitMap setzen?
--
regards
eliot
http://www.exception-dev.de

[ - Answer - Quote - Direct link - ]

2009-09-10, 20:02 h

eliotmc
Posts: 925
User
Hallo,

folgendes geht leider auch nicht:
C code:
myBitMap= AllocBitMap(320,
        					        240,
                                    32,
                                    BMF_CLEAR|BMF_DISPLAYABLE|SHIFT_PIXFMT(PIXFMT_ARGB32)|BMF_SPECIALFMT,
                                    NULL);
				InitRastPort(&myRp);

                SetRPAttrs(&myRp,RPTAG_PenMode,FALSE,TAG_DONE);
                SetRPAttrs(&myRp, RPTAG_FgColor,0xFFFFFF,TAG_DONE);
                SetRPAttrs(&myRp, RPTAG_BgColor,0xFFFFFF,TAG_DONE);



Es muss doch einen Weg geben die Farben zum Zeichnen bei einem
BitMap zu setzen!?
--
regards
eliot
http://www.exception-dev.de

[ Dieser Beitrag wurde von eliotmc am 10.09.2009 um 21:08 Uhr geändert. ]

[ - Answer - Quote - Direct link - ]

2009-09-11, 13:25 h

Holger
Posts: 8116
User
@eliotmc:
Bei eigenen Screens musst Du auch Pen-Sharing aktivieren, wenn Du es benutzen willst, also SA_SharePens, TRUE oder so ähnlich.

Sonst sind ohnehin alle Pens exklusiv für Dich reserviert.

mfg

--
Good coders do not comment. What was hard to write should be hard to read too.

[ - Answer - Quote - Direct link - ]

2009-09-11, 13:32 h

Holger
Posts: 8116
User
Nachtrag:
Wenn Du ohnehin eine Farbtabelle angibst, kannst Du natürlich auch auf Pen-Sharing ganz verzichten. Dann nimm einfach die Pen-Nummer, die Du ja kennst, und lass ObtainPen(...) ganz weg.

Zitat:
Original von eliotmc:
Hallo,

folgendes geht leider auch nicht:
C code:
myBitMap= AllocBitMap(320, 240, 32,
   BMF_CLEAR|BMF_DISPLAYABLE|SHIFT_PIXFMT(PIXFMT_ARGB32)|BMF_SPECIALFMT,
   NULL);
InitRastPort(&myRp);

SetRPAttrs(&myRp,RPTAG_PenMode,FALSE,TAG_DONE);
SetRPAttrs(&myRp, RPTAG_FgColor,0xFFFFFF,TAG_DONE);
SetRPAttrs(&myRp, RPTAG_BgColor,0xFFFFFF,TAG_DONE);


Das sieht mir ganz nach Dingen aus, die Du keinesfalls tun solltest, wenn Du die graphics.library mit Mindestversion 39 öffnest.

mfg

--
Good coders do not comment. What was hard to write should be hard to read too.

[ - Answer - Quote - Direct link - ]

2009-09-11, 13:35 h

Holger
Posts: 8116
User
Zitat:
Original von eliotmc:
Und wie kann ich bei einem BitMap den Pen setzen?

Das hatte ich noch übersehen:
Auf einer BitMap kannst Du keinen Pen setzen, weil Operationen auf BitMaps keinen Pen benutzen.
Wie man auf einem RastPort den Pen setzt, weißt Du ja.

mfg

--
Good coders do not comment. What was hard to write should be hard to read too.

[ - Answer - Quote - Direct link - ]

2009-09-11, 13:54 h

thomas
Posts: 7717
User
@eliotmc:

Ich denke, dein größter Fehler ist SA_Depth,16 und die falschen Annahmen über den Screen, der dabei herauskommt.

OpenScreen sucht sich nicht einen passenden Bildschirmmodus zu deinen Dimensionen, sondern es nimmt den Modus, den du angegeben hast. Da du keinen Modus angegeben hast, ist der Default PAL:Lores oder NTSC:Lores bzw. der entsprechende FakeNative-Modus unter OS4.

In jedem Fall bekommst du einen <=8 Bit CLUT-Modus. Unter AGA würde der Bildschirm gar nicht geöffnet, weil eine Tiefe größer als 8 nicht möglich ist. Picasso96 verzeiht diesen Fehler offenbar, aber begrenzt die Tiefe auf 8.

Im folgenden legst du dann eine 32bit Truecolor-Bitmap an und versuchst diese auf den Screen zu kopieren. Die Konvertierung von Truecolor auf CLUT wird von Picaso96 nicht unterstützt, deshalb passiert bei BltBitMapRastPort einfach nichts.

Gruß Thomas

--
Email: thomas-rapp@web.de
Home: thomas-rapp.homepage.t-online.de/

[ - Answer - Quote - Direct link - ]

2009-09-18, 20:41 h

eliotmc
Posts: 925
User
Hallo,

erstmal vieln Dank für die vielen Ratschläge.
Leider bin ich immer noch nicht richtig weiter.

So sieht der Code jetzt aus:
c code:
#include <exec/types.h>
#include <clib/alib_protos.h>
#include <graphics/rpattr.h>
#include <intuition/intuitionbase.h>
#include <graphics/gfxbase.h>
#include <graphics/gfxmacros.h>
#include <graphics/gfx.h>
#include <cybergraphx/cybergraphics.h>
#include <stdio.h>

#include <proto/muimaster.h>
#include <proto/graphics.h>
#include <proto/intuition.h>
#include <proto/exec.h>
#include <proto/dos.h>
#include <proto/utility.h>

/***********************************************************************************/

struct GfxBase 		 *GfxBase;
struct IntuitionBase *IntuitionBase;
/***********************************************************************************/

enum{
	MSG_ERROR_NOERROR = 0,
	MSG_ERROR_GRAPHICS,
	MSG_ERROR_INTUITION,
	MSG_ERROR_SCREEN,
};

STRPTR TAB_ERRORS[] = {
	"",
	"Unable to open 'graphics.library'!",
	"Unable to open 'intuition.library'!",
	"Unable to open screen!",
};

/***********************************************************************************/

//50 ticks=second

int main( void )
{
	struct Screen *screen;
    struct RastPort *rp=NULL;
	int result;
    LONG pen=1L;

    struct BitMap *myBitMap;
    struct RastPort myRp;

	result = MSG_ERROR_GRAPHICS;
	if( (GfxBase = (struct GfxBase *) OpenLibrary( "graphics.library", 39 ) ) ) {
		result = MSG_ERROR_INTUITION;
		if( (IntuitionBase = (struct IntuitionBase *) OpenLibrary( "intuition.library", 39 ) ) ) {
			result = MSG_ERROR_SCREEN;

			if( (screen = (struct Screen*) OpenScreenTags( NULL,
            											SA_Width, 1280,
                                                        SA_Height, 1024,
                                                        SA_Depth, 32,
                                                        SA_Title, "Test",
                                                        SA_ShowTitle,FALSE,
                                                        SA_Quiet,TRUE,
                                                        SA_Exclusive, TRUE,
                                                        TAG_DONE )
                                                        ) ) {
              
				VPrintf("Okn",&result);
                rp=&screen->RastPort;

                //Get a pen and set color
                pen = ObtainBestPen(screen->ViewPort.ColorMap,
                					0x00000000,
                                    0x00000000,
                                    0x00000000,
                                    OBP_Precision, PRECISION_EXACT,TAG_DONE);
                SetRGB32(&screen->ViewPort,pen,0x00000000,0x00000000,0x00000000);
                SetAPen(rp,pen);
                SetOPen(rp,pen);
                
                //Fills screen
 			    SetRast(rp,pen);
              
        
                SetRGB32(&screen->ViewPort,pen,0xFFFFFFFF,0x00000000,0x00000000);
    		    //Drwas a rectangle
        		RectFill(rp,10,10,20,20);
    
                //Draws a pixel
                WritePixel(rp,200,150);

                //Moves gfx cursor to position
                Move(rp, 0,50);
                //Draws a line
                Draw(rp,320,50);

                //Draws a elipse
                DrawEllipse(rp,100,100,10,20);

                //Zeichnet einen Kreis
                DrawCircle(rp, 70,70,20);

                //Fills a shape
                Flood(rp,1,100,100);

                //Wait for 2 seconds
				Delay( 2 * 50 );

               // ReleasePen(screen->ViewPort.ColorMap, pen);

                //Create bitmap
                myBitMap= AllocBitMap(320,
        					        240,
                                    32,
                                    BMF_CLEAR|BMF_DISPLAYABLE|SHIFT_PIXFMT(PIXFMT_ARGB32)|BMF_SPECIALFMT,
                                    //screen->RastPort.BitMap);
                                    NULL);
				InitRastPort(&myRp);

                SetRPAttrs(&myRp,RPTAG_PenMode,FALSE,TAG_DONE);
                SetRPAttrs(&myRp,RPTAG_AlphaMode,TRUE,TAG_DONE);
                SetRPAttrs(&myRp, RPTAG_FgColor,0xFFFFFFFF,TAG_DONE);
                SetRPAttrs(&myRp, RPTAG_BgColor,0xFFFFFFFF,TAG_DONE);

                 myRp.BitMap = myBitMap;

                //SetRGB32(&screen->ViewPort,pen,0x00000000,0x00000000,0x00000000);
                //RectFill(&myRp,0,0,320,240);
              
                //SetRGB32(&screen->ViewPort,pen,0xFFFFFFFF,0x00000000,0x00000000);
                RectFill(&myRp,10,10,50,50);

                //Blitting bitmap to screen
                BltBitMapRastPort(myBitMap,
                                    0,
                                    0,
                                    rp,
                                    0,
                                    0,
                                    320,
                                    240,
                                    0xc0);
                Delay( 2 * 50 );
                FreeBitMap(myBitMap);

				result = MSG_ERROR_NOERROR;
				CloseScreen( screen );
                
               
			}
			CloseLibrary( &IntuitionBase->LibNode );
		}
		CloseLibrary( &GfxBase->LibNode );
	}
	if( result ) {
		VPrintf( TAB_ERRORS[ result ], &result );
		result = 20;
	}
	return( result );
}


Wie kann ich bei dem Bitmap Rastport (myrp) die Farbe setzen, so
dass ich zeichnen kann (und zwar in meiner genwüscnhten Farbe).
Das SetRPAttrs(&myRp, RPTAG_FgColor,0xFFFFFFFF,TAG_DONE);
SetRPAttrs(&myRp, RPTAG_BgColor,0xFFFFFFFF,TAG_DONE);
scheint nicht zu funktionieren (oder ich nutze es falsch).

--
regards
eliot
http://www.exception-dev.de

[ - Answer - Quote - Direct link - ]

2009-09-18, 22:09 h

eliotmc
Posts: 925
User
Hallo,


wenn ich SetRPAttrs nach dem Zuweisen der Bitmap zum Rastport
aufrufe, funktioniert alles!
--
regards
eliot
http://www.exception-dev.de

[ - Answer - Quote - Direct link - ]


-1- [ - Post reply - ]


amiga-news.de Forum > Programmierung > BitMap und Farbe setzen [ - Search - New posts - Register - Login - ]


.
Masthead | Privacy policy | Netiquette | Advertising | Contact
Copyright © 1998-2024 by amiga-news.de - all rights reserved.
.