nes like graphics system?

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
Shadowblitz16
Citizen
Posts: 73
Joined: Wed Oct 28, 2015 11:18 pm

nes like graphics system?

Post by Shadowblitz16 »

is there a way to make a graphics system that is a table of indexed textures/images?

the main problem is importing textures from png
basically I want to make the user select a base palette when importing the image to the texturebank..
this palette is used to find out what colors are mapped to what colors by comparing the passed palette index with the current colors in the image.
then the new indexed texture is returned which is basically a bunch of indices pointing to a color in the palette.

I also need this data to be wrapped on the tile count and the texture count
for example if trying to draw a 2x2 tile (in tiles not pixels) and the texture was only 1 tile long and the texturebank was only 3 textures long it would do this...
-Texture 0, Tile 0 (moves to next texture)
-Texture 1, Tile 0 (moves to next texture)
-Texture 2, Tile 0 (moves to next texture)
-Texture 3, Tile 0 (wraps back to texture 0)
-Done rendered big tile
[/code]

sorry if this doesn't make sense, I am trying to explain it clearly
User avatar
raidho36
Party member
Posts: 2063
Joined: Mon Jun 17, 2013 12:00 pm

Re: nes like graphics system?

Post by raidho36 »

You can create your sprite with "indexed pallette" color mode. Then you can use a trivial shader to substitute current color for desired color, using a second sprite just containing a row of colors of the alternative pallette. It is also an option to repaint the sprite pixel by pixel when you load it, but that leaves its coloring static during the game.

As for tiles, well, just Tiled & STI library, or somesuch.
Shadowblitz16
Citizen
Posts: 73
Joined: Wed Oct 28, 2015 11:18 pm

Re: nes like graphics system?

Post by Shadowblitz16 »

what I am wondering though is the code behind importing.
I can easily import the image by pixels with no wrap but that's not what I want
I want to handle image importing by tiles, I also want to make sure that tiles indices are never out of bounds by using wrapping.

here is a little picture I made to explain...

Image
in the image there are 4 tiles per texture page with a width of 2.
every time the index is greator then the texture's tile length it goes to the next texture.
when it reaches the end of the texturepage list it wraps back around to texture 0.

this is how I would like to import my images in tiles and not nessarly pixels
User avatar
zorg
Party member
Posts: 3436
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: nes like graphics system?

Post by zorg »

I don't get why the order is weird on your example image (C,1,4,5;2,3,6,7;8,9,A,B) but you can essentially code something that stores how many tiles are horizontally and vertically in a texture, and their dimensions in pixels, then apply logic to it so it wraps around on all edges.

Also, i don't understand what you don't get about importing; an image is an image is an image (or imagedata, whatever); it is made out of pixels, there's no atomic tile unit; if you meant gpu-based texture wrapping, that behaviour only matters if you want to manipulate texture uv-s directly on a mesh or something, although you may also be content with just using quads, since you did mention tile indices.

One example, store 12 quads for 12 tiles in one table, and whenever you index into it with a number n, just do ((n % 12)+1) and that will wrap the index correctly (if the table is 1-based, 0-based ones don't need the +1).

(Edit: I elaborated on the mesh per-vertex texture uv coordinate thing in your other thread, if you don't want to use quads.)
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
User avatar
Jasoco
Inner party member
Posts: 3725
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: nes like graphics system?

Post by Jasoco »

I wrote a simple shader for a project I did a while ago that does just that, takes an image and replaces certain colors with whatever you pass to it. It would be used for NES-style sprite and tile colorizing. Here's the simple code if you want it:

Code: Select all

nesShader = love.graphics.newShader[[
	extern vec4 color1;
	extern vec4 color2;
	extern vec4 color3;
	extern vec4 color4;

	vec4 effect( vec4 color, Image texture, vec2 texture_coords, vec2 screen_coords ){
		vec4 pixel = Texel(texture, texture_coords );//This is the current pixel color
		if (pixel.a == 0.0) { return vec4(0.0,0.0,0.0,0.0); }
		if (pixel.r < 0.25) { return vec4(color4.r/255,color4.g/255,color4.b/255,color4.a/255); }
		else if (pixel.r < 0.5) { return vec4(color3.r/255,color3.g/255,color3.b/255,color3.a/255); }
		else if (pixel.r < 0.75) { return vec4(color2.r/255,color2.g/255,color2.b/255,color2.a/255); }
		else { return vec4(color1.r/255,color1.g/255,color1.b/255,color1.a/255); }
		return pixel;
	}
]]
You'd use the following to send colors to it:

Code: Select all

nesShader:send("color1", **COLOR 1**)
nesShader:send("color2", **COLOR 2**)
nesShader:send("color3", **COLOR 3**)
nesShader:send("color4", **COLOR 4**)
lgr.setShader(nesShader)
**DRAW IMAGE HERE**
lgr.setShader()
And you'd structure your image so it has only 4 shades of grey. Each shade should be either between white-25% grey (Color 1), between 25-50% grey (Color 2), between 50%-75% grey (Color 3) and 75%-black (Color 4) and each will be replaced with whatever you send it.

If you want to follow NES restrictions, remember that for tiles you can have up to 3 colors per 16x16 tile area and a default "universal" color (Which you would probably pass as the 1st entry in the shader and will be the same for every tile on the screen), and for sprites you can have up to 3 colors and a transparent color. (Which would also be the 1st entry) Basically I guess if you want to be strict, make the universal color just be the backgroundColor or a colored rectangle behind everything that you can change at will.

Check out the NES post on this page: https://pixelation.org/index.php?PHPSES ... #msg115062
Tells you everything you need to know.

Also this old gem from Shovel Knight: https://www.gamasutra.com/blogs/DavidDA ... Knight.php
Shadowblitz16
Citizen
Posts: 73
Joined: Wed Oct 28, 2015 11:18 pm

Re: nes like graphics system?

Post by Shadowblitz16 »

@zorg ya I messed up on the example sorry but the idea was that it used a 1d tile index instead of a 2d one and tilebanks were looked up by amount tileindex went into the tilebank count

@Jasoco I would need to allow images to be more the n just grey they need to be indexed on import so that any image can by imported without having to grey scale it

also I need it to be at least 16 colors since I won't be emulating the nes exactly
Post Reply

Who is online

Users browsing this forum: No registered users and 47 guests